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
f5a4fc97
Commit
f5a4fc97
authored
Jan 05, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #111 from j4mie/url-generation
Preserve existing query params in PaginatorMixin
parents
b745d0c2
18535c7a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
2 deletions
+17
-2
djangorestframework/mixins.py
+4
-2
djangorestframework/tests/mixins.py
+11
-0
requirements.txt
+1
-0
setup.py
+1
-0
No files found.
djangorestframework/mixins.py
View file @
f5a4fc97
...
@@ -7,6 +7,7 @@ from django.contrib.auth.models import AnonymousUser
...
@@ -7,6 +7,7 @@ from django.contrib.auth.models import AnonymousUser
from
django.core.paginator
import
Paginator
from
django.core.paginator
import
Paginator
from
django.db.models.fields.related
import
ForeignKey
from
django.db.models.fields.related
import
ForeignKey
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
urlobject
import
URLObject
from
djangorestframework
import
status
from
djangorestframework
import
status
from
djangorestframework.renderers
import
BaseRenderer
from
djangorestframework.renderers
import
BaseRenderer
...
@@ -659,11 +660,12 @@ class PaginatorMixin(object):
...
@@ -659,11 +660,12 @@ class PaginatorMixin(object):
def
url_with_page_number
(
self
,
page_number
):
def
url_with_page_number
(
self
,
page_number
):
""" Constructs a url used for getting the next/previous urls """
""" Constructs a url used for getting the next/previous urls """
url
=
"
%
s?page=
%
d"
%
(
self
.
request
.
path
,
page_number
)
url
=
URLObject
.
parse
(
self
.
request
.
get_full_path
())
url
=
url
.
add_query_param
(
'page'
,
page_number
)
limit
=
self
.
get_limit
()
limit
=
self
.
get_limit
()
if
limit
!=
self
.
limit
:
if
limit
!=
self
.
limit
:
url
=
"
%
s&limit=
%
d"
%
(
url
,
limit
)
url
=
url
.
add_query_param
(
'limit'
,
limit
)
return
url
return
url
...
...
djangorestframework/tests/mixins.py
View file @
f5a4fc97
...
@@ -237,3 +237,14 @@ class TestPagination(TestCase):
...
@@ -237,3 +237,14 @@ class TestPagination(TestCase):
response
=
MockPaginatorView
.
as_view
()(
request
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
NOT_FOUND
)
self
.
assertEqual
(
response
.
status_code
,
status
.
NOT_FOUND
)
def
test_existing_query_parameters_are_preserved
(
self
):
""" Tests that existing query parameters are preserved when
generating next/previous page links """
request
=
self
.
req
.
get
(
'/paginator/?foo=bar&another=something'
)
response
=
MockPaginatorView
.
as_view
()(
request
)
content
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
.
status_code
,
status
.
OK
)
self
.
assertTrue
(
'foo=bar'
in
content
[
'next'
])
self
.
assertTrue
(
'another=something'
in
content
[
'next'
])
self
.
assertTrue
(
'page=2'
in
content
[
'next'
])
requirements.txt
View file @
f5a4fc97
...
@@ -3,3 +3,4 @@
...
@@ -3,3 +3,4 @@
Django
>=1.2
Django
>=1.2
coverage
>=3.4
coverage
>=3.4
URLObject
>=0.6.0
setup.py
View file @
f5a4fc97
...
@@ -26,6 +26,7 @@ setup(
...
@@ -26,6 +26,7 @@ setup(
package_dir
=
{
'djangorestframework'
:
'djangorestframework'
},
package_dir
=
{
'djangorestframework'
:
'djangorestframework'
},
package_data
=
{
'djangorestframework'
:
[
'templates/*'
,
'static/*'
]},
package_data
=
{
'djangorestframework'
:
[
'templates/*'
,
'static/*'
]},
test_suite
=
'djangorestframework.runtests.runcoverage.main'
,
test_suite
=
'djangorestframework.runtests.runcoverage.main'
,
install_requires
=
[
'URLObject>=0.6.0'
],
classifiers
=
[
classifiers
=
[
'Development Status :: 4 - Beta'
,
'Development Status :: 4 - Beta'
,
'Environment :: Web Environment'
,
'Environment :: Web Environment'
,
...
...
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