8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00
re2o/api/pagination.py

21 lines
612 B
Python
Raw Normal View History

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',)
2018-05-24 23:06:03 +00:00
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:
2018-05-24 23:06:03 +00:00
return self.max_page_size
except KeyError:
pass
return super(PageSizedPagination, self).get_page_size(request)