entities: adapt default treemixin generators to Keyword entity
authorJulien Jehannet <julien.jehannet@logilab.fr>
Mon, 19 Oct 2009 21:39:58 +0200
changeset 71 178f11d7f7d7
parent 70 2cdf0d3d3977
child 72 c47d1759317c
entities: adapt default treemixin generators to Keyword entity
entities.py
--- a/entities.py	Mon Oct 19 10:48:23 2009 +0200
+++ b/entities.py	Mon Oct 19 21:39:58 2009 +0200
@@ -24,6 +24,10 @@
         """returns the parent entity"""
         return None
 
+    def iterparents(self):
+        """returns parent entities"""
+        yield self
+
     def children(self, entities=True):
         """returns the item's children"""
         return self.related('included_in', 'object', entities=entities)
@@ -55,13 +59,28 @@
 
     @property
     def classification(self):
-        return self.included_in[0]
+        if self.included_in:
+            return self.included_in[0]
+        return None
 
     def parent(self):
         if self.subkeyword_of:
             return self.subkeyword_of[0]
         return self.classification
 
+    def iterparents(self):
+        """returns parent entities"""
+        parent = self.parent()
+        while parent is not None:
+            yield parent
+            parent = parent.parent()
+
+    def iterchildren(self):
+        """returns children entities"""
+        if self.reverse_descendant_of:
+            for child in self.reverse_descendant_of:
+                yield child
+
     def is_leaf(self):
         if self.reverse_subkeyword_of:
             return False