Recently we discussed the problem of keeping the pagination state
(e.g. if you have an edit link in a grid and want to return to the
same page after editing). It seems TG does not offer a simple solution
for this so far and people are forced to invent various tricky ways to
overcome this problem, involving cookies, Referer header,
cherrypy.path, hidden fields etc.

As a general solution, I have now written a simple decorator called
"recollect" that will make TG recollect all parameters passed to an
exposed method. This is achieved by storing these parameters in the
cherrypy.session (which must be enabled to use this decorator).
Passing an additional parameter "tg_recollect" will clear previously
stored parameters.

As arguments, the decorator takes the names of the parameters that
shall be recollected. If you don't specify any parameter name, all
parameters will be recollected. You can also pass a "default" argument
that will be used as the default value for "tg_recollect". If you set
this to False, then the parameters will only be recollected if you
explicitly pass tg_recollect=True in the request, otherwise (default)
it is exactly the other way round.

I have already tested this in combination with the pagination
decorator and it works just perfectly.

Another way of remembering parameters (if you don't want to use
cookies) is passing them around in hidden fields and urls. To make
this easier, I have written another decorator called "pass_params". It
modifies the output dictionary by adding hidden fields for the
specified parameters in all forms that are passed to the template, and
also passes a modified tg.url() function to the template that
automatically adds the specified parameters as query parameters to all
urls created with tg.url().

I'd like to get some feedback - do you think these decorators are
generally useful and should be included in TurboGears? I think
"recollect" is pretty useful and straightforward, but "pass_params"
may be a bit too wacky for general use. Any details you would want to
change (naming etc.)?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to