From f9d3d641cbd51c0b820828b0ca6123a185caefd5 Mon Sep 17 00:00:00 2001 From: Alex Dusenbery Date: Fri, 12 Oct 2018 14:36:01 -0400 Subject: [PATCH] Use CursorPagination to paginate responses from grades views. --- .../grades/api/v1/tests/test_views.py | 2 -- lms/djangoapps/grades/api/v1/views.py | 21 ++++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lms/djangoapps/grades/api/v1/tests/test_views.py b/lms/djangoapps/grades/api/v1/tests/test_views.py index 23ec64b79e..6d76ab4827 100644 --- a/lms/djangoapps/grades/api/v1/tests/test_views.py +++ b/lms/djangoapps/grades/api/v1/tests/test_views.py @@ -647,7 +647,6 @@ class GradebookViewTest(GradeViewTestMixin, APITestCase): self.get_url(course_key=self.empty_course.id) ) expected_data = { - 'count': 0, 'next': None, 'previous': None, 'results': [], @@ -722,7 +721,6 @@ class GradebookViewTest(GradeViewTestMixin, APITestCase): self.assertEqual(status.HTTP_200_OK, resp.status_code) actual_data = dict(resp.data) - self.assertEqual(2, actual_data['count']) self.assertIsNone(actual_data['next']) self.assertIsNone(actual_data['previous']) self.assertEqual(expected_results, actual_data['results']) diff --git a/lms/djangoapps/grades/api/v1/views.py b/lms/djangoapps/grades/api/v1/views.py index c5b747e452..becf4b7906 100644 --- a/lms/djangoapps/grades/api/v1/views.py +++ b/lms/djangoapps/grades/api/v1/views.py @@ -9,7 +9,7 @@ from django.urls import reverse from rest_framework import status from rest_framework.exceptions import AuthenticationFailed from rest_framework.generics import GenericAPIView -from rest_framework.pagination import PageNumberPagination +from rest_framework.pagination import CursorPagination from rest_framework.response import Response from six import text_type @@ -93,6 +93,14 @@ def verify_writable_gradebook_enabled(view_func): return wrapped_function +class CourseEnrollmentPagination(CursorPagination): + """ + Paginates over CourseEnrollment objects. + """ + page_size = 25 + ordering = 'id' + + class GradeViewMixin(DeveloperErrorViewMixin): """ Mixin class for Grades related views. @@ -316,6 +324,8 @@ class CourseGradesView(GradeViewMixin, GenericAPIView): permission_classes = (permissions.JWT_RESTRICTED_APPLICATION_OR_USER_ACCESS,) + pagination_class = CourseEnrollmentPagination + required_scopes = ['grades:read'] @verify_course_exists @@ -342,11 +352,6 @@ class CourseGradesView(GradeViewMixin, GenericAPIView): return self._get_user_grades(course_key) -class GradebookPagination(PageNumberPagination): - page_size = 25 - page_size_query_param = 'page_size' - - class GradebookView(GradeViewMixin, GenericAPIView): """ **Use Case** @@ -452,9 +457,9 @@ class GradebookView(GradeViewMixin, GenericAPIView): permission_classes = (permissions.JWT_RESTRICTED_APPLICATION_OR_USER_ACCESS,) - required_scopes = ['grades:read'] + pagination_class = CourseEnrollmentPagination - pagination_class = GradebookPagination + required_scopes = ['grades:read'] def _section_breakdown(self, course_grade): """