How can I call a ZSQL method in <dtml-if> tag?
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@nautilus.org http://www.nautilus.org
On Wed, 20 Feb 2002, Jin Chen wrote: You want expr="CountCrew() ==1" Without the parens, you're looking at the object, not the result of the object. HTH.
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@nautilus.org http://www.nautilus.org
_______________________________________________ Zope maillist - Zope@zope.org 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 )
-- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
[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
participants (3)
-
Jin Chen -
Joel Burton -
Thomas B. Passin