|
1 | 1 | """Views for the API""" |
2 | 2 |
|
3 | | -import json |
4 | 3 | import logging |
5 | 4 | import secrets |
6 | 5 | import string |
|
30 | 29 | from lms.djangoapps.certificates.models import GeneratedCertificate |
31 | 30 | from lms.djangoapps.course_api.api import list_courses |
32 | 31 | from lms.djangoapps.course_api.serializers import CourseSerializer |
33 | | -from lms.djangoapps.instructor.views.api import students_update_enrollment |
| 32 | +from lms.djangoapps.instructor.views.api import StudentsUpdateEnrollmentView |
34 | 33 | from opaque_keys.edx.keys import CourseKey |
35 | 34 | from openedx.core.djangoapps.enrollments.views import ( |
36 | 35 | ApiKeyPermissionMixIn, |
@@ -402,19 +401,20 @@ class BulkEnrollView(APIView, ApiKeyPermissionMixIn): |
402 | 401 | def post(self, request): |
403 | 402 | serializer = BulkEnrollmentSerializer(data=request.data) |
404 | 403 | if serializer.is_valid(): |
405 | | - request._request.POST = request.data # pylint: disable=protected-access |
406 | 404 | response_dict = { |
407 | 405 | "auto_enroll": serializer.data.get("auto_enroll"), |
408 | 406 | "email_students": serializer.data.get("email_students"), |
409 | 407 | "action": serializer.data.get("action"), |
410 | 408 | "courses": {}, |
411 | 409 | } |
| 410 | + view = StudentsUpdateEnrollmentView() |
412 | 411 | for course in serializer.data.get("courses"): |
413 | | - response = students_update_enrollment( |
414 | | - request._request, # pylint: disable=protected-access |
| 412 | + response_dict["courses"][course] = view._process_student_enrollment( # pylint: disable=protected-access |
| 413 | + user=request.user, |
415 | 414 | course_id=course, |
| 415 | + data=request.data, |
| 416 | + secure=request.is_secure(), |
416 | 417 | ) |
417 | | - response_dict["courses"][course] = json.loads(response.content.decode("utf-8")) |
418 | 418 | return Response(data=response_dict, status=status.HTTP_200_OK) |
419 | 419 | return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
420 | 420 |
|
|
0 commit comments