Create object inside newly created container?
Inside a python product, I have a class that subclasses OFS:Folder, and upon TTW instatiation of this object, I want to have a ZCatalog instance called 'Catalog' created within this new folder. Is the appropriate place to put code to do this within the class __init__() or within the module's manage_add...() method? What would one use to obtain the namespace of a newly created object after it is set in the ODB via _setObject()? I assume that after calling _setObject() in manage_add...(), that one could traverse into the namespace of that object, and call manage_addProduct['ZCatalog'].manage_addZCatalog()... Any thoughts? Sean ========================= Sean Upton Senior Programmer/Analyst SignOnSanDiego.com The San Diego Union-Tribune 619.718.5241 sean.upton@uniontrib.com =========================
Hi Sean, --On Donnerstag, 10. Mai 2001 10:03 -0700 sean.upton@uniontrib.com wrote:
Inside a python product, I have a class that subclasses OFS:Folder, and upon TTW instatiation of this object, I want to have a ZCatalog instance called 'Catalog' created within this new folder. Is the appropriate place to put code to do this within the class __init__() or within the module's manage_add...() method? What would one use to obtain the namespace of a newly created object after it is set in the ODB via _setObject()?
I assume that after calling _setObject() in manage_add...(), that one could traverse into the namespace of that object, and call manage_addProduct['ZCatalog'].manage_addZCatalog()...
Most of the zope code uses _getObject() directly after _setObject() to get the newly added object. Regards Tino
sean.upton@uniontrib.com wrote:
Inside a python product, I have a class that subclasses OFS:Folder, and upon TTW instatiation of this object, I want to have a ZCatalog instance called 'Catalog' created within this new folder. Is the appropriate place to put code to do this within the class __init__() or within the module's manage_add...() method? What would one use to obtain the namespace of a newly created object after it is set in the ODB via _setObject()?
IMHO the instantiation should be done in __init__ instead of the manage_add... method so that if you subclass it, you retain this behavior in the subclasses.
I assume that after calling _setObject() in manage_add...(), that one could traverse into the namespace of that object, and call manage_addProduct['ZCatalog'].manage_addZCatalog()...
To instanciate ZCatalog in your product: from Products.ZCatalog.ZCatalog import ZCatalog from OFS.Folder import Folder class MyClass(Folder): def __init__(self, id, title=''): catalog = ZCatalog('Catalog') self._setObject('Catalog', catalog)
Any thoughts?
Sean
hth -- | Casey Duncan | Kaivo, Inc. | cduncan@kaivo.com `------------------>
participants (3)
-
Casey Duncan -
sean.upton@uniontrib.com -
Tino Wildenhain