[Checkins] SVN: z3c.relationfield/trunk/ Change the signature of create_relation to be more useful. Also use it
Martijn Faassen
faassen at infrae.com
Mon Jan 19 15:06:10 EST 2009
Log message for revision 94858:
Change the signature of create_relation to be more useful. Also use it
in resolving temporary relations.
Changed:
U z3c.relationfield/trunk/CHANGES.txt
U z3c.relationfield/trunk/src/z3c/relationfield/relation.py
-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt 2009-01-19 19:52:25 UTC (rev 94857)
+++ z3c.relationfield/trunk/CHANGES.txt 2009-01-19 20:06:10 UTC (rev 94858)
@@ -22,6 +22,12 @@
You can also for broken status by calling ``isBroken`` on a
relation.
+* The signature of the top-level function ``create_relation``
+ changed. It used to take the object to which the relation was to be
+ created, but should now get the path (in ``IObjectPath`` terms).
+ ``create_relation`` will now create a broken relation object if the
+ path cannot be resolved.
+
0.2 (2009-01-08)
================
Modified: z3c.relationfield/trunk/src/z3c/relationfield/relation.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/relation.py 2009-01-19 19:52:25 UTC (rev 94857)
+++ z3c.relationfield/trunk/src/z3c/relationfield/relation.py 2009-01-19 20:06:10 UTC (rev 94858)
@@ -81,17 +81,7 @@
self.to_path = to_path
def convert(self):
- object_path = component.getUtility(IObjectPath)
- try:
- to_object = object_path.resolve(self.to_path)
- except ValueError:
- # we have a broken relation, so create one
- result = RelationValue(None)
- result.broken(self.to_path)
- return result
- intids = component.getUtility(IIntIds)
- to_id = intids.getId(to_object)
- return RelationValue(to_id)
+ return create_relation(self.to_path)
def _object(id):
if id is None:
@@ -114,6 +104,18 @@
def _interfaces_flattened(interfaces):
return Declaration(*interfaces).flattened()
-def create_relation(obj):
- intids = component.getUtility(IIntIds)
- return RelationValue(intids.getId(obj))
+def create_relation(to_path):
+ """Create a relation to a particular path.
+
+ Will create a broken relation if the path cannot be resolved.
+ """
+ object_path = component.getUtility(IObjectPath)
+ try:
+ to_object = object_path.resolve(to_path)
+ intids = component.getUtility(IIntIds)
+ return RelationValue(intids.getId(to_object))
+ except ValueError:
+ # create broken relation
+ result = RelationValue(None)
+ result.broken(to_path)
+ return result
More information about the Checkins
mailing list