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

yuppie y.2004_ at wcm-solutions.de
Fri Jul 9 07:48:16 EDT 2004


Stefan H. Holek wrote:
> +1
> 
> On Mittwoch, Jul 7, 2004, at 15:23 Europe/Vienna, Florent Guillaume wrote:
> 
>> I much prefer to have the template start by calling something that does
>> all the logic, and then uses it to display its things as it wants.

I guess for the same reason as Florent mentioned.


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.



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.

I'd like to have the best solution, but so far I'm not convinced the old 
pattern was better. Not by arguments and not by the number votes.


Cheers, Yuppie



More information about the Zope-CMF mailing list