diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 94184f6d9373..f0c88937a0f1 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -1658,22 +1658,31 @@ def get_course_survey_results(request, course_id): return JsonResponse({"status": success_status}) -@transaction.non_atomic_requests -@require_POST -@ensure_csrf_cookie -@cache_control(no_cache=True, no_store=True, must_revalidate=True) -@require_course_permission(permissions.EXAM_RESULTS) -@common_exceptions_400 -def get_proctored_exam_results(request, course_id): +@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') +@method_decorator(transaction.non_atomic_requests, name='dispatch') +class GetProctoredExamResults(DeveloperErrorViewMixin, APIView): """ - get the proctored exam resultsreport for the particular course. + get the proctored exam results report for the particular course. """ - course_key = CourseKey.from_string(course_id) - report_type = _('proctored exam results') - task_api.submit_proctored_exam_results_report(request, course_key) - success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type) - return JsonResponse({"status": success_status}) + permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_name = permissions.EXAM_RESULTS + + @method_decorator(ensure_csrf_cookie) + @method_decorator(transaction.non_atomic_requests) + def post(self, request, course_id): + """ + get the proctored exam results report for the particular course. + """ + try: + course_key = CourseKey.from_string(course_id) + report_type = _('proctored exam results') + task_api.submit_proctored_exam_results_report(request, course_key) + success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type) + return JsonResponse({"status": success_status}) + except AlreadyRunningError as error: + # Return a 400 status code with the error message + return JsonResponse({"error": str(error)}, status=400) @method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') diff --git a/lms/djangoapps/instructor/views/api_urls.py b/lms/djangoapps/instructor/views/api_urls.py index 5976411a9756..02c50d031abb 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -57,7 +57,7 @@ path('show_student_extensions', api.ShowStudentExtensions.as_view(), name='show_student_extensions'), # proctored exam downloads... - path('get_proctored_exam_results', api.get_proctored_exam_results, name='get_proctored_exam_results'), + path('get_proctored_exam_results', api.GetProctoredExamResults.as_view(), name='get_proctored_exam_results'), # Grade downloads... path('list_report_downloads', api.ListReportDownloads.as_view(), name='list_report_downloads'),