[Zope] initlevel at initialization of product with aq_parent

Nico de Boer nico@nfg.nl
19 Jul 2002 14:30:11 +0200


Hi all,

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.

I've tried the following:

	def __init__(self, id, title='', initlevel=0):
		"""initialize a new instance of SiteNav"""
		self.id = id
		self.title = title
		self.initlevel = self.getInitLevel()

	def getInitLevel(self):
		"""returns the initlevel"""
		initlevel = 0
		parent = self
		while 1:
			if hasattr(parent,'aq_parent'):
				parent=parent.aq_parent
				initlevel = initlevel + 1
			else:
				break
		return initlevel - 1

When I add a SiteNav object (folderish object) and I put a DTMLMethod
in it where I call getInitLevel, I get the correct initlevel.

But when I ask for initlevel in the DTMLMethod, I get -1.

Doesn't the object has a aq_parent at initialization?

Is there a way to do this?

Thanx!

Greetz Nico