From e4454fdbf47a44de9de725ed733d12b604855da6 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 11 Mar 2019 18:55:33 +0100 Subject: Site translations in forms --- ishtar_common/forms.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'ishtar_common/forms.py') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 448c06ceb..c7e3fe38c 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -548,11 +548,16 @@ class IshtarForm(forms.Form, BSForm): TYPES = [] # FieldType list PROFILE_FILTER = {} # profile key associated to field list HEADERS = {} # field key associated to FormHeader instance + SITE_KEYS = {} # archaeological sites fields and associated translation key + # to manage translation def __init__(self, *args, **kwargs): super(IshtarForm, self).__init__(*args, **kwargs) - if self.PROFILE_FILTER: + profile = None + if self.PROFILE_FILTER or self.SITE_KEYS: profile = models.get_current_profile() + + if self.PROFILE_FILTER: for profile_key in self.PROFILE_FILTER: if not getattr(profile, profile_key): for field_key in self.PROFILE_FILTER[profile_key]: @@ -562,6 +567,13 @@ class IshtarForm(forms.Form, BSForm): return for field in self.TYPES: self._init_type(field) + if self.SITE_KEYS: + field_keys = list(self.fields.keys()) + for site_key in list(self.SITE_KEYS.keys()): + if site_key in field_keys: + self.fields[site_key].label = profile.get_site_label( + self.SITE_KEYS[site_key] + ) self._post_init() def _init_type(self, field): -- cgit v1.2.3