[Zope] acquisition problem (I think???)
Andrew Altepeter
aaltepet@bethel.edu
03 Feb 2003 13:10:50 -0600
Hi,
I am writing a product through the ZMI (which extends Folder) that
contains products of the same type (basically a hierarchical system). I
want to be able to delete an arbitrary item and all of it's sub-items.
The method that does this is a recursive deleteMe() python script.
Here is the code that I am using:
def deleteMe(root=1):
children = context.objectIds('NavigationMenu')
if (len(children)):
for child in children:
context[child].deleteMe(root=0)
context.manage_delObjects(children)
if (root==1):
context.aq_parent.manage_delObjects(context.id)
So, to me this looks like your standard recursive function (well, sort
of). However, when I get to the bottom of the tree, context.objectIds
contains siblings, not children. I would expect that if there were no
children, objectIds would return [].
I have tried using container instead of context, but that does not work,
either.
As an example, say we have the following hierarchy:
menu1
- menu2
- menu3
- menu4
If I were to delete menu1, I would get an error inside menu2 like:
BadRequest: m3 does not exist
Sometimes I get attribute errors (e.g. __getitem__ doesn't exist), or
keyerrors.
The problem either happens in ObjectManager._getOb, or
manage_delObjects.
I get the feeling that *somehow* the context becomes menu1, even though
the callback says it is really menu2. Otherwise, I don't understand how
menu2.objectValues() would EVER know about it's siblings!
Any ideas why this is happening? Do just not understand acquisition?
Thank you so much for the help,
Andy