[Zope] Re: Accessing the PARENTS of the objects displayed by a DTML-tree

Maik Jablonski maik.jablonski@uni-bielefeld.de
Wed, 09 Oct 2002 12:14:41 +0200


Pierre Godefroy wrote:
> I am reformulating an earlier e-mail, as its wording might be confusing.
> (I also gave it a sexier subject line... :>)
> 
> I have the following Python script, which works well, thanks to an 
> earlier suggestion made by Maik Jablonski
> (it gives the position of an object inside Zope folder hierarchy in the 
> form of a "nested numbers", such as : "3.4.3.2.3") :
> --------------------------------------------------------------------------------------------------- 
> 
> from string import join
> 
> res=[]
> lll=len(context.REQUEST.PARENTS)
> 
> for i in range(lll-1):
>  xyz=context.REQUEST.PARENTS[i].id
>  a=context.REQUEST.PARENTS[i+1].objectIds().index(xyz)
>  res.append('.'+str(a+1))
> 
> res.reverse()
> fullnumber=join(res)
> print fullnumber
> 
> return printed
> -------------------------------------------------------------------------------------------------------- 
> 
> My problem is : how could I apply a similar mechanism for the objects 
> displayed by a dtml-tree?
> 
> I would like to have something like :
> 
> 1 : title
> 1.1 : title
> 1.2 : title
> 2 : title
> 2.1 : title
> 2.1.1 : title
> 2.1.2 : title
> 
> 
> This could be obtained by :
> <dtml-tree branches_expr="objectValues(['Folder'])">
> <dtml-var my_python_script><dtml-var title>
> </dtml-tree>
> 
> BUT, of course then, "context.REQUEST.PARENTS" in my present script is 
> not good as it applies to the main object being called, not to the 
> successive folders which are being retrieved recursively through the 
> dtml-tree.
> 
> I need to access successively the PARENTS hierarchy of these objects.
> 
> What should I do? Is there a solution? How should I modify the script 
> (or the DTML-tree itself)?

maybe you should simply slice your PARENTS...

examples (don't know what's the right "direction" for your problem, but 
you can try it for yourself):

lll=len(context.REQUEST.PARENTS[:2])

or

lll=len(context.REQUEST.PARENTS[3:])

cheers, maik
-- 
Maik Jablonski                 __o
www.zfl.uni-bielefeld.de     _ \<_    Deutsche Zope User Group
Bielefeld, Germany          (_)/(_)               www.dzug.org