[PATCH 4 of 5 seda] [entities] Add inherited_rule method where it may be used from the UI

Sylvain Thenault sylvain.thenault at logilab.fr
Fri Mar 17 10:45:12 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489741075 -3600
#      Fri Mar 17 09:57:55 2017 +0100
# Node ID 6ba8714893470ce571da20d437898696cfe2dece
# Parent  3c65e089271ed20fad54c3fb0115f16980e2e055
[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.

diff --git a/cubicweb_seda/entities/custom.py b/cubicweb_seda/entities/custom.py
--- a/cubicweb_seda/entities/custom.py
+++ b/cubicweb_seda/entities/custom.py
@@ -38,10 +38,22 @@ def _climb_rule_holders(transfer_or_arch
         else:
             yield transfer_or_archive_unit.first_level_choice.content_sequence
         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):
         return self.title
 
@@ -71,10 +83,12 @@ class SEDAArchiveTransfer(generated.SEDA
 
     @property
     def binary_data_objects(self):
         return self.reverse_seda_binary_data_object
 
+    inherited_rule = _inherited_rule
+
 
 class SEDAArchiveUnit(generated.SEDAArchiveUnit):
 
     def dc_title(self):
         return _extract_title(self.user_annotation)
@@ -91,20 +105,11 @@ class SEDAArchiveUnit(generated.SEDAArch
         """Return the choice element of an archive unit (SEDAAltArchiveUnitArchiveUnitRefId),
         holding either a reference or descriptive content
         """
         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):
 
     def dc_title(self):
@@ -215,10 +220,12 @@ class SEDASeqAltArchiveUnitArchiveUnitRe
     def originating_agency(self):
         if self.reverse_seda_originating_agency_from:
             return self.reverse_seda_originating_agency_from[0]
         return None
 
+    inherited_rule = _inherited_rule
+
 
 class SEDAKeyword(generated.SEDAKeyword):
 
     @property
     def reference(self):


More information about the saem-devel mailing list