[Zope] another simple question...

Michel Pelletier michel@digicool.com
Mon, 7 Jun 1999 17:07:53 -0400


> -----Original Message-----
> From: Tony.McDonald@newcastle.ac.uk
> [mailto:Tony.McDonald@newcastle.ac.uk]
> Sent: Monday, June 07, 1999 3:54 PM
> To: dmd@3e.org
> Cc: zope@zope.org
> Subject: Re: [Zope] another simple question...
> 
> 
> > 
> > 
> > The zope manual would be much more useful if it gave a few 
> examples...
> > 
> > I have this method:
> > 
> >   Method: GetAuthorID
> >   Arguments: authorid:int
> > 
> >   SELECT authorname,authoremail FROM authors
> >   WHERE <!--#sqltest authorid column=authorid type=int-->
> > 
> > I then want to do something like this:
> > 
> > <!--#in GetAuthorID(4)-->
> > <A HREF="mailto:<!--#var authoremail-->"><!--#var authorname--></A>
> > <!--#/in-->
> > 
> > 
> > What's the proper format for calling a method with arguments?
> > 
> 
> <!--#in "GetAuthor(authorid=4)"-->
> blah blah
> <!--#/in-->
> 
> I believe this is because 'GetAuthorID(4)' is actually an 
> expression and therefore needs
> quoting. As for setting the ZSQL argument, that's because 
> I've never managed to get a ZSQL method
> that needed an argumanet to work without it...
> 

There is another side effect of using name lookup vs. expressions.  If
you just look a method up by name (assuming no arguments) like <!--#var
blah--> and that method returns a sequence, the name 'blah' is actually
turned *into* a sequence from a method.  If you said:

<!--#var blah-->
<!--#var "blah()"-->

You would get an error that 'blah' has no __call__ method, because it
was turned into a sequence by being called by name.  This is a feature,
so that expensive methods can be cached.  If you don't want this method
cached (say it has some sort of side effect that changes itself, or is
based on time, or some other craziness) then allways use quotes around
it, and a) it won't be chached and b) it won't be transmutated into a
sequence.

Obviously, if your method requires arguments, 99% of the time your not
going to want the cache the results, so calling methods with arguments
requires using the expression machinery.

The rule of thumb is, be consistent.  Mixing and matching expressions
and name lookup on the same method can run you into cache clash.

-Michel

> hth
> toe
> (dumb telnet session..)
> 
> _______________________________________________
> 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 )
>