Hi Tres!

Tres Seaver wrote:
Lennart Regebro wrote:
On 10/17/05, yuppie <y.2005--E2EsyBC0hj3+aS/[EMAIL PROTECTED]> wrote:

I know that pattern, but I don't like it. [...]
The code on the goldegg-folder_contents branch processes the input in
the __call__ method of the view class. The template is only invoked if
needed. It's much cleaner to use the template just for displaying
results, not for triggering controllers.

That's purely a matter of taste. From a principal standpoint I don't
think there is any difference, really.

I think we might be able to come up with a heuristic for choosing
between the two patterns (this might be a mini pattern language, if

 - For "simple" forms, which redisplay themselves even after a
   successful POST, and which do not redirect, prefer a template-driven
   version, and make the form self-posting;  in ZCML, use <browser:page>
   with the 'template' attribute).  The classic 'document_edit' form
   fits this bill, I think.

I don't know many use cases for 'simple' forms. 'document_edit' redirects to itself if 'change' was successful and to view if 'change_and_view' was successful.

The redirect after a successful update is necessary to avoid further changes if people reload the page.

And even if we have a 'simple' form: A customized '__call__' method is simpler than a 'Update' method that has to be called from the template.

 - If you have to add logic to the template to cope with possible
   redirects, then publish a method of the view, and have the view
   redirect or return a template;  in ZCML, use <browser:page> with
   the 'attribute' variant.  "Add" forms fit this pattern, as well
   as the folder_contents stuff that Yuppie has done.

If we call an 'attribute' we can't specify the template in ZCML. We have to hard-code the template in the view class. Using the '__call__' method we can get the advantages of both patterns. The folder_contents stuff uses the '__call__' method.

 - For a set of inter-related pages sharing common view logic,
   you may end up mixing and matching -- the ':method' bit on submit
   button names is a way to get "off" the original template when
   needed.  ZCML for this case may either be a mixture of the
   'template' and 'attribute' variants of <browser:page>, or else
   <brower:view> with several <page> subdirectives.

I don't like using ':method' because that pattern uses the same URL for different pages. But I never tried to use ':method' with views. Does that even work?



Zope-CMF maillist  -  Zope-CMF@lists.zope.org

See http://collector.zope.org/CMF for bug reports and feature requests

Reply via email to