[views] Attempt to display inherited rule if there is no rule defined at some level
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 17 Mar 2017 10:01:50 +0100
changeset 2516 40a0ca66bc1a
parent 2515 bfe6130e62b5
child 2517 a1c4bd82b303
[views] Attempt to display inherited rule if there is no rule defined at some level Closes extranet #14593198
cubicweb_seda/i18n/en.po
cubicweb_seda/i18n/fr.po
cubicweb_seda/views/mgmt_rules.py
--- a/cubicweb_seda/i18n/en.po	Fri Mar 17 09:57:55 2017 +0100
+++ b/cubicweb_seda/i18n/en.po	Fri Mar 17 10:01:50 2017 +0100
@@ -4756,6 +4756,9 @@
 msgid "import_unit"
 msgstr ""
 
+msgid "inherited value"
+msgstr ""
+
 msgid "juridictional"
 msgstr ""
 
--- a/cubicweb_seda/i18n/fr.po	Fri Mar 17 09:57:55 2017 +0100
+++ b/cubicweb_seda/i18n/fr.po	Fri Mar 17 10:01:50 2017 +0100
@@ -4775,6 +4775,9 @@
 msgid "import_unit"
 msgstr "unité d'archive du référentiel"
 
+msgid "inherited value"
+msgstr "valeur héritée"
+
 msgid "juridictional"
 msgstr "juridication administrative"
 
--- a/cubicweb_seda/views/mgmt_rules.py	Fri Mar 17 09:57:55 2017 +0100
+++ b/cubicweb_seda/views/mgmt_rules.py	Fri Mar 17 10:01:50 2017 +0100
@@ -23,7 +23,7 @@
 
 from cubicweb.predicates import is_instance
 from cubicweb.web import INTERNAL_FIELD_VALUE
-from cubicweb.web.views import uicfg
+from cubicweb.web.views import reledit, uicfg
 
 from ..entities import parent_and_container, rule_type_from_etype
 from . import viewlib
@@ -180,3 +180,18 @@
                 need_human = _('without human intervention')
             self.w(u'<div>{0}</div>'.format(xml_escape(need_human)))
         super(ClassificationRuleComplexLinkEntityAttributeView, self).entity_call(entity)
+
+
+class MgmtRuleAutoClickAndEditFormView(reledit.AutoClickAndEditFormView):
+    __select__ = (reledit.AutoClickAndEditFormView.__select__
+                  & is_instance('SEDASeqAltArchiveUnitArchiveUnitRefIdManagement'))
+
+    def _compute_default_value(self, rschema, role):
+        if rschema.type.endswith('_rule'):
+            rule_type = rschema.type[len('seda_'):-len('_rule')]
+            rule = self.entity.inherited_rule(rule_type)
+            if rule:
+                return rule.view('seda.reledit.text') + u'<p><mark>{}</mark></p>'.format(
+                    self._cw._(u'inherited value'))
+        return super(MgmtRuleAutoClickAndEditFormView, self)._compute_default_value(
+            rschema, role)