Hi again, I was a too hasty. Because it is the FieldIndex that is missing the _p_oid attribute, and the fix I offered is for the container. Sorry about that.
I need more thinking. Regards, Darryl On Tue, 2006-07-25 at 22:10 +1200, Darryl Cousins wrote: > Hi Lorenzo, > > The key reference adapter can only get a key reference **after** the > object is added to the database (because it uses _p_oid). > > The problem could be fixed with a subscriber to IObjectAddedEvent:: > > def FilterableContainerInitializationHandler(object, event): > """Initialize container after its ObjectAddedEvent.""" > > # I have checks here too (maybe unecessary) > if not IObjectAddedEvent.providedBy(event): > return > if not IFilterableContainer.providedBy(object): > return > # whatever needs to be done > # self._catalog ... > > This handler is configured:: > > <!-- initialization handler --> > <subscriber > for=".IFilterableContainer > zope.app.container.interfaces.IObjectAddedEvent" > handler=".subscribers.FilterableContainerInitializationHandler" > /> > > Hope that helps. > > Best regards, > Darryl > > On Tue, 2006-07-25 at 11:26 +0200, Lorenzo Gil Sanchez wrote: > > Hi, > > > > I have a special Folder content. When an instance of this class is > > created I want to create a catalog and an index in its __init__ method. > > Something like: > > > > class FilterableContainer(BTreeContainer): > > > > implements(IFilterableContainer) > > > > def __init__(self): > > super(FilterableContainer, self).__init__() > > self._catalog = LocalCatalog() > > self._catalog['attr1'] = FieldIndex(field_name='attr1') > > > > where LocalCatalog is a subclass of Catalog that only indexes objects > > that belong to its parent. > > > > The problem arises when I add my FieldIndex to my internal catalog. Some > > events are triggered and at the end I got this exception: > > > > File "/opt/Zope-3.2.1/lib/python/zope/app/keyreference/persistent.py", > > line 41, in __init__ > > raise zope.app.keyreference.interfaces.NotYet(object) > > NotYet: <zope.app.catalog.field.FieldIndex object at 0x2aaab3609b90> > > > > > > It happens because the key reference adaptor to Persistent thinks my > > FieldIndex object is already stored in the database, which is not the > > case. > > > > Anybody knows how should I add an index to my catalog in the __init__ > > method? > > > > Thanks in advance > > > > Lorenzo > > > > _______________________________________________ > > Zope3-users mailing list > > Zope3-users@zope.org > > http://mail.zope.org/mailman/listinfo/zope3-users > > _______________________________________________ > Zope3-users mailing list > Zope3-users@zope.org > http://mail.zope.org/mailman/listinfo/zope3-users _______________________________________________ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users