[Zope] is it possible to add numerical comparison test to dtml-in
statement ? statement ?
Evan Simpson
evan@4-am.com
Sun, 09 Jan 2000 17:50:19 -0600
Stephen Pitts wrote:
> On Sun, Jan 09, 2000 at 02:31:49AM +0800, chas wrote:
> > When looping over ZClass instances in a dtml-in statement,
> > I have constantly wanted to add a numerical test condition
> > (eg. "where X > 12" where X is a property of the instance)
> Yep, since <dtml in "foo"> evaluates foo as a Python expression, the
> following should be possible:
> <dtml in "_.filter(objectValues(['MyClass'], lamba x: return x > 12)">
Actually, this would be <dtml-in "_.filter(lambda x: x > 12,
objectValues(['MyClass']))">. Sadly, DTML does not expose 'filter'.
A problem for more even slightly more complicated expressions, although
not this one, is that DTML's security features rely on magic variables
which aren't accessible to lambda's expression. For example, <dtml-var
expr="(lambda x: x.id())(this())"> fails; you have to write <dtml-var
expr="(lambda x, _vars=_vars: x.id())(this())">.
An External or Python Method could fix this up, or in the given example
you could simply write:
<dtml-in foo><dtml-if expr="x>12">
...
</dtml-if></dtml-in>
This should work fine, as long as you aren't grouping.
Cheers,
Evan @ 4-am