initlevel at initialization of product with aq_parent
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
See: http://www.zopelabs.com/cookbook/995468614 hth, -Casey On Friday 19 July 2002 08:30 am, Nico de Boer wrote:
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
there is no acquisition context while in __init__. look at "manage_afterAdd" instead, which gets called after initialization. jens On Friday, July 19, 2002, at 08:30 , Nico de Boer wrote:
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
_______________________________________________ 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 )
Hi, Sounds fine to me, use manage_afterAdd. But how do I do this? I think about the following: def __init__(self, id, title='', initlevel= 0): """initialise a new instance of SiteNav""" self.id = id self.title = title self.initlevel = initlevel def manage_afterAdd(self): self.initlevel = self.getInitlevel() return self.initlevel Or something like that, because I don't have an idea how this method manage_afterAdd works. Greetz Nico
the signature is:: def manage_afterAdd(self, item, container): """ do my thang """ ... self is self item is normally self as well container is this item's container. jens On Friday, July 19, 2002, at 10:44 , Nico de Boer wrote:
Hi,
Sounds fine to me, use manage_afterAdd. But how do I do this?
I think about the following:
def __init__(self, id, title='', initlevel= 0): """initialise a new instance of SiteNav""" self.id = id self.title = title self.initlevel = initlevel
def manage_afterAdd(self): self.initlevel = self.getInitlevel() return self.initlevel
Or something like that, because I don't have an idea how this method manage_afterAdd works.
Greetz Nico
participants (3)
-
Casey Duncan -
Jens Vagelpohl -
Nico de Boer