[Zope] Re: How can I call a ZSQL method in <dtml-if> tag?

jlagarde@bigfoot.com jlagarde@bigfoot.com
Wed, 20 Feb 2002 15:42:08 -0800


Jean,

Figure I should be a contributor to this list once in a while, and
that's an easy one...

Problem is that CountCrew used in expr="" is a reference to the method,
not the result of calling it, so what you really want is CountCrew(),
and actually, since ZSQL methods always return sequences,
CountCrew()[0].

As for the weird behavior you got:

1) CountCrew will indeed always evaluate to true (it's a function)
2) CountCrew == 1 will always evaluate to false because functions
generally do not equal numbers ;-)

Cheers,

Jean

--- In zope@y..., Jin Chen <jchen@n...> wrote:
> Hi there,
> 
> I am a newer to zope application. I met a problem of calling a ZQSL
method
> in the DTML if tag. Here is the example:
> 
> I have a ZSQL method called "CountCrew" which has no input parameter.
the
> query is: select count(*) from crew
> 
> 1. I test it looks good on the ZSQL method "CountCrew" page. If the
table
> crew has no data, it returns 0, if has one record, it retuens 1...
> 
> 2. I call this ZSQL method in a DTML method, code likes:
> 
> <dtml-if expr="CountCrew == 1">
> <dtml-call "AddCrew(ptime=time1,name=name2,pemail=email1)">
> <dtml-else>
> <dtml-var Error>
> </dtml-if>
> 
> But the <dtml-if ..> test is false and show the Error message no
> mater there is one crew or none in the crew table.
> 
> If I test it like this:
> <dtml-if "CountCrew">//or <dtml-if expr="CountCrew">
> <dtml-call "AddCrew(ptime=time1,name=name2,pemail=email1)">
> <dtml-else>
> <dtml-var Error>
> </dtml-if>
> the <dtml-if ..> test is always true and add the record no mater there
is
> none  or one crew in the crew table.
> 
> 
> You know, I want to add the record in the crew table only if there is
at
> least one crew exist in the crew table.
> 
> I don't know what's wrong with calling the ZSQL method in DTML if tag.
> Please give me any advice if you have time.
> 
> Thanks in advance!
> 
> Jean
> 
> _______________________________________
> Jean Chen
> 
> The Nautilus Institute
> 125 University Avenue
> Berkeley, CA 94710-1616 USA
> (510) 295-6113 * Fax: (510) 295-6130
> jchen@n...
> http://www.nautilus.org
> 
> _______________________________________________
> Zope maillist  -  Zope@z...
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )