[Zope] initlevel at initialization of product with aq_parent

Nico de Boer nico@nfg.nl
19 Jul 2002 16:37:54 +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.

But the function getInitLevel doesn't work in the __init__ method,
because acquisition doesn't work here. 

Following Casey's example at www.zopelabs.com/cookbook/995468614 
I got to the following:

def manage_addSiteNav(self, id, title=''):
	"""Add a SiteNav to a folder."""
	self._setObject(id, SiteNav(id, title, self.getId(), self))
	if self.REQUEST is not None:
		return self.manage_main(self, self.REQUEST)

	def __init__(self, acquiredObjectName, container,
                 id, title='', initlevel= 0):
		"""initialise a new instance of SiteNav"""
		self = self.__of__(container) # Create an acquisition wrapper
		acquiredObject = getattr(self, acquiredObjectName) # Acquire the object
		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

But what is acquiredObjectName in this context?

Greetz Nico