@@ -407,7 +407,7 @@ def to_html(self):
407
407
408
408
class CursorPagination (BasePagination ):
409
409
"""
410
- The cursor pagination implementation is neccessarily complex.
410
+ The cursor pagination implementation is necessarily complex.
411
411
For an overview of the position/offset style we use, see this post:
412
412
http://cramer.io/2011/03/08/building-cursors-for-the-disqus-api
413
413
"""
@@ -417,6 +417,12 @@ class CursorPagination(BasePagination):
417
417
ordering = '-created'
418
418
template = 'rest_framework/pagination/previous_and_next.html'
419
419
420
+ # The offset in the cursor is used in situations where we have a
421
+ # nearly-unique index. (Eg millisecond precision creation timestamps)
422
+ # We guard against malicious users attempting to cause expensive database
423
+ # queries, by having a hard cap on the maximum possible size of the offset.
424
+ offset_cutoff = 1000
425
+
420
426
def paginate_queryset (self , queryset , request , view = None ):
421
427
self .page_size = self .get_page_size (request )
422
428
if not self .page_size :
@@ -647,18 +653,12 @@ def decode_cursor(self, request):
647
653
if encoded is None :
648
654
return None
649
655
650
- # The offset in the cursor is used in situations where we have a
651
- # nearly-unique index. (Eg millisecond precision creation timestamps)
652
- # We guard against malicious users attempting to cause expensive database
653
- # queries, by having a hard cap on the maximum possible size of the offset.
654
- OFFSET_CUTOFF = 1000
655
-
656
656
try :
657
657
querystring = b64decode (encoded .encode ('ascii' )).decode ('ascii' )
658
658
tokens = urlparse .parse_qs (querystring , keep_blank_values = True )
659
659
660
660
offset = tokens .get ('o' , ['0' ])[0 ]
661
- offset = _positive_int (offset , cutoff = OFFSET_CUTOFF )
661
+ offset = _positive_int (offset , cutoff = self . offset_cutoff )
662
662
663
663
reverse = tokens .get ('r' , ['0' ])[0 ]
664
664
reverse = bool (int (reverse ))
0 commit comments