@@ -169,9 +169,6 @@ class PageNumberPagination(BasePagination):
169169 http://api.example.org/accounts/?page=4
170170 http://api.example.org/accounts/?page=4&page_size=100
171171 """
172- # The default page size.
173- # Defaults to `None`, meaning pagination is disabled.
174- page_size = api_settings .PAGE_SIZE
175172
176173django_paginator_class = DjangoPaginator
177174
@@ -184,18 +181,33 @@ class PageNumberPagination(BasePagination):
184181page_size_query_param = None
185182page_size_query_description = _ ('Number of results to return per page.' )
186183
187- # Set to an integer to limit the maximum page size the client may request.
188- # Only relevant if 'page_size_query_param' has also been set.
189- # Defaults to `None`, meaning page size is unlimited.
190- # It's recommended that you would set a limit to avoid api abuse.
191- max_page_size = api_settings .MAX_PAGE_SIZE
192-
193184last_page_strings = ('last' ,)
194185
195186template = 'rest_framework/pagination/numbers.html'
196187
197188invalid_page_message = _ ('Invalid page.' )
198189
190+ @property
191+ def page_size (self )-> int :
192+ """Get default page size.
193+
194+ Defaults to `None`, meaning pagination is disabled.
195+
196+ """
197+ return api_settings .PAGE_SIZE
198+
199+ @property
200+ def max_page_size (self )-> int :
201+ """Limit page size.
202+
203+ Set to an integer to limit the maximum page size the client may request.
204+ Only relevant if 'page_size_query_param' has also been set.
205+ Defaults to `None`, meaning page size is unlimited.
206+ It's recommended that you would set a limit to avoid api abuse.
207+
208+ """
209+ return api_settings .MAX_PAGE_SIZE
210+
199211def paginate_queryset (self ,queryset ,request ,view = None ):
200212"""
201213 Paginate a queryset if required, either returning a
@@ -379,14 +391,33 @@ class LimitOffsetPagination(BasePagination):
379391 http://api.example.org/accounts/?limit=100
380392 http://api.example.org/accounts/?offset=400&limit=100
381393 """
382- default_limit = api_settings .PAGE_SIZE
383394limit_query_param = 'limit'
384395limit_query_description = _ ('Number of results to return per page.' )
385396offset_query_param = 'offset'
386397offset_query_description = _ ('The initial index from which to return the results.' )
387- max_limit = api_settings .MAX_PAGE_SIZE
388398template = 'rest_framework/pagination/numbers.html'
389399
400+ @property
401+ def max_limit (self )-> int :
402+ """Limit maximum page size.
403+
404+ Set to an integer to limit the maximum page size the client may request.
405+ Only relevant if 'page_size_query_param' has also been set.
406+ Defaults to `None`, meaning page size is unlimited.
407+ It's recommended that you would set a limit to avoid api abuse.
408+
409+ """
410+ return api_settings .MAX_PAGE_SIZE
411+
412+ @property
413+ def default_limit (self )-> int :
414+ """Get default page size.
415+
416+ Defaults to `None`, meaning pagination is disabled.
417+
418+ """
419+ return api_settings .PAGE_SIZE
420+
390421def paginate_queryset (self ,queryset ,request ,view = None ):
391422self .request = request
392423self .limit = self .get_limit (request )
@@ -590,7 +621,6 @@ class CursorPagination(BasePagination):
590621 """
591622cursor_query_param = 'cursor'
592623cursor_query_description = _ ('The pagination cursor value.' )
593- page_size = api_settings .PAGE_SIZE
594624invalid_cursor_message = _ ('Invalid cursor' )
595625ordering = '-created'
596626template = 'rest_framework/pagination/previous_and_next.html'
@@ -600,16 +630,33 @@ class CursorPagination(BasePagination):
600630page_size_query_param = None
601631page_size_query_description = _ ('Number of results to return per page.' )
602632
603- # Set to an integer to limit the maximum page size the client may request.
604- # Only relevant if 'page_size_query_param' has also been set.
605- max_page_size = api_settings .MAX_PAGE_SIZE
606-
607633# The offset in the cursor is used in situations where we have a
608634# nearly-unique index. (Eg millisecond precision creation timestamps)
609635# We guard against malicious users attempting to cause expensive database
610636# queries, by having a hard cap on the maximum possible size of the offset.
611637offset_cutoff = 1000
612638
639+ @property
640+ def page_size (self )-> int :
641+ """Get default page size.
642+
643+ Defaults to `None`, meaning pagination is disabled.
644+
645+ """
646+ return api_settings .PAGE_SIZE
647+
648+ @property
649+ def max_page_size (self )-> int :
650+ """Limit page size.
651+
652+ Set to an integer to limit the maximum page size the client may request.
653+ Only relevant if 'page_size_query_param' has also been set.
654+ Defaults to `None`, meaning page size is unlimited.
655+ It's recommended that you would set a limit to avoid api abuse.
656+
657+ """
658+ return api_settings .MAX_PAGE_SIZE
659+
613660def paginate_queryset (self ,queryset ,request ,view = None ):
614661self .request = request
615662self .page_size = self .get_page_size (request )