diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-03-11 18:55:33 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2019-04-24 19:41:37 +0200 |
commit | 20d5c7d28d127a2ef8deab2ba2c6a7045700b6c8 (patch) | |
tree | 28057054e3cea0aa7815dbe0ef21d71219fae5e2 /ishtar_common/forms.py | |
parent | 630b7be7a5ee39bd418b81f8dc88831c1b65b39c (diff) | |
download | Ishtar-20d5c7d28d127a2ef8deab2ba2c6a7045700b6c8.tar.bz2 Ishtar-20d5c7d28d127a2ef8deab2ba2c6a7045700b6c8.zip |
Site translations in forms
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r-- | ishtar_common/forms.py | 14 |
1 files changed, 13 insertions, 1 deletions
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): |