[Grok-dev] grok.View: Self-submitting forms, redirect, and before()

Philipp von Weitershausen philipp at weitershausen.de
Wed Jan 10 10:12:15 EST 2007

After showing some grok code last night, I got some feedback from a few 
developers. Pretty much the only thing that a few people were confused 
about was before() in grok.View. After explaining what it was for, they 
all understood it. I was surprised I had to explain it, given that I 
documented what it did in the docstring.

Anyway, this got me thinking about the whole before() thing. We 
typically use it for two things:

a) processing of request variables in self-submitting forms, or in form 
handlers in general

b) preparing computations for the template

After talking to Martin Aspeli, I realized that these two things impose 
slightly different semantics: In a) you probably would like to be able 
to redirect somewhere under certain circumstances (e.g. invalid request 
parameters or something) and never have the template rendered, while in 
b) you know the tepmlate will always be rendered (you're preparing stuff 
for it, after all).

The redirect use case isn't properly addressed by before() currently. So 
I'm wondering whether we should have two separate methods for this (e.g. 
process() and prepare()) of which the process() method would allow to 
redirect somewhere, causing grok.View never to render the template. If 
that's overkill, then we should at least consider adding that 
possibility to before() (whose name would then be confusing, as it seems 
to already be to other people).


http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!

More information about the Grok-dev mailing list