[Zope-dev] z3c.form and redirects
Hi, A lot of the forms I write perform a redirect at the end of the action handler for a successfully submitted form. z3c.form's __call__() indiscriminately calls update() and then render(). This means that even if something in update() (the action handler in this case) causes a redirect, the render() method is called, which is unnecessary since the browser will ignore the response body and perform the redirect. It also triggered a small bug in Plone (since worked around) whereby status messages would be output on the hidden page and go missing for the final page (status messages in Plone can be persisted across redirects using a cookie). Grok's forms do something like this: def __call__(self): self.update() if self.request.response.getStatus() not in (301, 302): return self.render() return u'' Would it be an idea for z3c.form to do the same? Martin -- Author of `Professional Plone Development`, a book for developers who want to work with Plone. See http://martinaspeli.net/plone-book ___ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] z3c.form and redirects
On 2/23/10 15:33 , Martin Aspeli wrote: Hi, A lot of the forms I write perform a redirect at the end of the action handler for a successfully submitted form. z3c.form's __call__() indiscriminately calls update() and then render(). This means that even if something in update() (the action handler in this case) causes a redirect, the render() method is called, which is unnecessary since the browser will ignore the response body and perform the redirect. It also triggered a small bug in Plone (since worked around) whereby status messages would be output on the hidden page and go missing for the final page (status messages in Plone can be persisted across redirects using a cookie). Grok's forms do something like this: def __call__(self): self.update() if self.request.response.getStatus() not in (301, 302): return self.render() return u'' Would it be an idea for z3c.form to do the same? +1 I would be in favour skipping render() for any status outside of 2XX instead of hardcoding 301 302. Wichert. ___ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )
Re: [Zope-dev] z3c.form and redirects
On Tuesday 23 February 2010, Martin Aspeli wrote: Grok's forms do something like this: def __call__(self): self.update() if self.request.response.getStatus() not in (301, 302): return self.render() return u'' Would it be an idea for z3c.form to do the same? Yes. In fact several people I projects that I have seen do this already. I would have no objections of adding this to the distribution, if someone checks in a fix with a test. Regards, Stephan -- Entrepreneur and Software Geek Google me. Zope Stephan Richter ___ Zope-Dev maillist - Zope-Dev@zope.org https://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - https://mail.zope.org/mailman/listinfo/zope-announce https://mail.zope.org/mailman/listinfo/zope )