[Zope] manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot

Tim Hicks tim@sitefusion.co.uk
Tue, 24 Sep 2002 16:38:32 +0100


Grégoire Weber wrote:
> Hi,
> 
> below an issue I don't have any idea where the problem lies. Are there some 
> experts around that could give me some advice? Thanks! The code is for the 
> redesign of the swiss community site http://www.zope.ch hopefully working 
> in two weeks. So please, help!
> 
> Are there any known issues copy&pasting a freshly added object A to another 
> folderish object I in the A's manage_afterAdd hook?
> 
> Doing Copy&Paste by hand (by GUI) after the object A was added works.
> 
> Have a look at the simplified code snippet (Python Product):
> 
> def manage_afterAdd(self, item, container):
>    """ simplified code called after instanation of object A 
>        (self) in folder P (container)
>    """
>    index_obj = getattr(container.aq_base, 'index_html', None)
>    if (index_obj is not None) and (index_obj.meta_type == self.meta_type):
>        # P has an object I (index_obj) of the same type as A is
>        index_obj.addToCollection(container._getOb(self.getId()))
> 
> def addToCollection(self, obj):
>    """ simplified code in the same class called on index_html object 
>    """
>    container = obj.getParentNode()
>    id = obj.getId()
> 
>    # this copies object A (obj, just instanated before manage_afterAdd!!!) 
>    # to object I (self, same as index_obj above)
>    self.manage_pasteObjects(context.manage_copyObjects(id)) # raises ERROR below
                               ^^^^^^^

Not sure, but shouldn't 'context' be 'self'?  I'm not sure because that 
doesn't seem to be the error that you are seeing.  I would have thought 
that the use of 'context' would raise a NameError (or something like that).

tim