[Zope] manage_pasteObjects in manage_afterAdd raises AttributeError for getPhysicalRoot

Grégoire Weber gregoire.weber@switzerland.org
Tue, 24 Sep 2002 19:42:50 +0200


Hi All,

forgotten to post reply Tims and Roberts reply to the list. here ist is:

sorry first,

   there was a typo in the snippet as Tim stated (container is 
   correct instead of context in the last line):

second, 

   as robert supposed and I am casting suspicion on also is that the 
   problem could be that obj has not yet anaquisition wrapper. 
   Must this be done in addToCollection before container = ..., but 
   how?

third (Robert): 

   Ok, I see in this special case the parent of object A 
   is the same as the parent of object I. addToCollection is called in
   other contexts also, where this is not the case. So I can not change 
   that. It seems not to be the containers problem.

Greetings, Greg

--------------------------------------------------------------------------
Snippet no 2:

  - now correct and slightly changed code snippet 

  - The snippet now avoids generating obj out of the id and the container 
    and then regenerating the id and the container out of obj

  - same error as before

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, self.getId())
       # tried also to pass self wrapped by container: 
       #   index_obj.addToCollection(container, self.__of__(container).getId())

def addToCollection(self, container, id):
   """ simplified code in the same class called on index_html object 
   """
  # this copies object A (container/id, just instanated before 
   # manage_afterAdd!!!) to object I (self, same as index_obj above)
   cb = container.manage_copyObjects(id) # OK
   self.manage_pasteObjects(cb) # raises ERROR (same as before)

At 16:38 24.09.2002 +0100, you wrote:
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
                              ^^^^^^^ <-- has to be container

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
_____________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone:  +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org