8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-24 07:53:47 +00:00
re2o/api/pagination.py
2018-06-20 11:38:58 +00:00

20 lines
612 B
Python

from rest_framework import pagination
class PageSizedPagination(pagination.PageNumberPagination):
"""
Pagination subclass to all to control the page size
"""
page_size_query_param = 'page_size'
all_pages_strings = ('all',)
max_page_size = 10000
def get_page_size(self, request):
try:
page_size_str = request.query_params[self.page_size_query_param]
if page_size_str in self.all_pages_strings:
return self.max_page_size
except KeyError:
pass
return super(PageSizedPagination, self).get_page_size(request)