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
35c28a2a
Commit
35c28a2a
authored
Jun 05, 2015
by
Ash Hoover
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include correct limits in LimitOffsetPagination link urls
parent
8935db1b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
rest_framework/pagination.py
+3
-0
tests/test_pagination.py
+26
-0
No files found.
rest_framework/pagination.py
View file @
35c28a2a
...
...
@@ -431,6 +431,8 @@ class LimitOffsetPagination(BasePagination):
return
None
url
=
self
.
request
.
build_absolute_uri
()
url
=
replace_query_param
(
url
,
self
.
limit_query_param
,
self
.
limit
)
offset
=
self
.
offset
+
self
.
limit
return
replace_query_param
(
url
,
self
.
offset_query_param
,
offset
)
...
...
@@ -439,6 +441,7 @@ class LimitOffsetPagination(BasePagination):
return
None
url
=
self
.
request
.
build_absolute_uri
()
url
=
replace_query_param
(
url
,
self
.
limit_query_param
,
self
.
limit
)
if
self
.
offset
-
self
.
limit
<=
0
:
return
remove_query_param
(
url
,
self
.
offset_query_param
)
...
...
tests/test_pagination.py
View file @
35c28a2a
...
...
@@ -287,6 +287,8 @@ class TestLimitOffset:
def
setup
(
self
):
class
ExamplePagination
(
pagination
.
LimitOffsetPagination
):
default_limit
=
10
max_limit
=
15
self
.
pagination
=
ExamplePagination
()
self
.
queryset
=
range
(
1
,
101
)
...
...
@@ -442,7 +444,31 @@ class TestLimitOffset:
"""
request
=
Request
(
factory
.
get
(
'/'
,
{
'limit'
:
'invalid'
,
'offset'
:
0
}))
queryset
=
self
.
paginate_queryset
(
request
)
content
=
self
.
get_paginated_content
(
queryset
)
next_limit
=
self
.
pagination
.
default_limit
next_offset
=
self
.
pagination
.
default_limit
next_url
=
'http://testserver/?limit={0}&offset={1}'
.
format
(
next_limit
,
next_offset
)
assert
queryset
==
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
assert
content
.
get
(
'next'
)
==
next_url
def
test_max_limit
(
self
):
"""
The limit defaults to the max_limit when there is a max_limit and the
requested limit is greater than the max_limit
"""
offset
=
50
request
=
Request
(
factory
.
get
(
'/'
,
{
'limit'
:
'11235'
,
'offset'
:
offset
}))
queryset
=
self
.
paginate_queryset
(
request
)
content
=
self
.
get_paginated_content
(
queryset
)
max_limit
=
self
.
pagination
.
max_limit
next_offset
=
offset
+
max_limit
prev_offset
=
offset
-
max_limit
base_url
=
'http://testserver/?limit={0}'
.
format
(
max_limit
)
next_url
=
base_url
+
'&offset={0}'
.
format
(
next_offset
)
prev_url
=
base_url
+
'&offset={0}'
.
format
(
prev_offset
)
assert
queryset
==
list
(
range
(
51
,
66
))
assert
content
.
get
(
'next'
)
==
next_url
assert
content
.
get
(
'previous'
)
==
prev_url
class
TestCursorPagination
:
...
...
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