From 093734b2ea1d2db0429b994ca4cebedbfc9dba78 Mon Sep 17 00:00:00 2001 From: Awais Qureshi Date: Tue, 1 Oct 2024 15:32:50 +0500 Subject: [PATCH] feat!: upgrading simple api with DRF. (#35463) --- lms/djangoapps/instructor/views/api.py | 34 ++++++++++----------- lms/djangoapps/instructor/views/api_urls.py | 2 +- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lms/djangoapps/instructor/views/api.py b/lms/djangoapps/instructor/views/api.py index cae166e7b9b..5ac663d3841 100644 --- a/lms/djangoapps/instructor/views/api.py +++ b/lms/djangoapps/instructor/views/api.py @@ -1353,27 +1353,27 @@ def _get_problem_responses(request, *, course_id, problem_locations, problem_typ return JsonResponse({"status": success_status, "task_id": task.task_id}) -@require_POST -@ensure_csrf_cookie -@cache_control(no_cache=True, no_store=True, must_revalidate=True) -@require_course_permission(permissions.CAN_RESEARCH) -def get_grading_config(request, course_id): +@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch') +class GetGradingConfig(APIView): """ Respond with json which contains a html formatted grade summary. """ - course_id = CourseKey.from_string(course_id) - # course = get_course_with_access( - # request.user, 'staff', course_id, depth=None - # ) - course = get_course_by_id(course_id) - - grading_config_summary = instructor_analytics_basic.dump_grading_context(course) + permission_classes = (IsAuthenticated, permissions.InstructorPermission) + permission_name = permissions.CAN_RESEARCH - response_payload = { - 'course_id': str(course_id), - 'grading_config_summary': grading_config_summary, - } - return JsonResponse(response_payload) + @method_decorator(ensure_csrf_cookie) + def post(self, request, course_id): + """ + Post method to return grading config. + """ + course_id = CourseKey.from_string(course_id) + course = get_course_by_id(course_id) + grading_config_summary = instructor_analytics_basic.dump_grading_context(course) + response_payload = { + 'course_id': str(course_id), + 'grading_config_summary': grading_config_summary, + } + 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 92d5f46bc70..3e4a9c1f327 100644 --- a/lms/djangoapps/instructor/views/api_urls.py +++ b/lms/djangoapps/instructor/views/api_urls.py @@ -27,7 +27,7 @@ path('modify_access', api.ModifyAccess.as_view(), name='modify_access'), path('bulk_beta_modify_access', api.bulk_beta_modify_access, name='bulk_beta_modify_access'), path('get_problem_responses', api.get_problem_responses, name='get_problem_responses'), - path('get_grading_config', api.get_grading_config, name='get_grading_config'), + path('get_grading_config', api.GetGradingConfig.as_view(), name='get_grading_config'), re_path(r'^get_students_features(?P/csv)?$', api.get_students_features, name='get_students_features'), path('get_issued_certificates/', api.get_issued_certificates, name='get_issued_certificates'), path('get_students_who_may_enroll', api.GetStudentsWhoMayEnroll.as_view(), name='get_students_who_may_enroll'),