[Zope] is it possible to add numerical comparison test to dtml-in statement ? statement ?

Stephen Pitts smpitts@midsouth.rr.com
Sun, 9 Jan 2000 13:42:53 -0600


> Actually, this would be <dtml-in "_.filter(lambda x: x > 12,
> objectValues(['MyClass']))">.  Sadly, DTML does not expose 'filter'.
You can change that. The list of functions DTML exposes is in
lib/python/DocumentTemplate/DT_Util.py, starting at line 214 and
continuing until 310. You could easily add all of the functional
programming constructs (map, apply, filter) if needed. The beauty of
Open Source! 

> 
> 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())">.
> 
Yeah, my DTML is getting pretty ugly. Another option is to use a Python
Method to run filter on the list with lamba functions.

-- 
Stephen Pitts
smpitts@midsouth.rr.com
webmaster - http://www.mschess.org