Skip to content
Browse files

Make pagination keep arguments passed to the pager to create urls.

  • Loading branch information...
1 parent 4323710 commit e61c2d94675153493019a30806de8280d59e97d2 @amol- amol- committed Jun 21, 2011
View
6 tests/test_stack/rendering/controllers/root.py
@@ -74,6 +74,12 @@ def paginated(self, n):
@expose('genshi:genshi_paginated.html')
@paginate('testdata')
+ def paginate_with_params(self, n):
+ url_params = dict(param1='hi', param2='man')
+ return dict(testdata=range(int(n)), url_params=url_params)
+
+ @expose('genshi:genshi_paginated.html')
+ @paginate('testdata')
@validate(dict(n=validators.Int()))
def paginated_validated(self, n):
return dict(testdata=range(n))
View
7 tests/test_stack/rendering/templates/genshi_paginated.html
@@ -6,7 +6,12 @@
<title>Pagination Test</title>
</head>
<body>
-<div id="pager" py:content="c.paginators.testdata.pager()"/>
+<py:if test="not defined('url_params')">
+ <div id="pager" py:content="c.paginators.testdata.pager()"/>
+</py:if>
+<py:if test="defined('url_params')">
+ <div id="pager" py:content="c.paginators.testdata.pager(link='/fake_url', partial='/partial_url', **url_params)"/>
+</py:if>
<ul id="data"><li py:for="item in testdata" py:content="item"/></ul>
</body>
</html>
View
13 tests/test_stack/rendering/test_pagination.py
@@ -53,3 +53,16 @@ def test_validation_with_pagination(self):
page = self.app.get(url)
assert '<li>0</li>' not in page
assert '<li>10</li>' in page
+
+ def test_pagination_with_link_args(self):
+ url = '/paginate_with_params/42'
+ page = self.app.get(url)
+ assert 'param1=hi' in page
+ assert 'param2=man' in page
+ assert 'partial' not in page
+ assert '/fake_url' in page
+ url = '/paginate_with_params/42?page=2'
+ page = self.app.get(url)
+ print page
+ assert '<li>0</li>' not in page
+ assert '<li>10</li>' in page
View
11 tg/paginate.py
@@ -1,6 +1,7 @@
from webhelpers.paginate import Page as WhPage
from webhelpers.html import HTML
from tg import request
+from tg.controllers.util import url
class Page(WhPage):
@@ -30,12 +31,12 @@ def _pagerlink(self, pagenr, text):
link_params.update(self.pager_kwargs)
link_params[self.page_param] = pagenr
- # Create the URL to load a certain page
- link_url = link_params.get('link', request.path_info)
- link_url = '%s?page=%s'%(link_url, pagenr)
# Create the URL to load the page area part of a certain page (AJAX updates)
- #link_params[self.partial_param] = 1
- partial_url = link_params.get('partial', '') #url_for(**link_params)
+ partial_url = link_params.pop('partial', '') #url_for(**link_params)
+
+ # Create the URL to load a certain page
+ link_url = link_params.pop('link', request.path_info)
+ link_url = HTML.literal(url(link_url, params=link_params))
if self.onclick: # create link with onclick action for AJAX
try: # if '%s' is used in the 'onclick' parameter (backwards compatibility)

0 comments on commit e61c2d9

Please sign in to comment.
Something went wrong with that request. Please try again.