TreeMixin : provide an iterator on the parents
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Fri, 05 Dec 2008 11:51:03 +0100
changeset 173 a4a9e1a7e40f
parent 172 bed4bc2e0a2f
child 181 a57548916045
TreeMixin : provide an iterator on the parents
common/mixins.py
--- a/common/mixins.py	Tue Dec 02 19:25:59 2008 +0100
+++ b/common/mixins.py	Fri Dec 05 11:51:03 2008 +0100
@@ -95,6 +95,16 @@
         path.reverse()
         return path
     
+    def iterparents(self):
+        def _uptoroot(self):
+            curr = self
+            while True:
+                curr = curr.parent()
+                if curr is None:
+                    break
+                yield curr
+        return _uptoroot(self)
+
     def notification_references(self, view):
         """used to control References field of email send on notification
         for this entity. `view` is the notification view.