[Zope-DB] Testing for empty result set
Chris Withers
chris at simplistix.co.uk
Sat Mar 26 05:40:46 EST 2005
Dieter Maurer wrote:
> Charlie Clark wrote at 2005-3-24 13:44 +0100:
>
>>...
>>your right tal:condition is what you should be using. However, as
>>Results-Objects with empty records are not None you still need a little
>>Python test to get things to work correctly.
>>
>><div tal:condition="python: len(context.myZSQL())">
>
>
> While an empty result set is not "None", it behaves as a
> Python "false" value.
>
> Therefore, you can (and should) use
>
> tal:condition="context/myZSQL"
However, both of these may lead an inxpereinced person to call their
ZSQL method twice for each page rendering.
I'd suggest doing something like:
<table tal:define="results context/myZSQL">
<tr tal:condition="not:results>
<td colspan="3">
No results were found.
</td>
</tr>
<tr tal:repeat="result results">
<td tal:contents="result/x"/>
<td tal:contents="result/y"/>
<td tal:contents="result/z"/>
</tr>
</table>
cheers,
Chris
--
Simplistix - Content Management, Zope & Python Consulting
- http://www.simplistix.co.uk
More information about the Zope-DB
mailing list