From 82fe118fde9524aa1cced20b5dc26a3abb3f040b Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 10 Jun 2020 18:47:17 +0200 Subject: Documents: better form - improve select2 widget to manage new --- ishtar_common/forms.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 66b5c3796..6193c72c4 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -624,6 +624,8 @@ class IshtarForm(forms.Form, BSForm): CONDITIONAL_FIELDS = [] # dynamic conditions on field display PROFILE_FILTER = {} # profile key associated to field list HEADERS = {} # field key associated to FormHeader instance + # permission check for widget options, ex: forms_common.DocumentForm + OPTIONS_PERMISSIONS = {} SITE_KEYS = {} # archaeological sites fields and associated translation key # to manage translation @@ -650,6 +652,14 @@ class IshtarForm(forms.Form, BSForm): self.fields[site_key].label = profile.get_site_label( self.SITE_KEYS[site_key] ) + for field_name, permissions, options in self.OPTIONS_PERMISSIONS: + if field_name not in self.fields or not getattr(self, "user", None): + continue + if not [True for permission in permissions + if self.user.has_perm(permission)]: + continue + for option, value in options.items(): + setattr(self.fields[field_name].widget, option, value) self._post_init() def _init_type(self, field): -- cgit v1.2.3