[Zope3-dev] Correctly sending ObjectModifiedEvents [was SVN:
zope.webdav/trunk/src/zope/webdav/
Emit an ObjectModifiedEvent on successfully modifying a property with]
Philipp von Weitershausen
philipp at weitershausen.de
Tue Feb 20 08:52:25 EST 2007
Michael Kerrin wrote:
> Log message for revision 72694:
> Emit an ObjectModifiedEvent on successfully modifying a property with
> the proppatch method.
...
>
> + if changed:
> + zope.event.notify(ObjectModifiedEvent(self.context))
> +
Just emitting an ObjectModifiedEvent like that is pretty useless, IMO.
With this you have no clue
- whether the object or the object's annotations were modified
- which properties of which schema were modified.
The good news is that the ObjectModifiedEvent API actually supports this
kind of stuff, you just need to use it:
info = Attributes(ITheSchema, 'foo', 'bar', 'blergh')
notify(ObjectModifiedEvent(obj, info))
(Attributes is importable from zope.lifecycleevent). Note that the
object must not necessarily provide ITheSchema, it could also be that
the ITheSchema(obj) adapter was changed (this is useful when sending
modified events for annotation adapters like IZopeDublinCore).
Unfortunately, not many places in Zope 3 itself are good examples of
this. In fact, not even formlib sends this extra information along with
the events, something I've been meaning to report and fix. (Thanks for
reminding me to do so :)).
Philipp
--
http://worldcookery.com -- Professional Zope documentation and training
Next Zope 3 training at Camp5: http://trizpug.org/boot-camp/camp5
More information about the Zope3-dev
mailing list