[Zope] Create object inside newly created container?

Casey Duncan cduncan@kaivo.com
Thu, 10 May 2001 11:27:14 -0600


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
`------------------>