[Zope] Use of lambda expression in DTML

Nick Drew hyperspace@btinternet.com
Fri, 26 May 2000 17:25:42 +0100


I'm a newbie zopista, and python for that matter...

In brief: I get a NameError when invoking "filter(...)" from DTML.  I thought this was a built-in python method, so I'm a bit puzzled.
In detail:

1) I want to display a dtml-tree of my folder hierarchy, but I want to exclude all Zwiki discussion groups.
2) In my index_html for the top level folder, I have the following:

<dtml-tree Outline leaves=dtcTemplate >
 <SPAN CLASS="tree">
  <dtml-if tree-item-expanded>
    <dtml-if expr="objectValues(['Folder'])">
    <IMG SRC="<dtml-var BASE2>/Outline/OpenBook.gif" ALIGN="TOP" BORDER="0">
    </dtml-if>
    <STRONG>
    <I><dtml-var title></I>
    </STRONG>
  <dtml-else>
    <dtml-if expr="objectValues(['Folder'])">
    <IMG SRC="<dtml-var BASE2>/Outline/ClosedBook.gif" ALIGN="TOP" BORDER="0">
    </dtml-if>
    <dtml-var title>
  </dtml-if>
 </SPAN>
</dtml-tree>

which is cribbed straight from QuickStart.  

3) I only want to ignore Zwiki groups, but they are out-of-the-box folders, so I can't filter on meta-class.  
4) My approach is just to add a property to the Zwiki folder  ('blockTreeBranching')

5) In the dtml-tree tag, I change it to:

	<dtml-tree 
		Technical 
		leaves=dtcTemplate 
		branches_expr="filter( lambda f: not f.hasProperty('blockTreeBranching', false), objectValues(['Folder']) )">

which, all things equal, should DoTheRightThang.

6) The code can be published, but when I view it, it spits out a NameError, choking on "filter".  Argh.

Ideas gratefully recieved...

Nick

HyperSpace Ltd,Birmingham Research Park, Edgbaston, UK, B15 2SQ
(e) hyperspace@btinternet.com           (t) +44 (0)121 414 7019