[Zope] Recursive Display Of All Folder Items
Paul Winkler
pw_lists at slinkp.com
Tue Dec 13 15:16:40 EST 2005
On Tue, Dec 13, 2005 at 01:44:00PM -0600, J Cameron Cooper wrote:
> Francisco Chamorro wrote:
> >Hi everyone, I am trying to get a dump of all the content currently in
> >our zope server. Using DTML I was able to get the top level folders to
> >display their content but I am unable to recursively display the
> >contents of the sub-folders.
> >
> >This is the code I am using for my top level folders, where "TV" is the
> >name of the folder I want to display.
> >
> ><dtml-in "TV.objectValues()"><dtml-var id><br></dtml-in>
> >
> >
> >My second attempt at displaying sub-folder content was the following:
> >
> ><dtml-in "TV.objectItems()">
> > id: <dtml-var id>,<br>
> > type: <dtml-var meta_type><br>
> > <dtml-if "meta_type=='Folder'">
> > <dtml-in expr="objectValues(<dtml-var id>)">
> > id: <dtml-var id>,<br>
> > type: <dtml-var meta_type><br>
> > </dtml-in>
> > </dtml-if>
> ></dtml-in>
> >
> >But that also fails. I searched the documentation and found a post
> >about recursively calling the same function but that did not work as I
> >get a "excessive recursion" error. Any help on this problem would be
> >greatly appreciated.
>
> objectValues is acquired on all objects, even non-folderish ones. Thus
> recursion never stops. You must ask for it explicitly:
> aq_inner.aq_explicit or something like that if I remember directly.
You shouldn't have to, if you're dealing with objects that inherit from
OFS.SimpleItem.Item. This code is *supposed* to prevent infinite
recursion:
# This keeps simple items from acquiring their parents
# objectValues, etc., when used in simple tree tags.
def objectValues(self, spec=None):
return ()
objectIds=objectItems=objectValues
But of course, there's no requirement for everything to inherit from
Item. All it takes is one persistent object that doesn't and you can get
an infinite recursion.
Another option, if you don't have a catalog handy, is to use
ZopeFind(). See lib/python/OFS/FindSupport.py.
(The docstring is unhelpful, but the method signature
should give you a clue what to pass to it; or, look at the
source for the Find page in the ZMI.)
Call ZopeFind() on the folder you want to start your search at.
--
Paul Winkler
http://www.slinkp.com
More information about the Zope
mailing list