From 6d51145b6e6c22bd843e78d3f2e1efcca75820ec Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Wed, 9 Oct 2024 16:17:31 +0500 Subject: [PATCH] feat!: upgrading api to DRF. --- lms/djangoapps/instructor/views/api.py | 10 +++++++--- lms/djangoapps/instructor/views/serializer.py | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 2ca7bc93d203..3ed25df95623 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -2012,11 +2012,11 @@ def post(self, request, course_id): all_students and unique_student_identifier cannot both be present. """ + course_id = CourseKey.from_string(course_id) course = get_course_with_access(request.user, 'staff', course_id) serializer_data = self.serializer_class(data=request.data) - student = None if not serializer_data.is_valid(): return HttpResponseBadRequest(reason=serializer_data.errors) @@ -2025,11 +2025,15 @@ def post(self, request, course_id): all_students = serializer_data.validated_data.get("all_students") only_if_higher = serializer_data.validated_data.get("only_if_higher") + student = serializer_data.validated_data.get("unique_student_identifier") + student_identifier = request.data.get("unique_student_identifier") + + import pdb; + pdb.set_trace() + if all_students and not has_access(request.user, 'instructor', course): return HttpResponseForbidden("Requires instructor access.") - student = serializer_data.validated_data.get("unique_student_identifier") - if not (problem_to_reset and (all_students or student)): return HttpResponseBadRequest("Missing query parameters.") diff --git a/lms/djangoapps/instructor/views/serializer.py b/lms/djangoapps/instructor/views/serializer.py index e366fe30075a..71f9fda2cb35 100644 --- a/lms/djangoapps/instructor/views/serializer.py +++ b/lms/djangoapps/instructor/views/serializer.py @@ -243,5 +243,11 @@ class ProblemResetSerializer(UniqueStudentIdentifierSerializer): ) only_if_higher = serializers.BooleanField( default=False, - help_text=_("Whether to reset the problem for all students."), + ) + + # Override the unique_student_identifier field to make it optional + unique_student_identifier = serializers.CharField( + required=False, # Make this field optional + allow_null=True, + help_text=_("unique student identifier.") )