[Zope3-dev] Number of languages in Zope 3

Jim Penny jpenny@universal-fasteners.com
Wed, 9 Apr 2003 11:36:57 -0400


On Wed, Apr 09, 2003 at 08:39:43AM -0400, Tres Seaver wrote:
> On Wed, 2003-04-09 at 06:52, Andy McKay wrote:
> > >> But now you want to add a custom title attribute. Just because of this 
> > >> you have to switch to a completely different syntax:
> > >>
> > >> <img
> > >>   tal:replace="structure 
> > >> python:here.Imagefolder.imagename.tag(title='MyTitle')"
> > >>   src="" />
> > >
> > >> This is even hard to get for somebody who knows Python because you are 
> > >> limited to having to use single quotes in the brackets due to some 
> > >> limitation of the TAL parser.
> > > 
> > > I'd suggest writing this as a method in a supporting view class.
> > 
> > I don't know much about zope 3 at the moment, but how does writing a
> > supporting view class make passing parameters from a template easier?
> > 
> > I think the point here is that the template, contains a value that you
> > want to pass to the method. This is common when one does a tal:repeat,
> > and then pass some value of that repeat off to a function for each
> > iteration.
> 
> In Zope3, that idiom would typically be replaced by an intermediate
> method on the view class which did the underlying work.  E.g., where in
> Zope2 I might to something like:
> 
>   <div tal:repeat="snippet python:here.objectValues(['Some Type'])">
>    <h3 tal:conetnt="python:snippet.headline(version='Brief')">HEADLINE
>    >/h3>
>    <div tal:content="python:snippet.teaseText(maxwords=100)>TEASE</div>
>   </div>
> 
> in Zope3 I would add a method to the view class which did the heavy
> lifting:
> 
>    def getSnippetInfo(self):
>        results = []
>        for snippet in [x for x in self.context.values()
>                          if ISnippet.isImplementedBy(x) ]:
>            results.append({'title' : snppet.headline(version='Brief'),
>                            'tease' : snippet.teaseText(maxWords=100)})
>        return results
> 
> The template then becomes much clearer:
> 
>    <div tal:repeat="info context/getSnippetInfo">
>     <h3 tal:content="info/title">TITLE</h3>
>     <div tal:content="info/tease">TEASE</div>
>    </div>
> 

I am not such a big fan of this.  It starts to reek of magic again - I
have to chase down the view class to find out what parameters are being
used.

I do a lot of work with SQL methods.

Frankly, I prefer 
<div tal repeat="pf
python:container.select_paint_formula_sql(finish_number=request['finish_number'])">

to

<div tal repeat="pf here/select_paint_formula_sql">.

Is is simply more explicit.

And I really don't see that
<div tal replace="${pf/vendor} - ${pf/stock_number}">
is much preferable to:
<div tal replace="python:'%s - %s'%(pf['vendor'], pf['stock_number'])">

Both look pretty funky - but if one happens to be a float, well, you
have to fall back to python syntax anyway.

-----

I started out hating ZPT.  It looked odd, there were a lot of precedence
rules with no clear explanation of of why they were there.  Some
keywords are verbs; some are nouns.  All but one of the keywords are
singular; but suddenly attributes is in plural.  There is the gratuitous 
renaming of 'container' to 'here'.  (This one really grates, because it
makes a python call from ZPT look different from any other context, in
particular from a script python. If there is a single thing I would have
changed in ZPT, it is this.)

Nevertheless, I struggled for a couple of weeks, and am glad that I am
writing most of my code in ZPT.  

But, if 'explicit is better than implicit', you have to show the
parameters at call time.  Path expressions simply offer no support!

Jim Penny