Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed ``Paginator`` appending multiple ``offset/limit`` values to que…

…rystring.
  • Loading branch information...
commit 4b208f727bc9a6dcd0fa1f8da563e236cd8cf73e 1 parent 868daa0
@jbrownbridge jbrownbridge authored toastdriven committed
Showing with 28 additions and 0 deletions.
  1. +8 −0 tastypie/paginator.py
  2. +20 −0 tests/core/tests/paginator.py
View
8 tastypie/paginator.py
@@ -157,6 +157,10 @@ def _generate_uri(self, limit, offset):
try:
# QueryDict has a urlencode method that can handle multiple values for the same key
request_params = self.request_data.copy()
+ if 'limit' in request_params:
+ del request_params['limit']
+ if 'offset' in request_params:
+ del request_params['offset']
request_params.update({'limit': limit, 'offset': offset})
encoded_params = request_params.urlencode()
except AttributeError:
@@ -168,6 +172,10 @@ def _generate_uri(self, limit, offset):
else:
request_params[k] = v
+ if 'limit' in request_params:
+ del request_params['limit']
+ if 'offset' in request_params:
+ del request_params['offset']
request_params.update({'limit': limit, 'offset': offset})
encoded_params = urlencode(request_params)
View
20 tests/core/tests/paginator.py
@@ -69,6 +69,26 @@ def test_page3(self):
self.assertEqual(meta['next'], None)
self.assertEqual(meta['total_count'], 6)
+ def test_page2_with_request(self):
+ for req in [{'offset' : '2', 'limit' : '2'}, QueryDict('offset=2&limit=2')]:
+ paginator = Paginator(req, self.data_set, resource_uri='/api/v1/notes/', limit=2, offset=2)
+ meta = paginator.page()['meta']
+ self.assertEqual(meta['limit'], 2)
+ self.assertEqual(meta['offset'], 2)
+ self.assertEqual(meta['previous'], '/api/v1/notes/?limit=2&offset=0')
+ self.assertEqual(meta['next'], '/api/v1/notes/?limit=2&offset=4')
+ self.assertEqual(meta['total_count'], 6)
+
+ def test_page3_with_request(self):
+ for req in [{'offset' : '4', 'limit' : '2'}, QueryDict('offset=4&limit=2')]:
+ paginator = Paginator(req, self.data_set, resource_uri='/api/v1/notes/', limit=2, offset=4)
+ meta = paginator.page()['meta']
+ self.assertEqual(meta['limit'], 2)
+ self.assertEqual(meta['offset'], 4)
+ self.assertEqual(meta['previous'], '/api/v1/notes/?limit=2&offset=2')
+ self.assertEqual(meta['next'], None)
+ self.assertEqual(meta['total_count'], 6)
+
def test_large_limit(self):
paginator = Paginator({}, self.data_set, resource_uri='/api/v1/notes/', limit=20, offset=0)
meta = paginator.page()['meta']
Please sign in to comment.
Something went wrong with that request. Please try again.