[Checkins] SVN: z3c.relationfield/trunk/ Use IIntIdAddedEvent instead of IObjectAddedEvent
Alec Mitchell
alecpm at gmail.com
Mon Jun 29 12:53:17 EDT 2009
Log message for revision 101327:
Use IIntIdAddedEvent instead of IObjectAddedEvent
Changed:
U z3c.relationfield/trunk/CHANGES.txt
U z3c.relationfield/trunk/src/z3c/relationfield/configure.zcml
U z3c.relationfield/trunk/src/z3c/relationfield/event.py
-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt 2009-06-29 15:59:39 UTC (rev 101326)
+++ z3c.relationfield/trunk/CHANGES.txt 2009-06-29 16:53:16 UTC (rev 101327)
@@ -4,6 +4,8 @@
0.5 (unreleased)
==================
+* Subscribe to IIntIdAddedEvent instead of IObjectAddedEvent to prevent
+ errors due to subscriber ordering.
0.4.3 (2009-06-04)
Modified: z3c.relationfield/trunk/src/z3c/relationfield/configure.zcml
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/configure.zcml 2009-06-29 15:59:39 UTC (rev 101326)
+++ z3c.relationfield/trunk/src/z3c/relationfield/configure.zcml 2009-06-29 16:53:16 UTC (rev 101327)
@@ -5,5 +5,6 @@
<include package="grokcore.component" file="meta.zcml" />
<grok:grok package="."/>
+
</configure>
Modified: z3c.relationfield/trunk/src/z3c/relationfield/event.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/event.py 2009-06-29 15:59:39 UTC (rev 101326)
+++ z3c.relationfield/trunk/src/z3c/relationfield/event.py 2009-06-29 16:53:16 UTC (rev 101327)
@@ -4,9 +4,10 @@
from zope.schema import getFields
from zope import component
from zope.event import notify
-from zope.app.intid.interfaces import IIntIds, IIntIdRemovedEvent
-from zope.app.container.interfaces import (IObjectAddedEvent,
- IObjectRemovedEvent)
+from zope.app.intid.interfaces import (IIntIds,
+ IIntIdRemovedEvent,
+ IIntIdAddedEvent)
+from zope.app.container.interfaces import IObjectRemovedEvent
from zope.lifecycleevent.interfaces import IObjectModifiedEvent
from zope.lifecycleevent import ObjectModifiedEvent
@@ -18,7 +19,8 @@
IRelationValue,
ITemporaryRelationValue)
- at grok.subscribe(IHasOutgoingRelations, IObjectAddedEvent)
+# five.intid dispatches an object event for efficiency
+ at grok.subscribe(IHasOutgoingRelations, IIntIdAddedEvent)
def addRelations(obj, event):
"""Register relations.
@@ -27,6 +29,17 @@
for name, relation in _relations(obj):
_setRelation(obj, name, relation)
+# zope.app.intid dispatches a normal event, so we need to check that the object
+# has relations. This adds some overhead to every intid registration,
+# which would not be needed if an object event were fired.
+ at grok.subscribe(IIntIdAddedEvent)
+def addRelationsEventOnly(event):
+ obj = event.object
+ if not IHasOutgoingRelations.providedBy(obj):
+ return
+ addRelations(obj, event)
+
+
@grok.subscribe(IHasOutgoingRelations, IObjectRemovedEvent)
def removeRelations(obj, event):
"""Remove relations.
More information about the Checkins
mailing list