Added "inherit_from" attribute to IInheritInfo interface
authorThierry Florac <thierry.florac@onf.fr>
Wed, 09 May 2018 14:05:08 +0200
changeset 176 f2acf176be2c
parent 175 db6128915fc1
child 177 d9c6a2a99acf
child 255 ecccb445b517
Added "inherit_from" attribute to IInheritInfo interface
src/pyams_utils/inherit.py
src/pyams_utils/interfaces/inherit.py
--- a/src/pyams_utils/inherit.py	Wed May 09 14:04:21 2018 +0200
+++ b/src/pyams_utils/inherit.py	Wed May 09 14:05:08 2018 +0200
@@ -61,6 +61,15 @@
     def no_inherit(self, value):
         self.inherit = not bool(value)
 
+    @property
+    def inherit_from(self):
+        if not self.inherit:
+            return self
+        parent = self.parent
+        while self.adapted_interface(parent).inherit:
+            parent = parent.parent
+        return parent
+
 
 class InheritedFieldProperty(object):
     """Inherited field property"""
--- a/src/pyams_utils/interfaces/inherit.py	Wed May 09 14:04:21 2018 +0200
+++ b/src/pyams_utils/interfaces/inherit.py	Wed May 09 14:05:08 2018 +0200
@@ -41,3 +41,5 @@
     no_inherit = Bool(title=_("Don't inherit from parent?"),
                       required=False,
                       default=False)
+
+    inherit_from = Attribute("Parent from which adapted interface is inherited")