Skip to content

Commit 9f5fe30

Browse files
authored
feat!: upgrading get_proctored_exam_results api to DRF ( 32 ) (#35612)
* feat!: upgrading api to DRF
1 parent bdd2bc3 commit 9f5fe30

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lms/djangoapps/instructor/views/api.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,22 +1706,31 @@ def post(self, request, course_id):
17061706
return JsonResponse({"status": success_status})
17071707

17081708

1709-
@transaction.non_atomic_requests
1710-
@require_POST
1711-
@ensure_csrf_cookie
1712-
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
1713-
@require_course_permission(permissions.EXAM_RESULTS)
1714-
@common_exceptions_400
1715-
def get_proctored_exam_results(request, course_id):
1709+
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')
1710+
@method_decorator(transaction.non_atomic_requests, name='dispatch')
1711+
class GetProctoredExamResults(DeveloperErrorViewMixin, APIView):
17161712
"""
1717-
get the proctored exam resultsreport for the particular course.
1713+
get the proctored exam results report for the particular course.
17181714
"""
1719-
course_key = CourseKey.from_string(course_id)
1720-
report_type = _('proctored exam results')
1721-
task_api.submit_proctored_exam_results_report(request, course_key)
1722-
success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)
17231715

1724-
return JsonResponse({"status": success_status})
1716+
permission_classes = (IsAuthenticated, permissions.InstructorPermission)
1717+
permission_name = permissions.EXAM_RESULTS
1718+
1719+
@method_decorator(ensure_csrf_cookie)
1720+
@method_decorator(transaction.non_atomic_requests)
1721+
def post(self, request, course_id):
1722+
"""
1723+
get the proctored exam results report for the particular course.
1724+
"""
1725+
try:
1726+
course_key = CourseKey.from_string(course_id)
1727+
report_type = _('proctored exam results')
1728+
task_api.submit_proctored_exam_results_report(request, course_key)
1729+
success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)
1730+
return JsonResponse({"status": success_status})
1731+
except (AlreadyRunningError, QueueConnectionError, AttributeError) as error:
1732+
# Return a 400 status code with the error message
1733+
return JsonResponse({"error": str(error)}, status=400)
17251734

17261735

17271736
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')

lms/djangoapps/instructor/views/api_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
path('show_student_extensions', api.ShowStudentExtensions.as_view(), name='show_student_extensions'),
5858

5959
# proctored exam downloads...
60-
path('get_proctored_exam_results', api.get_proctored_exam_results, name='get_proctored_exam_results'),
60+
path('get_proctored_exam_results', api.GetProctoredExamResults.as_view(), name='get_proctored_exam_results'),
6161

6262
# Grade downloads...
6363
path('list_report_downloads', api.ListReportDownloads.as_view(), name='list_report_downloads'),

0 commit comments

Comments
 (0)