[Checkins] SVN: z3c.relationfield/trunk/ Properly catalog broken relations.

Martijn Faassen faassen at infrae.com
Wed Jan 21 13:19:01 EST 2009


Log message for revision 94909:
  Properly catalog broken relations.
  

Changed:
  U   z3c.relationfield/trunk/CHANGES.txt
  U   z3c.relationfield/trunk/src/z3c/relationfield/README.txt
  U   z3c.relationfield/trunk/src/z3c/relationfield/event.py

-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt	2009-01-21 17:54:32 UTC (rev 94908)
+++ z3c.relationfield/trunk/CHANGES.txt	2009-01-21 18:19:01 UTC (rev 94909)
@@ -1,10 +1,10 @@
 CHANGES
 *******
 
-0.4 (unreleased)
-================
+0.3.2 (unreleased)
+==================
 
-* ...
+* When a relation is broken, properly re-catalog things.
 
 0.3.1 (2009-01-20)
 ==================

Modified: z3c.relationfield/trunk/src/z3c/relationfield/README.txt
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/README.txt	2009-01-21 17:54:32 UTC (rev 94908)
+++ z3c.relationfield/trunk/src/z3c/relationfield/README.txt	2009-01-21 18:19:01 UTC (rev 94909)
@@ -420,6 +420,11 @@
   >>> sorted(catalog.findRelations({'to_id': c_id})) 
   [<z3c.relationfield.relation.RelationValue object at ...>]
 
+We have no broken relations::
+
+  >>> sorted(catalog.findRelations({'to_id': None})) 
+  []
+
 The relation isn't broken::
   
   >>> b.rel.isBroken()
@@ -449,6 +454,18 @@
   >>> b.rel.to_id is None
   True
 
+We cannot find the broken relation in the catalog this way as it's not
+pointing to ``c_id`` anymore::
+
+  >>> sorted(catalog.findRelations({'to_id': c_id})) 
+  []
+
+We can however find it by searching for relations that have a
+``to_id`` of ``None``::
+
+  >>> sorted(catalog.findRelations({'to_id': None})) 
+  [<z3c.relationfield.relation.RelationValue object at ...>]
+
 A broken relation isn't equal to ``None`` (this was a bug)::
 
   >>> b.rel == None

Modified: z3c.relationfield/trunk/src/z3c/relationfield/event.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/event.py	2009-01-21 17:54:32 UTC (rev 94908)
+++ z3c.relationfield/trunk/src/z3c/relationfield/event.py	2009-01-21 18:19:01 UTC (rev 94909)
@@ -3,10 +3,12 @@
 from zope.interface import providedBy
 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.lifecycleevent.interfaces import IObjectModifiedEvent
+from zope.lifecycleevent import ObjectModifiedEvent
 
 from zc.relation.interfaces import ICatalog
 
@@ -70,7 +72,9 @@
     rels = list(catalog.findRelations({'to_id': intids.getId(obj)}))
     for rel in rels:
         rel.broken(rel.to_path)
-    
+        # we also need to update the relations for these objects
+        notify(ObjectModifiedEvent(rel.from_object))
+        
 def realize_relations(obj):
     """Given an object, convert any temporary relations on it to real ones.
     """



More information about the Checkins mailing list