Problems accessing container properties at product creation time
Hi Folks, I am trying to create a nested Zope product, and have trouble accessing properties from the container object... - I have a class MyFolder that extends Folder. - I have a class MyObj that extends (CatalogAware, SimpleItem, PropertyManager) - Class MyFolder is meant to contain several instances of class MyObj. I am able to create instances of class MyObj properly, and even have them be contained within MyFolder (using the inherited _setObject method of MyFolder). My problem is that I cannot seem to get manage_changeProperties to work on instances of MyObj at the time of addition (ie: just after I do the _setObject call). I have similar problems referencing methods/properties of MyFolder from within the methods of MyObject at the time of creation. However, after the addition has taken place, I can then through the ZMI, access or manipulate those same (and previously inaccessible/supposedly-non-existent) properties in MyFolder from within MyObj instances. What am I missing here. Is there anther step besides calling _setObject that I need to do, when the container is also a custom class in my product? Do I need to define my own __getattr__() for MyObj instances? I have tried to grep through the source code for various products, but am not seeing an obvious solution. Thanks, Roy Mathew. __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/
whil you are in a factory that creates your object it is not yet "rooted" in the zodb. It is not yet a "real" object. However in the manage_afterAdd method which you must override in your class you can do as you please. Robert Roy Mathew wrote:
Hi Folks,
I am trying to create a nested Zope product, and have trouble accessing properties from the container object...
- I have a class MyFolder that extends Folder. - I have a class MyObj that extends (CatalogAware, SimpleItem, PropertyManager) - Class MyFolder is meant to contain several instances of class MyObj.
I am able to create instances of class MyObj properly, and even have them be contained within MyFolder (using the inherited _setObject method of MyFolder).
My problem is that I cannot seem to get manage_changeProperties to work on instances of MyObj at the time of addition (ie: just after I do the _setObject call). I have similar problems referencing methods/properties of MyFolder from within the methods of MyObject at the time of creation. However, after the addition has taken place, I can then through the ZMI, access or manipulate those same (and previously inaccessible/supposedly-non-existent) properties in MyFolder from within MyObj instances.
What am I missing here. Is there anther step besides calling _setObject that I need to do, when the container is also a custom class in my product? Do I need to define my own __getattr__() for MyObj instances? I have tried to grep through the source code for various products, but am not seeing an obvious solution.
Thanks, Roy Mathew.
__________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
--- robert rottermann <robert@redcor.ch> wrote:
whil you are in a factory that creates your object it is not yet "rooted" in the zodb. It is not yet a "real" object. However in the manage_afterAdd method which you must override in your class you can do as you please. Robert
Thanks for the tip, Robert. I did also notice that if I did the following (right after _setObject()): ob = container._getOb(id) and worked with the "ob" handle, I could access properties in the container. I can't say I understand why :( Roy. __________________________________ Do you Yahoo!? Yahoo! Small Business $15K Web Design Giveaway http://promotions.yahoo.com/design_giveaway/
Thanks for the tip, Robert. I did also notice that if I did the following (right after _setObject()):
ob = container._getOb(id)
and worked with the "ob" handle, I could access properties in the container. I can't say I understand why :(
Because this latter is the "wrapped" version of your object in the terms of aquisition. You can use __of__ to achive the same result.
I have similar problems referencing methods/properties of MyFolder from within the methods of MyObject at the time of creation.
Oh, this is a nice one. If you have a newly created object, and you want to store references pointing to other zodb objects in it, you always have to do that with the wrapped version, e.g. either in manage_afterAdd, or from the container. You can't do that in __init__. This bit me once because sometimes it still works and gives very strange results when you try to debug. Regards, Sandor
participants (3)
-
robert rottermann -
Roy Mathew -
zope@netchan.cotse.net