[Zope] dtml and 'none' behaviour

Tino Wildenhain tino at wildenhain.de
Fri Feb 11 14:34:18 EST 2005


Am Freitag, den 11.02.2005, 19:21 +0000 schrieb garry saddington:
> I have a zsql method which returns some null values. These are then displayed 
> in a table but the null values become 'None'. Is there any way to get round 
> this behaviour and have empty cells in the displayed results? I can do it 
> with several dtml-if and dtml-unless calls but wondered if there was a more 
> subtle approach.

Well, null is to SQL as None to python. So either you solve this
at database level or in python. For example in python you could
use: 

return [{'foo':row.foo or '',
         'bar':row.bar or ''} for row in context.yourzsqlmethod()]

with this little "or" you solve this quite elegant. Every 
value which evaluates to false (which is: 0, "", ... and None)
let the expression return its right side, which is '' in this
case.


On database level you could use coerce() which returns the
first non null argument:

SELECT coerce(foo,'') as foo,coerce(bar,'') as bar FROM ...

or even better try to avoid nulls where possible.

Regards
Tino




More information about the Zope mailing list