[Zope] Iterating over items returned from external methods

Michel Pelletier michel@digicool.com
Sun, 9 May 1999 01:16:25 -0400


> -----Original Message-----
> From: Kevin Dangoor [mailto:tazzzzz@yahoo.com]
> Sent: Saturday, May 08, 1999 8:54 PM
> To: Ben Derstine; 'zope@zope.org'
> Subject: Re: [Zope] Iterating over items returned from 
> external methods
> 
> 
> I'm sure someone will happily correct me if I'm wrong,
> but I think it's just (for example):
> 
> <ul>
> <!--#in "ExtMethod()"-->
> <li><!--#var sequence-item-->
> <!--#/in-->
> </ul>
> 

If your external method does not require any arguments:

<!--#in ExtMethod-->
...
<!--#/in-->

will suffice.  Note however, that there are subtle differences between
using a method by name (no quotes) and calling it in an expression
(quotes).  I got bit by this just the other day, and I'm still not 100%
on the full behavior (I'm sure someone here will correct me if I'm
wrong).

Lets say you have your Method, and it returns a list:

<!--#in Method-->
<li><!--#var sequence-item-->
<!--#/in-->

Calling it by name the very first time you use it in your DTML
Method|Document will cause the results to get cached and bound to the
name 'Method'.  After DTML rendering engine execute 'Method', it then
turns that object into a sequence object (or a mapping if you specified
the 'mapping' #in tag attribute).  At this point, "Method" is no longer
callable.  So:

<!--#in Method-->
  <!--#var sequence-item-->
<!--#/in-->
<!--#in "Method()"-->
  <!--#var sequence-item-->
<!--#/in-->

Will raise an exception at the second #in expression.

This is nice if 1) Method does not require any arguments, and 2) Method
is an computationally expensive procedure (like searching a large
external database of some kind).

This behavior happens for all callable objects, not just External
Methods.  Python Methods, ZClass Methods, and others will behave
similarly.

So the point is, be consistent in your usage of Methods in DTML.  If the
cacheing behavior breaks something of yours, use the expression syntax
(quotes) as expressions are never cached.

-Michel

> --- Ben Derstine <bend@ecollege.com> wrote:
> > I have an external method that returns a list call
> > List.  I am using a DTML
> > document to display the results of the method. As it
> > is now Zope simply
> > displays ['Sales', 'Marketing','Research']  However,
> > I would like to be able
> > to display the list by iterating over the list
> > instead of directly
> > displaying the raw list. I know about the DTML 'in'
> > tag to iterate over a
> > sequence.  I just can't find any documentation on
> > how to use it for a list
> > returned by an external method.  Would anyone have a
> > simple example of this?
> > 
> > 
> > Thanks
> > 
> > 
> > 
> > 
> > Benjamin L Derstine
> > Network Administrator
> > Real Education, Inc.
> > 10200 A East Girard Avenue
> > Denver, CO 80231
> > 
> > e-mail:  bend@realeducation.com
> > phone:  303-873-7400
> > fax:  303-873-7449
> > 
> > http://www.realeducation.com
> > 
> > "The Leader in Online Education over the Internet"
> > 
> > 
> > _______________________________________________
> > Zope maillist  -  Zope@zope.org
> > http://www.zope.org/mailman/listinfo/zope
> > 
> > (For developer-specific issues, use the companion
> > list,
> > zope-dev@zope.org -
> > http://www.zope.org/mailman/listinfo/zope-dev )
> > 
> > 
> > 
> 
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
> 
> (For developer-specific issues, use the companion list,
> zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
>