[Zope3-dev] update called twice for editview

Marius Gedminas mgedmin at b4net.lt
Mon Sep 13 08:33:05 EDT 2004


On Tue, Sep 07, 2004 at 02:08:28AM +1000, Stuart Bishop wrote:
> On 01/09/2004, at 3:23 AM, Garrett Smith wrote:
> 
> >The use of tal:tag at the top of edit.pt (z.a.form.browser) as well as
> >tal:define in line 18 results in update being called twice for the edit
> >view.
>
> It is indeed there to ensure that everything is updated before 
> attempting
> to render the form.
> 
> >Ideally, we could define 'status' in the first line to accomplish what
> >we needed in a single call to update.
> 
> Yup.
> 
> >AFAIC, this is a performance related issue that should be fixed -- I'm
> >happy to do it, but need some help using tal:tag. This would also be
> >possible using a slot in the main template for code needed to be
> >evaluated before the rest of the page is rendered, but I'm hoping
> >there's an easier path.
> 
> <tal:x define="status view/update">
>  <html metal:use-macro="context/@@standard_macros/view">
>    [...]
> </tal:x>

Or

<tal:x define="global status view/update" />
<html metal:use-macro="context/@@standard_macros/view">
...
</html>


Lately I've acquired the habit of moving the view/update call directly
into the __call__ method of the view class:

    class MyView(BrowserView):

         template = ViewPageTemplateFile('foo.pt')

         def __call__(self):
             self.status = self.update()
             return self.template()

The page template uses view/status and does not worry about view/update.

I see three advantages to this pattern:

  - Less logic in page templates

  - The view can choose one of several page templates to display
    depending on form values (I used this technique to build multistep
    forms).

  - The template can be rendered in unit tests, catching ZPT bugs
    faster.

Marius Gedminas
-- 
Voodoo Programming:  Things programmers do that they know shouldn't work but
they try anyway, and which sometimes actually work, such as recompiling
everything.
-- Karl Lehenbauer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20040913/1f7c0fcf/attachment.bin


More information about the Zope3-dev mailing list