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
2e7fae76
Commit
2e7fae76
authored
Jun 13, 2016
by
Tom Christie
Committed by
GitHub
Jun 13, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
limit=0 should revert to default limit (#4194)
parent
c3b7fba9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
25 deletions
+14
-25
rest_framework/pagination.py
+1
-0
tests/test_pagination.py
+13
-25
No files found.
rest_framework/pagination.py
View file @
2e7fae76
...
@@ -319,6 +319,7 @@ class LimitOffsetPagination(BasePagination):
...
@@ -319,6 +319,7 @@ class LimitOffsetPagination(BasePagination):
try
:
try
:
return
_positive_int
(
return
_positive_int
(
request
.
query_params
[
self
.
limit_query_param
],
request
.
query_params
[
self
.
limit_query_param
],
strict
=
True
,
cutoff
=
self
.
max_limit
cutoff
=
self
.
max_limit
)
)
except
(
KeyError
,
ValueError
):
except
(
KeyError
,
ValueError
):
...
...
tests/test_pagination.py
View file @
2e7fae76
...
@@ -486,6 +486,19 @@ class TestLimitOffset:
...
@@ -486,6 +486,19 @@ class TestLimitOffset:
assert
queryset
==
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
assert
queryset
==
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
]
assert
content
.
get
(
'next'
)
==
next_url
assert
content
.
get
(
'next'
)
==
next_url
def
test_zero_limit
(
self
):
"""
An zero limit query param should be ignored in favor of the default.
"""
request
=
Request
(
factory
.
get
(
'/'
,
{
'limit'
:
0
,
'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
):
def
test_max_limit
(
self
):
"""
"""
The limit defaults to the max_limit when there is a max_limit and the
The limit defaults to the max_limit when there is a max_limit and the
...
@@ -505,31 +518,6 @@ class TestLimitOffset:
...
@@ -505,31 +518,6 @@ class TestLimitOffset:
assert
content
.
get
(
'next'
)
==
next_url
assert
content
.
get
(
'next'
)
==
next_url
assert
content
.
get
(
'previous'
)
==
prev_url
assert
content
.
get
(
'previous'
)
==
prev_url
def
test_limit_zero
(
self
):
"""
A limit of 0 should return empty results.
"""
request
=
Request
(
factory
.
get
(
'/'
,
{
'limit'
:
0
,
'offset'
:
10
}))
queryset
=
self
.
paginate_queryset
(
request
)
context
=
self
.
get_html_context
()
content
=
self
.
get_paginated_content
(
queryset
)
assert
context
==
{
'previous_url'
:
'http://testserver/?limit=0&offset=10'
,
'page_links'
:
[
PageLink
(
url
=
'http://testserver/?limit=0'
,
number
=
1
,
is_active
=
True
,
is_break
=
False
)
],
'next_url'
:
'http://testserver/?limit=0&offset=10'
}
assert
queryset
==
[]
assert
content
.
get
(
'results'
)
==
[]
class
TestCursorPagination
:
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