mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-05 04:50:12 +03:00
Merge f91d332c6c
into 003c304115
This commit is contained in:
commit
d4df1b8094
|
@ -572,7 +572,7 @@ class CursorPagination(BasePagination):
|
||||||
if not self.has_next:
|
if not self.has_next:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if self.cursor and self.cursor.reverse and self.cursor.offset != 0:
|
if self.cursor and self.cursor.reverse and self.cursor.offset != 0 and self.page:
|
||||||
# If we're reversing direction and we have an offset cursor
|
# If we're reversing direction and we have an offset cursor
|
||||||
# then we cannot use the first position we find as a marker.
|
# then we cannot use the first position we find as a marker.
|
||||||
compare = self._get_position_from_instance(self.page[-1], self.ordering)
|
compare = self._get_position_from_instance(self.page[-1], self.ordering)
|
||||||
|
@ -620,7 +620,7 @@ class CursorPagination(BasePagination):
|
||||||
if not self.has_previous:
|
if not self.has_previous:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if self.cursor and not self.cursor.reverse and self.cursor.offset != 0:
|
if self.cursor and not self.cursor.reverse and self.cursor.offset != 0 and self.page:
|
||||||
# If we're reversing direction and we have an offset cursor
|
# If we're reversing direction and we have an offset cursor
|
||||||
# then we cannot use the first position we find as a marker.
|
# then we cannot use the first position we find as a marker.
|
||||||
compare = self._get_position_from_instance(self.page[0], self.ordering)
|
compare = self._get_position_from_instance(self.page[0], self.ordering)
|
||||||
|
|
|
@ -9,7 +9,7 @@ from django.test import TestCase
|
||||||
from rest_framework import (
|
from rest_framework import (
|
||||||
exceptions, filters, generics, pagination, serializers, status
|
exceptions, filters, generics, pagination, serializers, status
|
||||||
)
|
)
|
||||||
from rest_framework.pagination import PAGE_BREAK, PageLink
|
from rest_framework.pagination import PAGE_BREAK, PageLink, Cursor
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.test import APIRequestFactory
|
from rest_framework.test import APIRequestFactory
|
||||||
|
|
||||||
|
@ -633,6 +633,16 @@ class CursorPaginationTestsMixin:
|
||||||
|
|
||||||
assert isinstance(self.pagination.to_html(), type(''))
|
assert isinstance(self.pagination.to_html(), type(''))
|
||||||
|
|
||||||
|
def test_offset_cutoff(self):
|
||||||
|
(previous, current, next, previous_url, next_url) = self.get_pages('/')
|
||||||
|
|
||||||
|
next_url = self.pagination.encode_cursor(Cursor(1050, False, None))
|
||||||
|
(previous, current, next, previous_url, next_url) = self.get_pages(next_url)
|
||||||
|
|
||||||
|
assert previous == [7, 7, 7, 8, 9]
|
||||||
|
assert current == []
|
||||||
|
assert next is None
|
||||||
|
|
||||||
|
|
||||||
class TestCursorPagination(CursorPaginationTestsMixin):
|
class TestCursorPagination(CursorPaginationTestsMixin):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user