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

Simplify rule inheritance control of simplified profiles

We may hide the ignore all rules / ignore one rule complexity since there may be
only one inherited rule.

Do several tweaks to make it nice.

Note it doesn't work yet until the parent rule entity isn't created, because we
are not able to detect the parent transfer...
parent d3e384864e8f
......@@ -1329,7 +1329,7 @@ msgid "SEDAPhysicalDataObject_plural"
msgstr "objets-données physiques"
msgid "SEDAPreventInheritance"
msgstr "ignorer toutes les règles héritées"
msgstr "ignorer les règles héritées"
msgctxt ""
"inlined:SEDAAltAccessRulePreventInheritance.seda_prevent_inheritance.object"
......@@ -3217,7 +3217,7 @@ msgid "add a SEDAPhysicalDataObject"
msgstr ""
msgid "add a SEDAPreventInheritance"
msgstr "ignorer toutes les règles héritées"
msgstr "ignorer les règles héritées"
msgctxt ""
"inlined:SEDAAltAccessRulePreventInheritance.seda_prevent_inheritance.object"
......
......@@ -291,6 +291,17 @@ class SimplifiedFormsTC(CubicWebTC):
self.assertNoRemove(form, 'seda_start_date', 'object')
self.assertNoTitle(form, 'seda_start_date', 'object')
def test_prevent_inheritance_form(self):
with self.admin_access.web_request() as req:
for rule_type in ('access', 'appraisal'):
form = self.rule_form(req, 'SEDAAlt{0}RulePreventInheritance'.format(
rule_type.capitalize()))
self.assertInlinedFields(form, [
('seda_prevent_inheritance', 'PreventInheritanceInlineEntityCreationFormView'),
])
self.assertNoRemove(form, 'seda_prevent_inheritance', 'object')
self.assertEqual(form.form_renderer_id, 'not-an-alt')
if __name__ == '__main__':
unittest.main()
......@@ -18,7 +18,7 @@
from logilab.common.registry import objectify_predicate
from cubicweb.predicates import is_instance
from cubicweb.web.views import uicfg, autoform
from cubicweb.web.views import uicfg, autoform, formrenderers
from cubes.seda.entities import simplified_profile
from cubes.seda.views import copy_rtag
......@@ -123,3 +123,63 @@ class StartDateInlineEntityCreationFormView(autoform.InlineEntityCreationFormVie
& simplified_start_date())
removejs = None
form_renderer_id = 'notitle'
# simplified profil will have a single appraisal/access rule, hence 'ignore inherited rules' is
# enough, no need for explicit rule deactivation. This implies:
# 1. hide explicit rule deactivation
# 2. force appearance (hence choice) of the ignore all rules entity
# 3. adapt alternative's title, so it doesn't appear like an alternative
# 1. hide explicit rule deactivation
simplified_afs.tag_object_of(('*', 'seda_ref_non_rule_id_from', '*'),
'main', 'hidden')
class AltInheritanceAutomaticEntityForm(autoform.AutomaticEntityForm):
__select__ = (is_instance('SEDAAltAccessRulePreventInheritance',
'SEDAAltAppraisalRulePreventInheritance')
& simplified_profile())
# 3. adapt alternative's title, so it doesn't appear like an alternative
def __init__(self, *args, **kwargs):
super(AltInheritanceAutomaticEntityForm, self).__init__(*args, **kwargs)
self.form_renderer_id = 'not-an-alt'
# 2. force appearance (hence choice) of the ignore all rules entity
def should_display_inline_creation_form(self, rschema, existing, card):
if not existing and rschema == 'seda_prevent_inheritance':
return True
return super(AltInheritanceAutomaticEntityForm, self).should_display_inline_creation_form(
rschema, existing, card)
# 2. force appearance (hence choice) of the ignore all rules entity
@objectify_predicate
def simplified_prevent_inheritance(cls, req, rtype=None, pform=None, **kwargs):
if isinstance(pform, AltInheritanceAutomaticEntityForm) and rtype == 'seda_prevent_inheritance':
return 1
return 0
class PreventInheritanceInlineEntityEditionFormView(autoform.InlineEntityEditionFormView):
__select__ = (autoform.InlineEntityEditionFormView.__select__
& simplified_prevent_inheritance())
removejs = None
class PreventInheritanceInlineEntityCreationFormView(autoform.InlineEntityCreationFormView):
__select__ = (autoform.InlineEntityCreationFormView.__select__
& simplified_prevent_inheritance())
removejs = None
class NotAnAltEntityInlinedFormRenderer(formrenderers.EntityInlinedFormRenderer):
"""Custom form renderer that remove 'Alternative :' from an alternative's inlined form's title.
"""
__regid__ = 'not-an-alt'
def render_title(self, w, form, values):
values['title'] = values['title'].split(':', 1)[1]
super(NotAnAltEntityInlinedFormRenderer, self).render_title(w, form, values)
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