[Zope] manage_afterAdd method

Nico de Boer nico@nfg.nl
23 Jul 2002 09:57:11 +0200


Hi all,

I'm working on a SiteNav product that creates Site Navigations for a
website. At initialization I need an initlevel, so the product knows
at which level it lives. I'm trying to do this with manage_afterAdd,
but it isn't really working.

Can somebody tell me what I am doing wrong?

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

	def __init__(self, container, id, title=''):
		"""initialise a new instance of SiteNav"""
		self.id = id
		self.title = title
		self.initlevel = self.manage_afterAdd(self, container)

	def manage_afterAdd(self, parent, container):
		"""is supposed to return the correct initlevel"""
		initlevel = 0
		while 1:
			if hasattr(parent,'aq_parent'):
				parent=parent.aq_parent
				initlevel = initlevel + 1
			else:
				break
		return initlevel - 1

As you can see manage_afterAdd has to return the correct initlevel. But when
I install my product I get initlevel -1.

How can I get the initlevel at the correct value with manage_afterAdd?
Or are there other possibilities here?

Greetz Nico