Skip to content

Commit

Permalink
feat!: upgrading api to DRF.
Browse files Browse the repository at this point in the history
  • Loading branch information
awais786 committed Sep 23, 2024
1 parent ad7a920 commit 60e8d0f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3603,6 +3603,7 @@ class CertificateInvalidationView(APIView):
def post(self, request, course_id):
course_key = CourseKey.from_string(course_id)
validation_response = self.validate_and_get_data(request, course_key)

# If validation fails, return the error response
if isinstance(validation_response, JsonResponse):
return validation_response
Expand Down Expand Up @@ -3651,6 +3652,16 @@ def delete(self, request, course_id):
return JsonResponse({}, status=204)

def validate_and_get_data(self, request, course_key):
"""
Validates the request data, retrieves the student and certificate for the specified course.
This method performs the following steps:
1. Parses the request data to extract the necessary information.
2. Retrieves the student object from the parsed request data.
3. Fetches the certificate for the user and course specified by the course_key.
If any of the steps fail (e.g., invalid request data or missing certificate), a ValueError is raised,
and the method returns a JsonResponse with a 400 status code.
"""
try:
certificate_invalidation_data = parse_request_data(request)
student = _get_student_from_request_data(certificate_invalidation_data)
Expand Down

0 comments on commit 60e8d0f

Please sign in to comment.