Hi Cito,
On 4/2/08, Cito <[EMAIL PROTECTED]> wrote: > > 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. IMHO, making use of session is not a good idea, specially when you have power users browsing your system. Imagine an user opening you "Search product" in several tabs, allowing him to do different searches in the product table. Each search result presents the data in a paginate grid, allowing the user to click on a row to present more detailed info about the product. How would you handle the situation when the user wants to detail 2 different products in 2 different tabs, and after that he decides to come back to grid result ? I have seen this in the past (not in my systems, of course :)). And it was even worse, because the search criteria was always stored in the same session variable, regardless the context. Example: storing customer search params in the same variable that had product search params. When the user wanted to return to the search of products (in the other tab).... Kaboomm... :) > 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. That's cool... :) (except for the session use...:)) > 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(). When I read the other thread, I was thinking something like what you are describing here... > 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.)? I personally think it is useful. Lets see what the others devs think about it. Cheers, Roger --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
