How do I use paginate in conjunction with a controller method that
takes multiple parameters? I have a search page that takes a url in the
form "page.html?search=xxx". I'd like to be able to use the pagination
decorator - however, I can't figure out how to get the pagination
decorator to combine my "search=" query parameter with its own query
params.You would think that get_href would take optional params
indicating additional query params - just like tg.url does.
(And you can't use tg.url to glue together the pagination url and your
own query, because that just adds an extra '?' making the URL invalid.)
-- Talin
In the file paginate.py:
- def get_href(self, page, order=None, reverse_order=None):
+ def get_href(self, page, order=None, reverse_order=None, **kw):
- return turbogears.url('', self.input_values)
+ return turbogears.url('', self.input_values, **kw)
Hope that helps, I haven't had a chance to test this so it may not work
first try.
-Adam
AMAZING ! I took the patch in #1115 and replaced the encoding with the formencode version. Works like a charm.
I had as sneaky suspicion that the code was in there somewhere...
Thanks for the tip!
In the standard paginate.py I added the following as the first line of Paginate.__init__():
input_values = variable_encode(input_values)
Don't forget to import...
Nicky
input_values =
variable_encode(cherrypy.request.params.copy())
input_values.pop('self', None)
for input_key in input_values.keys():
if input_key.startswith('tg_paginate'):
del input_values[input_key]
Going to http://localhost:8080/admin/brand/editImages?id=1 makes:
A page url: http://localhost:8080/admin/brand/editImages?tg_paginate_limit=2&id=1&tg_paginate_no=2
But the next/last urls:
http://localhost:8080/admin/brand/editImages?tg_paginate_limit=2
I looked at the code and it looks like the input values should be okay
when they get to making the urls but it is not working. How can I get
the id in that next/last urls?
Thanks.
-Ian
-Ian
Randall
Patch 5 should work for you. Note that until I can write a full set of
tests for it, I don't consider the paginate changes stable.
Randall
-Ian
So the quickstart you sent me works but I realized that my example was
not working because my template tries to use the urls in tg.paginate
like this:
<div>
<span><a
href="${tg.paginate.href_first}">First</a></span>
<span><a href="${tg.paginate.href_prev}">Prev</a></span>
<span py:for="page in tg.paginate.pages">
<a py:if="page != tg.paginate.current_page"
href="${tg.paginate.get_href(page)}">${page}</a>
<b py:if="page ==
tg.paginate.current_page">${page}</b>
</span>
<span><a href="${tg.paginate.href_next}">Next</a></span>
<span><a href="${tg.paginate.href_last}">Last</a></span>
</div>
Somehow the input_values got updated and put in self but the following
lines didn't get tended to: So this seems to be the problem(These
lines numbers are probably not correct in reference to the current
source):
160c117
< self.href_next = turbogears.url(cherrypy.request.path,
self.input_values)
---
> self.href_next = turbogears.url(cherrypy.request.path, input_values)
164c121
< self.href_last = turbogears.url(cherrypy.request.path,
self.input_values)
---
> self.href_last = turbogears.url(cherrypy.request.path, input_values)
173c130
< self.href_prev = turbogears.url(cherrypy.request.path,
self.input_values)
---
> self.href_prev = turbogears.url(cherrypy.request.path, input_values)
177c134
< self.href_first = turbogears.url(cherrypy.request.path,
self.input_values)
---
> self.href_first = turbogears.url(cherrypy.request.path, input_values)
-Ian