Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
30b36a59
Commit
30b36a59
authored
Jun 12, 2015
by
homm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use PageSizePaginationMixin for CursorPagination
tests for custom page_size in CursorPagination
parent
9a5373d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
3 deletions
+23
-3
rest_framework/pagination.py
+3
-3
tests/test_pagination.py
+20
-0
No files found.
rest_framework/pagination.py
View file @
30b36a59
...
@@ -487,20 +487,20 @@ class LimitOffsetPagination(BasePagination):
...
@@ -487,20 +487,20 @@ class LimitOffsetPagination(BasePagination):
return
template
.
render
(
context
)
return
template
.
render
(
context
)
class
CursorPagination
(
BasePagination
):
class
CursorPagination
(
BasePag
eSizePag
ination
):
"""
"""
The cursor pagination implementation is neccessarily complex.
The cursor pagination implementation is neccessarily complex.
For an overview of the position/offset style we use, see this post:
For an overview of the position/offset style we use, see this post:
http://cramer.io/2011/03/08/building-cursors-for-the-disqus-api/
http://cramer.io/2011/03/08/building-cursors-for-the-disqus-api/
"""
"""
cursor_query_param
=
'cursor'
cursor_query_param
=
'cursor'
page_size
=
api_settings
.
PAGE_SIZE
invalid_cursor_message
=
_
(
'Invalid cursor'
)
invalid_cursor_message
=
_
(
'Invalid cursor'
)
ordering
=
'-created'
ordering
=
'-created'
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
:
self
.
page_size
=
self
.
get_page_size
(
request
)
if
not
self
.
page_size
:
return
None
return
None
self
.
base_url
=
request
.
build_absolute_uri
()
self
.
base_url
=
request
.
build_absolute_uri
()
...
...
tests/test_pagination.py
View file @
30b36a59
...
@@ -508,6 +508,8 @@ class TestCursorPagination:
...
@@ -508,6 +508,8 @@ class TestCursorPagination:
class
ExamplePagination
(
pagination
.
CursorPagination
):
class
ExamplePagination
(
pagination
.
CursorPagination
):
page_size
=
5
page_size
=
5
page_size_query_param
=
'page_size'
max_page_size
=
20
ordering
=
'created'
ordering
=
'created'
self
.
pagination
=
ExamplePagination
()
self
.
pagination
=
ExamplePagination
()
...
@@ -643,6 +645,24 @@ class TestCursorPagination:
...
@@ -643,6 +645,24 @@ class TestCursorPagination:
assert
isinstance
(
self
.
pagination
.
to_html
(),
type
(
''
))
assert
isinstance
(
self
.
pagination
.
to_html
(),
type
(
''
))
def
test_page_size
(
self
):
(
previous
,
current
,
next
,
previous_url
,
next_url
)
=
\
self
.
get_pages
(
'/?page_size=10'
)
assert
previous
is
None
assert
current
==
[
1
,
1
,
1
,
1
,
1
,
1
,
2
,
3
,
4
,
4
]
assert
next
==
[
4
,
4
,
5
,
6
,
7
,
7
,
7
,
7
,
7
,
7
]
assert
'page_size=10'
in
next_url
(
previous
,
current
,
next
,
previous_url
,
next_url
)
=
\
self
.
get_pages
(
next_url
.
replace
(
'page_size=10'
,
'page_size=4'
))
assert
previous
==
[
2
,
3
,
4
,
4
]
assert
current
==
[
4
,
4
,
5
,
6
]
assert
next
==
[
7
,
7
,
7
,
7
]
assert
'page_size=4'
in
previous_url
assert
'page_size=4'
in
next_url
def
test_get_displayed_page_numbers
():
def
test_get_displayed_page_numbers
():
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment