[entities] Add inherited_rule method where it may be used from the UI
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 17 Mar 2017 09:57:55 +0100
changeset 2515 bfe6130e62b5
parent 2514 c18e4cdffd64
child 2516 40a0ca66bc1a
[entities] Add inherited_rule method where it may be used from the UI In later cset, we'll want to retrieve the inherited rule from the management rule UI. This UI is generated from SEDAArchiveTransfer and SEDASeqAltArchiveUnitArchiveUnitRefIdManagement entities, so we want this method on those entity types.
cubicweb_seda/entities/custom.py
--- a/cubicweb_seda/entities/custom.py	Fri Mar 17 09:55:52 2017 +0100
+++ b/cubicweb_seda/entities/custom.py	Fri Mar 17 09:57:55 2017 +0100
@@ -40,6 +40,18 @@
         transfer_or_archive_unit = transfer_or_archive_unit.cw_adapt_to('ITreeBase').parent()
 
 
+def _inherited_rule(self, rule_type):
+    """Return the rule entity of the given type, defined on this unit or in its nearest parent
+    possible defining it, or None if no matching rule has been found.
+    """
+    assert rule_type in RULE_TYPES
+    rtype = 'reverse_seda_{}_rule'.format(rule_type)
+    for rule_holder in _climb_rule_holders(self):
+        if getattr(rule_holder, rtype):
+            return getattr(rule_holder, rtype)[0]
+    return None
+
+
 class SEDAArchiveTransfer(generated.SEDAArchiveTransfer):
 
     def dc_title(self):
@@ -73,6 +85,8 @@
     def binary_data_objects(self):
         return self.reverse_seda_binary_data_object
 
+    inherited_rule = _inherited_rule
+
 
 class SEDAArchiveUnit(generated.SEDAArchiveUnit):
 
@@ -93,16 +107,7 @@
         """
         return self.related('seda_alt_archive_unit_archive_unit_ref_id', 'subject').one()
 
-    def inherited_rule(self, rule_type):
-        """Return the rule entity of the given type, defined on this unit or in its nearest parent
-        possible defining it, or None if no matching rule has been found.
-        """
-        assert rule_type in RULE_TYPES
-        rtype = 'reverse_seda_{}_rule'.format(rule_type)
-        for rule_holder in _climb_rule_holders(self):
-            if getattr(rule_holder, rtype):
-                return getattr(rule_holder, rtype)[0]
-        return None
+    inherited_rule = _inherited_rule
 
 
 class SEDABinaryDataObject(generated.SEDABinaryDataObject):
@@ -217,6 +222,8 @@
             return self.reverse_seda_originating_agency_from[0]
         return None
 
+    inherited_rule = _inherited_rule
+
 
 class SEDAKeyword(generated.SEDAKeyword):