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

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


Philipp von Weitershausen wrote:
> Martijn Faassen wrote:
>> Philipp von Weitershausen wrote:
>> [snip]
>>> 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).
>>
>> I'm not tied to the name 'before' nor am I tied to the current 
>> semantics of 'render'. Some suggestions:
>>
>> * could we employ the Zope 3 standard update/render technique in this? 
>> I don't mean we *only* use this but perhaps we can use it as a 
>> foundation to what we want.
>>
>> * try implementing process/prepare and see how the Wiki and your Herd 
>> example (for instance) are affected.
> 
> After some more discussion on IRC, the change Martijn and I agreed upon 
> was:
> 
> Index: src/grok/components.py
> ===================================================================
> --- src/grok/components.py      (revision 71844)
> +++ src/grok/components.py      (working copy)
> @@ -137,7 +137,11 @@
>                  interface.Interface, 
> name=self.module_info.package_dotted_name)
> 
>      def __call__(self):
> -        self.before()
> +        self.update()
> +        if self.request.response.getStatus() in (302, 303):
> +            # Somewhere in update(), a redirect was triggered.  Don't
> +            # continue rendering the template or doing anything else.
> +            return
> 
>          template = getattr(self, 'template', None)
>          if not template:
> @@ -183,7 +187,7 @@
>      def redirect(self, url):
>          return self.request.response.redirect(url)
> 
> -    def before(self):
> +    def update(self):
>          pass
> 
> 
> Basically, we rename before() to update() and add the semantics that a 
> redirect caused in update() will stop all further rendering.

Done. It's checked in. I also updated my blog entry: 
http://www.z3lab.org/sections/blogs/philipp-weitershausen/2007_01_09_you-thought-zope-3-wasn/blog_entry_view

-- 
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