From 7c0ebf8b920d226afd4490aac5b00f4cdf844273 Mon Sep 17 00:00:00 2001 From: Veriny <2002.ijustin@gmail.com> Date: Mon, 18 Sep 2023 20:43:04 -0700 Subject: [PATCH] fix merge conflict --- csm_web/scheduler/views/student.py | 45 ++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/csm_web/scheduler/views/student.py b/csm_web/scheduler/views/student.py index 038f081c..3f2b696d 100644 --- a/csm_web/scheduler/views/student.py +++ b/csm_web/scheduler/views/student.py @@ -1,5 +1,3 @@ -import datetime - from django.core.exceptions import ObjectDoesNotExist from django.db.models import Q from django.utils import timezone @@ -7,7 +5,6 @@ from rest_framework.decorators import action from rest_framework.exceptions import PermissionDenied from rest_framework.response import Response -from scheduler.models import Attendance, SectionOccurrence from ..models import Student from ..serializers import AttendanceSerializer, StudentSerializer @@ -29,6 +26,10 @@ def get_queryset(self): @action(detail=True, methods=["patch"]) def drop(self, request, pk=None): + """ + Drops a student form a course. + PATCH: Drop a given student. Check for student ban if coordinator made request + """ student = get_object_or_error(self.get_queryset(), pk=pk) is_coordinator = student.course.coordinator_set.filter( user=request.user @@ -44,8 +45,10 @@ def drop(self, request, pk=None): student.course.whitelist.remove(student.user) student.save() logger.info( - f" User {log_str(request.user)} dropped Section" - f" {log_str(student.section)} for Student user {log_str(student.user)}" + " User %s dropped section %s for Student %s.", + log_str(request.user), + log_str(student.section), + log_str(student.user), ) # filter attendances and delete future attendances now = timezone.now().astimezone(timezone.get_default_timezone()) @@ -57,14 +60,21 @@ def drop(self, request, pk=None): ) ).delete() logger.info( - f" Deleted {num_deleted} attendances for user" - f" {log_str(student.user)} in Section {log_str(student.section)} after" - f" {now.date()}" + " Deleted %s attendances for user %s in Section %s after %s", + num_deleted, + log_str(student.user), + log_str(student.section), + now.date(), ) return Response(status=status.HTTP_204_NO_CONTENT) @action(detail=True, methods=["get", "put"]) def attendances(self, request, pk=None): + """ + Method for updating attendances. + GET: Gets the attendances for a student + PUT: Updates the attendances for a student + """ student = get_object_or_error(self.get_queryset(), pk=pk) if request.method == "GET": return Response( @@ -86,21 +96,26 @@ def attendances(self, request, pk=None): ) except ObjectDoesNotExist: logger.error( - " Could not record attendance for User" - f" {log_str(request.user)}, used non-existent attendance id" - f" {request.data['id']}" + ( + " Could not record attendance for User %s, used" + " non-existent attendance ID %s" + ), + log_str(request.user), + request.data["id"], ) return Response(status=status.HTTP_400_BAD_REQUEST) if serializer.is_valid(): attendance = serializer.save() logger.info( - f" Attendance {log_str(attendance)} recorded for" - f" User {log_str(request.user)}" + " Attendance %s recorded for User %s", + log_str(attendance), + log_str(request.user), ) return Response(status=status.HTTP_204_NO_CONTENT) logger.error( - " Could not record attendance for User" - f" {log_str(request.user)}, errors: {serializer.errors}" + " Could not record attendance for User %s, errors: %s", + log_str(request.user), + serializer.errors, ) return Response(serializer.errors, status=status.HTTP_422_UNPROCESSABLE_ENTITY)