[Zope-CMF] Re: [CMF-checkins] renamings

Florent Guillaume fg at nuxeo.com
Fri Jul 9 08:29:32 EDT 2004


Yes I agree that the two patterns are adequately described below:

> To make sure we are talking about exactly the same things, I try to 
> describe the two patterns more in detail:
> 
> 
> script calls template (after the renaming)
> ------------------------------------------
> 
> webpage_script:
> 
>    ##parameters=var1='', button1='', button2=''
>    ##
> 
>    if button1:
>        #process and redirect if successful
>    elif button2:
>        #process and redirect if successful
> 
>    results_dict = {'value1': 'foo'}
>    return context.webpage_template(**results_dict)
> 
> webpage_template:
> 
>    <p tal:content="options/value1"></p>
> 
> Based on the parameters the script either redirects or returns the 
> template.
> 
> 
> template starts by calling a script (before the renaming)
> ---------------------------------------------------------
> 
> webpage_script:
> 
>    ##parameters=var1='', button1='', button2='', **kw
>    ##
> 
>    if button1:
>        #process and redirect if successful
>    elif button2:
>        #process and redirect if successful
> 
>    results_dict = {'value1': 'foo'}
>    return results_dict
> 
> webpage_template:
> 
>    <tal:page
>       tal:define="results python: context.webpage_script(**request.form)"
>       tal:condition="results">
>    <p tal:content="results/value1"></p>
>    </tal:page>
> 
> The template calls the script, forwarding the parameters. Based on the 
> parameters the script either returns None or the results_dict. None 
> means we don't need the template because a redirect is set.

Okay.

> The second pattern makes things more complicated, invoking the template 
> before we even know if we need it. Of course pages that are no forms 
> (like 'index_html', 'search') would not look that bad with the second 
> pattern. But I prefer to use the same pattern for forms and non-forms.

There are 3-4 more lines to add at the top of the template. That's a
small price to pay for reusability of the script. My search_control
example came from an real use case, it's used by several different
templates.

I hate to have a hardcoded template name in the script part. OTOH having
the template use a hardcoded script name is okay in my book as these
kind of templates are not reusable anyway. Also I don't like to have
something that's not a ZPT used directly as a view/edit action, it makes
for confusing sources.

But maybe that's just me and Stefan, I guess we can live with either
solution in any case.

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)
+33 1 40 33 79 87  http://nuxeo.com  mailto:fg at nuxeo.com


More information about the Zope-CMF mailing list