complete ITree interface
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Mon, 10 Aug 2009 11:04:42 +0200
changeset 55 d1982791000f
parent 54 d03369f67a1d
child 56 9cae95b68efe
complete ITree interface
entities.py
--- a/entities.py	Mon Aug 10 10:56:45 2009 +0200
+++ b/entities.py	Mon Aug 10 11:04:42 2009 +0200
@@ -15,14 +15,30 @@
     fetch_attrs, fetch_order = fetch_config(['name'])
     __implements__ = AnyEntity.__implements__ + (ITree,)
 
+    def root(self):
+        """returns the root object"""
+        return None
+
     def parent(self):
-        """overriden from TreeMixIn"""
+        """returns the parent entity"""
         return None
 
     def children(self, entities=True):
-        """TreeMixIn interface"""
+        """returns the item's children"""
         return self.related('included_in', 'object', entities=entities)
 
+    def children_rql(self):
+        """XXX returns RQL to get children"""
+        return self.related_rql('included_in', 'object')
+
+    def is_leaf(self):
+        """returns true if this node as no child"""
+        return bool(self.children())
+
+    def is_root(self):
+        """returns true if this node has no parent"""
+        return True
+
 
 class Keyword(TreeMixIn, AnyEntity):
     id = 'Keyword'
@@ -47,6 +63,7 @@
             # XXX no state yet, due to notification before state has been set
             return self.name
 
+
 class CodeKeyword(Keyword):
     id = 'CodeKeyword'
     rest_attr = 'code'