[ZPT] dictionaries, has_key, and the test function
Tino Wildenhain
tino@wildenhain.de
Sat, 14 Dec 2002 23:23:40 +0100
Hi Tim,
--On Freitag, 13. Dezember 2002 16:12 -0500 Tim Lynch
<lynch@gould.mannlib.cornell.edu> wrote:
>
>
> I'd like to write something like:
>
> <span tal:define="parents python:test(results.has_key('parents'),
> results['parents'], None)"> do stuff
> </span>
>
>
> This fails if 'parents' doesn't exist; the line faults & I get
> a key doesn't exist error.
>
>
>
> I've worked out an alternative:
>
> <span tal:condition="python:test(results.has_key('parents'), 1, 0)">
> <span tal:define="parents python:results['parents']">
> do stuff
> </span>
> </span>
>
>
> but I figure I'm missing something here and that first approach
> ought to somehow work.
>
> Anybody have any ideas?
Yeah. Just dont try to copy DTML style to ZPT.
Just write a python script, call it say.. getParents
and let it do the stuff above:
return results.get('parents',None)
or even do whatever you vagualy describe with "do stuff"
also inside the python script.
Would be great if Evan could decide to remove that tal:define ;)
Regards
Tino