Commit e7b16a84 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[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.
parent c18e4cdffd64
......@@ -40,6 +40,18 @@ def _climb_rule_holders(transfer_or_archive_unit):
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 @@ class SEDAArchiveTransfer(generated.SEDAArchiveTransfer):
def binary_data_objects(self):
return self.reverse_seda_binary_data_object
inherited_rule = _inherited_rule
class SEDAArchiveUnit(generated.SEDAArchiveUnit):
......@@ -93,16 +107,7 @@ class SEDAArchiveUnit(generated.SEDAArchiveUnit):
"""
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 @@ class SEDASeqAltArchiveUnitArchiveUnitRefIdManagement(
return self.reverse_seda_originating_agency_from[0]
return None
inherited_rule = _inherited_rule
class SEDAKeyword(generated.SEDAKeyword):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment