On Thursday, September 22, 2016 at 2:14:41 PM UTC-4, Anthony wrote: > > On Thursday, September 22, 2016 at 6:45:55 AM UTC-4, Scott Hunter wrote: >> >> Because I don't need it. The original call tells me enough to make the >> modifications I need to do, and then proceeds to build an up-to-date grid, >> which becomes wasted effort because I'm getting a redirect re-build the >> page I just built. >> > > The grid code first retrieves the records and then calls the selectable > callback (which it must do, as the record ids are passed to the callback), > so if the callback makes any modifications to the records, the resulting > grid will *not* contain up-to-date data unless the grid is called again > (hence the redirect). I think the idea is to ensure it works in all cases, > though I agree it could be made more efficient in some cases. > > For now, a workaround is to check for request.post_vars.records, and if > present, run whatever code you need to, and then delete > request.post_vars.records and request.post_vars.formname before creating > the grid (this will prevent the form from being accepted and therefore skip > the redirect). You could abstract this into a wrapper around the grid. >
Note, with the above method, you would be foregoing the web2py form processing functionality, which among other things protects against CSRF. If you want to allow the grid to handle the form processing and callback as usual but still short circuit the redirect, you could do something like this: def mygrid(*args, **kwargs): try: return SQLFORM.grid(*args, **kwargs) except HTTP as e: if e.status == 303 and 'records' in request.post_vars: del request.post_vars.records del request.post_vars._formname return SQLFORM.grid(*args, **kwargs) def myfunc(): return dict(grid=mygrid(..., selectable=mycallback)) Anthony -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.