[Zope] manage_afterAdd method

peter sabaini sabaini@inode.at
Tue, 23 Jul 2002 14:56:43 +0200


Nico de Boer wrote:
> 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)


shouldnt be something like

         class SiteNav( XXX ):

here?

i think your object is missing acquisition wrappers. take a look here

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

or here

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


cheers, peter.

> 	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
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 
>