|
|
|
@ -1,12 +1,23 @@ |
|
|
|
from rest_framework.pagination import PageNumberPagination, LimitOffsetPagination |
|
|
|
from rest_framework.response import Response |
|
|
|
|
|
|
|
|
|
|
|
from rest_framework.pagination import PageNumberPagination |
|
|
|
from rest_framework.response import Response |
|
|
|
class StandardResultsSetPagination(PageNumberPagination): |
|
|
|
page_size = 16 |
|
|
|
page_size_query_param = 'page_size' |
|
|
|
max_page_size = 100 |
|
|
|
|
|
|
|
def get_paginated_response(self, data): |
|
|
|
return Response({ |
|
|
|
'count': self.page.paginator.count, |
|
|
|
'next': self.get_next_link(), |
|
|
|
'previous': self.get_previous_link(), |
|
|
|
'results': data, |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
class NoPagination(PageNumberPagination): |
|
|
|
def paginate_queryset(self, queryset, request, view=None): |
|
|
|
# Override to return all items instead of paginated ones |
|
|
|
self.count = len(queryset) |
|
|
|
self.request = request |
|
|
|
self.page = None |
|
|
|
@ -14,10 +25,9 @@ class NoPagination(PageNumberPagination): |
|
|
|
return list(queryset) |
|
|
|
|
|
|
|
def get_paginated_response(self, data): |
|
|
|
# Keep the structure but include all results |
|
|
|
return Response({ |
|
|
|
'count': self.count, |
|
|
|
'next': None, # No next page |
|
|
|
'previous': None, # No previous page |
|
|
|
'next': None, |
|
|
|
'previous': None, |
|
|
|
'results': data, |
|
|
|
}) |