[Zope] Using a Python script inside a dtml-tree - repost

Pierre Godefroy pierre.godefroy@noos.fr
Tue, 08 Oct 2002 08:50:33 +0200


I have the following Python script, which works well
(it gives the position of an object in the form of a "nested numbered=20
hierarchy", such as : "3.4.3.2.3") :
----------------------------------------------------------------------------=
-----------------------
from string import join

res=3D[]
lll=3Dlen(context.REQUEST.PARENTS)

for i in range(lll-1):
  xyz=3Dcontext.REQUEST.PARENTS[i].id
  a=3Dcontext.REQUEST.PARENTS[i+1].objectIds().index(xyz)
  res.append('.'+str(a+1))

res.reverse()
fullnumber=3Djoin(res)
print fullnumber

return printed
----------------------------------------------------------------------------=
----------------------------
BUT, in its present form it only works for the object which is being called=
=20
directly by the user.

I would like to use it also in the framework of a dtml-tree, in order to=20
order to apply it successively to each object reached through the tree and=
=20
displayed as a menu item :

<dtml-tree>

<dtml-var my_python_script>
</dtml-tree>

Of course then, "context.REQUEST.PARENTS" is not good as it applies to the=
=20
main object being called, not to the successive objects which are being=20
retrieved recursively through the dtml-tree.

What should I do? How should I modify the script?

Thanking you all in advance,

Pierre

Pierre Godefroy
52 rue des Archives
75004 PARIS
FRANCE

T=E9l. : +33 (0)1 42 74 46 05