[Checkins] SVN: z3c.relationfield/trunk/ Fix a comparison bug.
Martijn Faassen
faassen at infrae.com
Tue Jan 20 16:12:04 EST 2009
Log message for revision 94883:
Fix a comparison bug.
Changed:
U z3c.relationfield/trunk/CHANGES.txt
U z3c.relationfield/trunk/src/z3c/relationfield/README.txt
U z3c.relationfield/trunk/src/z3c/relationfield/relation.py
-=-
Modified: z3c.relationfield/trunk/CHANGES.txt
===================================================================
--- z3c.relationfield/trunk/CHANGES.txt 2009-01-20 21:09:53 UTC (rev 94882)
+++ z3c.relationfield/trunk/CHANGES.txt 2009-01-20 21:12:04 UTC (rev 94883)
@@ -1,11 +1,14 @@
CHANGES
*******
-0.4 (unreleased)
-================
+0.3.1 (unreleased)
+==================
-* ...
+* Introduce sensible sort order for relations, based on a
+ ``(from_attribute, from_path, to_path)`` tuple.
+* Relations will now never compare to ``None``.
+
0.3 (2009-01-19)
================
Modified: z3c.relationfield/trunk/src/z3c/relationfield/README.txt
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/README.txt 2009-01-20 21:09:53 UTC (rev 94882)
+++ z3c.relationfield/trunk/src/z3c/relationfield/README.txt 2009-01-20 21:12:04 UTC (rev 94883)
@@ -378,6 +378,27 @@
>>> l[1].from_path
u'b-2'
+Relations are sortable
+======================
+
+Relations are sorted by default on a combination of the relation name,
+the path of the object the relation is one and the path of the object
+the relation is pointing to.
+
+Let's query all relations availble right now and sort them::
+
+ >>> l = sorted(catalog.findRelations())
+ >>> len(l)
+ 2
+ >>> l[0].from_attribute
+ 'rel'
+ >>> l[1].from_attribute
+ 'rel'
+ >>> l[0].from_path
+ u'b'
+ >>> l[1].from_path
+ u'b-2'
+
Removing an object with relations
=================================
@@ -428,6 +449,11 @@
>>> b.rel.to_id is None
True
+A broken relation isn't equal to ``None`` (this was a bug)::
+
+ >>> b.rel == None
+ False
+
RelationList
============
Modified: z3c.relationfield/trunk/src/z3c/relationfield/relation.py
===================================================================
--- z3c.relationfield/trunk/src/z3c/relationfield/relation.py 2009-01-20 21:09:53 UTC (rev 94882)
+++ z3c.relationfield/trunk/src/z3c/relationfield/relation.py 2009-01-20 21:12:04 UTC (rev 94883)
@@ -59,9 +59,12 @@
def __cmp__(self, other):
if other is None:
- return cmp(self.to_id, None)
- return cmp(self.to_id, other.to_id)
+ return cmp(self._sort_key(), None)
+ return cmp(self._sort_key(), other._sort_key())
+ def _sort_key(self):
+ return (self.from_attribute, self.from_path, self.to_path)
+
def broken(self, to_path):
self._broken_to_path = to_path
self.to_id = None
More information about the Checkins
mailing list