[Zope] How can I call a ZSQL method in <dtml-if> tag?
Thomas B. Passin
tpassin@mitretek.org
Thu, 21 Feb 2002 11:10:43 -0500
[Jin Chen]
>
> 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 you write
<dtml-var CountCrew>
then Zope evaluates the CountCrew object. Zope will discover that this
object can be called, and then call it, which executes the method.
If you write
<dtml-var "CountCrew">
then Zope hands CountCrew off to Python. Python sees that you have
referenced an object and so returns a reference to that object. This is not
what you want, as you have learned. You want Python to call the object. To
have Python call the object, it need to be told CountCrew().
So you should write
<dtml-if expr="CountCrew() == 1">
You can shorten this to
<dtml-if "CountCrew() == 1">
If you do not care how many there are as long as it is more than zero, you
can write
<dtml-if CountCrew>
or
<dtml-if "CountCrew()">
Cheers,
Tom P