Skip to content

Commit 4cea2ab

Browse files
authored
feat: export ora2 summary to DRF (#36555)
* feat: export ora2 summary to DRF.
1 parent d6dbc40 commit 4cea2ab

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

lms/djangoapps/instructor/views/api.py

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,22 +2742,35 @@ def post(self, request, course_id):
27422742
return JsonResponse({"error": str(err)}, status=400)
27432743

27442744

2745-
@transaction.non_atomic_requests
2746-
@require_POST
2747-
@ensure_csrf_cookie
2748-
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
2749-
@require_course_permission(permissions.CAN_RESEARCH)
2750-
@common_exceptions_400
2751-
def export_ora2_summary(request, course_id):
2745+
@method_decorator(transaction.non_atomic_requests, name='dispatch')
2746+
class ExportOra2SummaryView(DeveloperErrorViewMixin, APIView):
27522747
"""
2753-
Pushes a Celery task which will aggregate a summary students' progress in ora2 tasks for a course into a .csv
2748+
Pushes a Celery task which will aggregate a summary of students' progress in ora2 tasks for a course into a .csv
27542749
"""
2755-
course_key = CourseKey.from_string(course_id)
2756-
report_type = _('ORA summary')
2757-
task_api.submit_export_ora2_summary(request, course_key)
2758-
success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)
2750+
permission_classes = (IsAuthenticated, permissions.InstructorPermission)
2751+
permission_name = permissions.CAN_RESEARCH
27592752

2760-
return JsonResponse({"status": success_status})
2753+
@method_decorator(ensure_csrf_cookie)
2754+
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True))
2755+
def post(self, request, course_id):
2756+
"""
2757+
Initiates a Celery task to generate an ORA summary report for the specified course.
2758+
2759+
Args:
2760+
request: The HTTP request object
2761+
course_id: The string representation of the course key
2762+
2763+
Returns:
2764+
Response: A JSON response with a status message indicating the report generation has started
2765+
"""
2766+
course_key = CourseKey.from_string(course_id)
2767+
report_type = _('ORA summary')
2768+
try:
2769+
task_api.submit_export_ora2_summary(request, course_key)
2770+
success_status = SUCCESS_MESSAGE_TEMPLATE.format(report_type=report_type)
2771+
return Response({"status": success_status})
2772+
except (AlreadyRunningError, QueueConnectionError, AttributeError) as err:
2773+
return JsonResponse({"error": str(err)}, status=400)
27612774

27622775

27632776
@transaction.non_atomic_requests

lms/djangoapps/instructor/views/api_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
# Reports..
6868
path('get_course_survey_results', api.GetCourseSurveyResults.as_view(), name='get_course_survey_results'),
6969
path('export_ora2_data', api.ExportOra2DataView.as_view(), name='export_ora2_data'),
70-
path('export_ora2_summary', api.export_ora2_summary, name='export_ora2_summary'),
70+
path('export_ora2_summary', api.ExportOra2SummaryView.as_view(), name='export_ora2_summary'),
7171

7272
path('export_ora2_submission_files', api.export_ora2_submission_files,
7373
name='export_ora2_submission_files'),

0 commit comments

Comments
 (0)