Add a GET API endpoint for program enrollments.

This commit is contained in:
Alex Dusenbery
2019-04-29 13:00:26 -04:00
committed by Alex Dusenbery
parent c8f8e05616
commit 20f0bc03d4
18 changed files with 485 additions and 47 deletions

View File

@@ -15,6 +15,7 @@ from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin
from rest_framework.permissions import IsAuthenticated
from rest_framework.request import clone_request
from rest_framework.response import Response
from rest_framework.views import APIView
from six import text_type, iteritems
from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser
@@ -304,3 +305,36 @@ class LazySequence(Sequence):
self.iterable,
self.est_len,
)
class PaginatedAPIView(APIView):
"""
An `APIView` class enhanced with the pagination methods of `GenericAPIView`.
"""
# pylint: disable=attribute-defined-outside-init
@property
def paginator(self):
"""
The paginator instance associated with the view, or `None`.
"""
if not hasattr(self, '_paginator'):
if self.pagination_class is None:
self._paginator = None
else:
self._paginator = self.pagination_class()
return self._paginator
def paginate_queryset(self, queryset):
"""
Return a single page of results, or `None` if pagination is disabled.
"""
if self.paginator is None:
return None
return self.paginator.paginate_queryset(queryset, self.request, view=self)
def get_paginated_response(self, data):
"""
Return a paginated style `Response` object for the given output data.
"""
assert self.paginator is not None
return self.paginator.get_paginated_response(data)