RE: [Zope] Use of lambda expression in DTML - Result!

2000-05-31 Thread Nick Drew

Thanks for helping me solve this one.  In the end I did the following:

1) hacked DocumentTemplate/DT_Util.py to include "filter" in the __builtins__
2) Installed PythonMethods and called pruneTree with parameter 'self' and  content
return _.filter( 
   lambda x: x.getProperty('pruneFromTree',0)==0 , 
   self.objectValues(['Folder']) 
)
3) The new tag reads
dtml-tree name="Outline" leaves=dtcTemplate branches="pruneTree"

Chris McDonough wrote:
|If it's something you want badly (and if you haven't already) add it as
|a feature request to the Collector on Zope.org.  Once other folks get
|past the knee-jerk reaction, maybe it'll sink in as a good thing.  In
|the meantime, you can add it yourself if you like.

Good idea - I'll do that.

|Hopefully, you'll be so kind as to forgive me.  

That's easy - as long as you keep writing HowTos of the same quality as "Zope 
installation and upgrade" and "Zope enlightenment by understanding object 
orientation"... :-)

|After seeing people post
|DTML code to the list that they need debugged that computes pay rates,
|has the shape of an arrowhead and scrolls past the maximum character
|length of my email client horizontally, I'm a little leery of adding
|anything whatsoever to DTML, as I think the rest of the folks at DC
|are.  Reducing the complexity of DTML is a good thing, however 
|it can be accomplished.

Agreed.  You can do some very powerful things with the lamda expressions, but they 
very quickly become unwieldy if used inappropriately, so I think people are right to 
be wary.  Having said that, any sort of block structured language has the same 
pitfalls - e.g. Smalltalk, Self, even Java's anonymous classes could be used to 
detrimental effect.

I prefer to leave this stuff to style and convention ("good practice") than prescribe 
them entirely.

Thanks again,
Nick.


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )




[Zope] Use of lambda expression in DTML

2000-05-26 Thread Nick Drew


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
Idtml-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) [EMAIL PROTECTED]   (t) +44 (0)121 414 7019


___
Zope maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )