aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/pagination.py
diff options
context:
space:
mode:
authorTom Christie2012-11-09 13:49:52 +0000
committerTom Christie2012-11-09 13:49:52 +0000
commit8953a60196cb55ec75902882314da5a42636349c (patch)
tree43bf6ea1f69955aeecd83fb9f866d92ea9a5f3df /rest_framework/pagination.py
parentb78872b7dbb55f1aa2d21f15fbb952f0c7156326 (diff)
parent9aaeeacdfebc244850e82469e4af45af252cca4d (diff)
downloaddjango-rest-framework-8953a60196cb55ec75902882314da5a42636349c.tar.bz2
Merge with master
Diffstat (limited to 'rest_framework/pagination.py')
-rw-r--r--rest_framework/pagination.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py
index 131718fd..d241ade7 100644
--- a/rest_framework/pagination.py
+++ b/rest_framework/pagination.py
@@ -1,4 +1,5 @@
from rest_framework import serializers
+from rest_framework.templatetags.rest_framework import replace_query_param
# TODO: Support URLconf kwarg-style paging
@@ -7,30 +8,30 @@ class NextPageField(serializers.Field):
"""
Field that returns a link to the next page in paginated results.
"""
+ page_field = 'page'
+
def to_native(self, value):
if not value.has_next():
return None
page = value.next_page_number()
request = self.context.get('request')
- relative_url = '?page=%d' % page
- if request:
- return request.build_absolute_uri(relative_url)
- return relative_url
+ url = request and request.build_absolute_uri() or ''
+ return replace_query_param(url, self.page_field, page)
class PreviousPageField(serializers.Field):
"""
Field that returns a link to the previous page in paginated results.
"""
+ page_field = 'page'
+
def to_native(self, value):
if not value.has_previous():
return None
page = value.previous_page_number()
request = self.context.get('request')
- relative_url = '?page=%d' % page
- if request:
- return request.build_absolute_uri('?page=%d' % page)
- return relative_url
+ url = request and request.build_absolute_uri() or ''
+ return replace_query_param(url, self.page_field, page)
class PaginationSerializerOptions(serializers.SerializerOptions):