Commit 9c952dcf by Tom Christie

Merge pull request #3147 from tomchristie/uploadcare-cursor-limits

Add `get_page_size` hook to `CursorPagination`
parents 3c57e08f 46836142
...@@ -455,7 +455,8 @@ class CursorPagination(BasePagination): ...@@ -455,7 +455,8 @@ class CursorPagination(BasePagination):
template = 'rest_framework/pagination/previous_and_next.html' template = 'rest_framework/pagination/previous_and_next.html'
def paginate_queryset(self, queryset, request, view=None): def paginate_queryset(self, queryset, request, view=None):
if self.page_size is None: page_size = self.get_page_size(request)
if not page_size:
return None return None
self.base_url = request.build_absolute_uri() self.base_url = request.build_absolute_uri()
...@@ -490,8 +491,8 @@ class CursorPagination(BasePagination): ...@@ -490,8 +491,8 @@ class CursorPagination(BasePagination):
# If we have an offset cursor then offset the entire page by that amount. # If we have an offset cursor then offset the entire page by that amount.
# We also always fetch an extra item in order to determine if there is a # We also always fetch an extra item in order to determine if there is a
# page following on from this one. # page following on from this one.
results = list(queryset[offset:offset + self.page_size + 1]) results = list(queryset[offset:offset + page_size + 1])
self.page = list(results[:self.page_size]) self.page = list(results[:page_size])
# Determine the position of the final item following the page. # Determine the position of the final item following the page.
if len(results) > len(self.page): if len(results) > len(self.page):
...@@ -530,6 +531,9 @@ class CursorPagination(BasePagination): ...@@ -530,6 +531,9 @@ class CursorPagination(BasePagination):
return self.page return self.page
def get_page_size(self, request):
return self.page_size
def get_next_link(self): def get_next_link(self):
if not self.has_next: if not self.has_next:
return None return None
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment