diff options
| author | Tom Christie | 2013-01-15 17:53:24 +0000 |
|---|---|---|
| committer | Tom Christie | 2013-01-15 17:53:24 +0000 |
| commit | 71e55cc4f6300959398f7aef4a8d91b6a6a2af57 (patch) | |
| tree | 68c2080034263d897741da33cbc5e09746006257 /rest_framework/pagination.py | |
| parent | 52847a215d4e8de88e81d9ae79ce8bee9a36a9a2 (diff) | |
| parent | e1076cfb49b6293aa837cf7bdb4c11988892c598 (diff) | |
| download | django-rest-framework-71e55cc4f6300959398f7aef4a8d91b6a6a2af57.tar.bz2 | |
Merge with latest master
Diffstat (limited to 'rest_framework/pagination.py')
| -rw-r--r-- | rest_framework/pagination.py | 17 |
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): |
