> Yes, this is what I'd recommend. A handler for an ObjectAddedEvent will
> always see the object already as part of the object hierarchy (which is,
> after all, what ObjectAddedEvent is about).
I found myself doing this quite often.
I use a decorator to make the code read nicer..
self['subobject'] = SomeObject()
self['subobject2'] = AnotherObject()
"""Decorator which invokes a method after an instance
has been added to a container.
caller_locals = sys._getframe(1).f_locals
if caller_locals.get('__callafteradd__') is None:
caller_locals['__callafteradd__'] = ()
caller_locals['__callafteradd__'] += (method,)
callafteradd_methods = getattr(ob, '__callafteradd__', ())
for f in callafteradd_methods:
Zope3-users mailing list