From bfb6d37e4862f0a3474c226be995134f30bcf7c5 Mon Sep 17 00:00:00 2001 From: awais qureshi Date: Wed, 25 Sep 2024 17:03:03 +0500 Subject: [PATCH] feat!: upgrading api to DRF. --- lms/djangoapps/instructor/views/api.py | 37 ++++++++++++--------- lms/djangoapps/instructor/views/api_urls.py | 2 +- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index 45c460d32908..e9425013b6ab 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -3232,26 +3232,31 @@ def mark_student_can_skip_entrance_exam(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 a248b46ae531..db7bc8e6c7c3 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -81,7 +81,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,