You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
620 B
Python
23 lines
620 B
Python
# Copyright (C) 2019 Intel Corporation
|
|
#
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
import sys
|
|
from rest_framework.pagination import PageNumberPagination
|
|
|
|
class CustomPagination(PageNumberPagination):
|
|
page_size_query_param = "page_size"
|
|
|
|
def get_page_size(self, request):
|
|
page_size = 0
|
|
try:
|
|
value = request.query_params[self.page_size_query_param]
|
|
if value == "all":
|
|
page_size = sys.maxsize
|
|
else:
|
|
page_size = int(value)
|
|
except (KeyError, ValueError):
|
|
pass
|
|
|
|
return page_size if page_size > 0 else self.page_size
|