From 04aa93c213c868d680b3927a36ca03f1ae02fe9f Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Thu, 24 Apr 2025 11:29:34 +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 9176d45ecc..e5c73e9309 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -2259,26 +2259,31 @@ def rescore_entrance_exam(request, course_id): return JsonResponse(response_payload) -@require_POST -@ensure_csrf_cookie -@cache_control(no_cache=True, no_store=True, must_revalidate=True) -@require_course_permission(permissions.EMAIL) -def list_background_email_tasks(request, course_id): +@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') +class ListBackgroundEmailTasks(DeveloperErrorViewMixin, APIView): """ List background email tasks. """ - course_id = CourseKey.from_string(course_id) - task_type = InstructorTaskTypes.BULK_COURSE_EMAIL - # Specifying for the history of a single task type - tasks = task_api.get_instructor_task_history( - course_id, - task_type=task_type - ) + permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_name = permissions.EMAIL - response_payload = { - 'tasks': list(map(extract_task_features, tasks)), - } - return JsonResponse(response_payload) + @method_decorator(ensure_csrf_cookie) + def post(self, request, course_id): + """ + List background email tasks. + """ + course_id = CourseKey.from_string(course_id) + task_type = InstructorTaskTypes.BULK_COURSE_EMAIL + # Specifying for the history of a single task type + tasks = task_api.get_instructor_task_history( + course_id, + task_type=task_type + ) + + response_payload = { + 'tasks': list(map(extract_task_features, tasks)), + } + return JsonResponse(response_payload) @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 01bfbd5fab..67006decba 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -46,7 +46,7 @@ urlpatterns = [ path('mark_student_can_skip_entrance_exam', api.MarkStudentCanSkipEntranceExam.as_view(), name='mark_student_can_skip_entrance_exam'), path('list_instructor_tasks', api.ListInstructorTasks.as_view(), name='list_instructor_tasks'), - path('list_background_email_tasks', api.list_background_email_tasks, name='list_background_email_tasks'), + path('list_background_email_tasks', api.ListBackgroundEmailTasks.as_view(), name='list_background_email_tasks'), path('list_email_content', api.ListEmailContent.as_view(), name='list_email_content'), path('list_forum_members', api.list_forum_members, name='list_forum_members'), path('update_forum_role_membership', api.update_forum_role_membership, name='update_forum_role_membership'),