[Zope] initlevel at initialization of product with aq_parent

Casey Duncan casey@zope.com
Fri, 19 Jul 2002 09:02:55 -0400


See:

http://www.zopelabs.com/cookbook/995468614

hth,

-Casey

On Friday 19 July 2002 08:30 am, Nico de Boer wrote:
> Hi all,
>=20
> I'm working on a product that renders treemenu's for websites. Now I
> have to get an initlevel as starting point for my menu.
>=20
> I've tried the following:
>=20
> =09def __init__(self, id, title=3D'', initlevel=3D0):
> =09=09"""initialize a new instance of SiteNav"""
> =09=09self.id =3D id
> =09=09self.title =3D title
> =09=09self.initlevel =3D self.getInitLevel()
>=20
> =09def getInitLevel(self):
> =09=09"""returns the initlevel"""
> =09=09initlevel =3D 0
> =09=09parent =3D self
> =09=09while 1:
> =09=09=09if hasattr(parent,'aq_parent'):
> =09=09=09=09parent=3Dparent.aq_parent
> =09=09=09=09initlevel =3D initlevel + 1
> =09=09=09else:
> =09=09=09=09break
> =09=09return initlevel - 1
>=20
> When I add a SiteNav object (folderish object) and I put a DTMLMethod
> in it where I call getInitLevel, I get the correct initlevel.
>=20
> But when I ask for initlevel in the DTMLMethod, I get -1.
>=20
> Doesn't the object has a aq_parent at initialization?
>=20
> Is there a way to do this?
>=20
> Thanx!
>=20
> Greetz Nico