diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 94184f6d9373..98df3e48bcf3 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -3239,26 +3239,31 @@ def post(self, request, course_id): return JsonResponse(response_payload) -@transaction.non_atomic_requests -@ensure_csrf_cookie -@cache_control(no_cache=True, no_store=True, must_revalidate=True) -@require_course_permission(permissions.START_CERTIFICATE_GENERATION) -@require_POST -@common_exceptions_400 -def start_certificate_generation(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 StartCertificateGeneration(DeveloperErrorViewMixin, APIView): """ Start generating certificates for all students enrolled in given course. """ - course_key = CourseKey.from_string(course_id) - task = task_api.generate_certificates_for_students(request, course_key) - message = _('Certificate generation task for all students of this course has been started. ' - 'You can view the status of the generation task in the "Pending Tasks" section.') - response_payload = { - 'message': message, - 'task_id': task.task_id - } + permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_name = permissions.START_CERTIFICATE_GENERATION - return JsonResponse(response_payload) + @method_decorator(ensure_csrf_cookie) + @method_decorator(transaction.non_atomic_requests) + def post(self, request, course_id): + """ + Generating certificates for all students enrolled in given course. + """ + course_key = CourseKey.from_string(course_id) + task = task_api.generate_certificates_for_students(request, course_key) + message = _('Certificate generation task for all students of this course has been started. ' + 'You can view the status of the generation task in the "Pending Tasks" section.') + response_payload = { + 'message': message, + 'task_id': task.task_id + } + + return JsonResponse(response_payload) @transaction.non_atomic_requests diff --git a/lms/djangoapps/instructor/views/api_urls.py b/lms/djangoapps/instructor/views/api_urls.py index 5976411a9756..e7309d7f5f81 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -82,7 +82,7 @@ # Certificates path('enable_certificate_generation', api.enable_certificate_generation, name='enable_certificate_generation'), - path('start_certificate_generation', api.start_certificate_generation, name='start_certificate_generation'), + path('start_certificate_generation', api.StartCertificateGeneration.as_view(), name='start_certificate_generation'), path('start_certificate_regeneration', api.start_certificate_regeneration, name='start_certificate_regeneration'), path('certificate_exception_view/', api.certificate_exception_view, name='certificate_exception_view'), re_path(r'^generate_certificate_exceptions/(?P[^/]*)', api.generate_certificate_exceptions,