@@ -169,9 +169,6 @@ class PageNumberPagination(BasePagination):
169
169
http://api.example.org/accounts/?page=4
170
170
http://api.example.org/accounts/?page=4&page_size=100
171
171
"""
172
- # The default page size.
173
- # Defaults to `None`, meaning pagination is disabled.
174
- page_size = api_settings .PAGE_SIZE
175
172
176
173
django_paginator_class = DjangoPaginator
177
174
@@ -184,18 +181,33 @@ class PageNumberPagination(BasePagination):
184
181
page_size_query_param = None
185
182
page_size_query_description = _ ('Number of results to return per page.' )
186
183
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
-
193
184
last_page_strings = ('last' ,)
194
185
195
186
template = 'rest_framework/pagination/numbers.html'
196
187
197
188
invalid_page_message = _ ('Invalid page.' )
198
189
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
+
199
211
def paginate_queryset (self , queryset , request , view = None ):
200
212
"""
201
213
Paginate a queryset if required, either returning a
@@ -379,14 +391,33 @@ class LimitOffsetPagination(BasePagination):
379
391
http://api.example.org/accounts/?limit=100
380
392
http://api.example.org/accounts/?offset=400&limit=100
381
393
"""
382
- default_limit = api_settings .PAGE_SIZE
383
394
limit_query_param = 'limit'
384
395
limit_query_description = _ ('Number of results to return per page.' )
385
396
offset_query_param = 'offset'
386
397
offset_query_description = _ ('The initial index from which to return the results.' )
387
- max_limit = api_settings .MAX_PAGE_SIZE
388
398
template = 'rest_framework/pagination/numbers.html'
389
399
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
+
390
421
def paginate_queryset (self , queryset , request , view = None ):
391
422
self .request = request
392
423
self .limit = self .get_limit (request )
@@ -590,7 +621,6 @@ class CursorPagination(BasePagination):
590
621
"""
591
622
cursor_query_param = 'cursor'
592
623
cursor_query_description = _ ('The pagination cursor value.' )
593
- page_size = api_settings .PAGE_SIZE
594
624
invalid_cursor_message = _ ('Invalid cursor' )
595
625
ordering = '-created'
596
626
template = 'rest_framework/pagination/previous_and_next.html'
@@ -600,16 +630,33 @@ class CursorPagination(BasePagination):
600
630
page_size_query_param = None
601
631
page_size_query_description = _ ('Number of results to return per page.' )
602
632
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
-
607
633
# The offset in the cursor is used in situations where we have a
608
634
# nearly-unique index. (Eg millisecond precision creation timestamps)
609
635
# We guard against malicious users attempting to cause expensive database
610
636
# queries, by having a hard cap on the maximum possible size of the offset.
611
637
offset_cutoff = 1000
612
638
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
+
613
660
def paginate_queryset (self , queryset , request , view = None ):
614
661
self .request = request
615
662
self .page_size = self .get_page_size (request )
0 commit comments