Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrading show_unit_extensions api to drf compatible ( 18th ) #35395

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions lms/djangoapps/instructor/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
from lms.djangoapps.instructor_task.data import InstructorTaskTypes
from lms.djangoapps.instructor_task.models import ReportStore
from lms.djangoapps.instructor.views.serializer import (
AccessSerializer, RoleNameSerializer, ShowStudentExtensionSerializer,
UserSerializer, SendEmailSerializer, StudentAttemptsSerializer
AccessSerializer, RoleNameSerializer, ShowStudentExtensionSerializer, UnitBlockSerializer, UserSerializer,
SendEmailSerializer, StudentAttemptsSerializer
)
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.course_groups.cohorts import add_user_to_cohort, is_course_cohorted
Expand Down Expand Up @@ -3024,19 +3024,33 @@ def reset_due_date(request, course_id):
original_due_date_str))


@handle_dashboard_error
@require_POST
@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
@require_course_permission(permissions.GIVE_STUDENT_EXTENSION)
@require_post_params('url')
def show_unit_extensions(request, course_id):
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')
class ShowUnitExtensions(APIView):
"""
Shows all of the students which have due date extensions for the given unit.
"""
course = get_course_by_id(CourseKey.from_string(course_id))
unit = find_unit(course, request.POST.get('url'))
return JsonResponse(dump_block_extensions(course, unit))
permission_classes = (IsAuthenticated, permissions.InstructorPermission)
serializer_class = UnitBlockSerializer
permission_name = permissions.GIVE_STUDENT_EXTENSION

@method_decorator(ensure_csrf_cookie)
def post(self, request, course_id):
"""
Parameters:
`URL`: Unit block url path.
"""
course = get_course_by_id(CourseKey.from_string(course_id))

serializer_data = self.serializer_class(data=request.data)
if not serializer_data.is_valid():
return HttpResponseBadRequest(reason=serializer_data.errors)

try:
unit = find_unit(course, request.POST.get('url'))
except Exception as error: # pylint: disable=broad-except
return JsonResponse({'error': str(error)}, status=400)

return JsonResponse(dump_block_extensions(course, unit))


@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/instructor/views/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
path('send_email', api.SendEmail.as_view(), name='send_email'),
path('change_due_date', api.change_due_date, name='change_due_date'),
path('reset_due_date', api.reset_due_date, name='reset_due_date'),
path('show_unit_extensions', api.show_unit_extensions, name='show_unit_extensions'),
path('show_unit_extensions', api.ShowUnitExtensions.as_view(), name='show_unit_extensions'),
path('show_student_extensions', api.ShowStudentExtensions.as_view(), name='show_student_extensions'),

# proctored exam downloads...
Expand Down
7 changes: 7 additions & 0 deletions lms/djangoapps/instructor/views/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ def validate_student(self, value):
return user


class UnitBlockSerializer(serializers.Serializer):
"""
URL path of the unit block
"""
url = serializers.CharField()


class StudentAttemptsSerializer(serializers.Serializer):
"""
Serializer for resetting a students attempts counter or starts a task to reset all students
Expand Down
Loading