|
26 | 26 | from rest_framework import generics, mixins, views
|
27 | 27 | from rest_framework.decorators import MethodMapper
|
28 | 28 | from rest_framework.reverse import reverse
|
| 29 | +from rest_framework.settings import api_settings |
29 | 30 |
|
30 | 31 |
|
31 | 32 | def _is_extra_action(attr):
|
@@ -214,7 +215,35 @@ class ViewSet(ViewSetMixin, views.APIView):
|
214 | 215 | """
|
215 | 216 | The base ViewSet class does not provide any actions by default.
|
216 | 217 | """
|
217 |
| - pass |
| 218 | + |
| 219 | + pagination_class = api_settings.DEFAULT_PAGINATION_CLASS |
| 220 | + |
| 221 | + @property |
| 222 | + def paginator(self): |
| 223 | + """ |
| 224 | + The paginator instance associated with the view, or `None`. |
| 225 | + """ |
| 226 | + if not hasattr(self, "_paginator"): |
| 227 | + if self.pagination_class is None: |
| 228 | + self._paginator = None |
| 229 | + else: |
| 230 | + self._paginator = self.pagination_class() |
| 231 | + return self._paginator |
| 232 | + |
| 233 | + def paginate_queryset(self, queryset): |
| 234 | + """ |
| 235 | + Return a single page of results, or `None` if pagination is disabled. |
| 236 | + """ |
| 237 | + if self.paginator is None: |
| 238 | + return None |
| 239 | + return self.paginator.paginate_queryset(queryset, self.request, view=self) |
| 240 | + |
| 241 | + def get_paginated_response(self, data): |
| 242 | + """ |
| 243 | + Return a paginated style `Response` object for the given output data. |
| 244 | + """ |
| 245 | + assert self.paginator is not None |
| 246 | + return self.paginator.get_paginated_response(data) |
218 | 247 |
|
219 | 248 |
|
220 | 249 | class GenericViewSet(ViewSetMixin, generics.GenericAPIView):
|
|
0 commit comments