summaryrefslogtreecommitdiff
path: root/ishtar_common/forms.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-11-07 16:46:06 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-11-07 16:48:28 +0100
commit83f352f37c8f034ebeca188a9716aafec765dfdf (patch)
tree4111e2ce659862f80df395113f5669da24270430 /ishtar_common/forms.py
parentc110e2c12168e635f3ce078727d69cf90a343222 (diff)
downloadIshtar-83f352f37c8f034ebeca188a9716aafec765dfdf.tar.bz2
Ishtar-83f352f37c8f034ebeca188a9716aafec765dfdf.zip
Fix JSON date field init on forms
Diffstat (limited to 'ishtar_common/forms.py')
-rw-r--r--ishtar_common/forms.py49
1 files changed, 31 insertions, 18 deletions
diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py
index 26da204fd..20c65971e 100644
--- a/ishtar_common/forms.py
+++ b/ishtar_common/forms.py
@@ -122,7 +122,33 @@ JSON_VALUE_TYPES_FIELDS = {
}
-class CustomForm(object):
+class BSForm(object):
+ def _post_init(self):
+ for k in self.fields:
+ # manage bs decoration
+ if not hasattr(self.fields[k].widget, 'NO_FORM_CONTROL'):
+ cls = 'form-control'
+ if 'class' in self.fields[k].widget.attrs:
+ if 'form-control' in self.fields[k].widget.attrs['class']:
+ cls = self.fields[k].widget.attrs['class']
+ else:
+ cls = self.fields[k].widget.attrs['class'] + " " + cls
+ self.fields[k].widget.attrs['class'] = cls
+
+ # manage datepicker
+ widget = self.fields[k].widget
+ if not isinstance(widget, DatePicker):
+ continue
+ lang = translation.get_language()
+ widget.options['language'] = lang
+ if lang in DATE_FORMAT:
+ widget.options['format'] = DATE_FORMAT[lang]
+ if 'autoclose' not in widget.options:
+ widget.options['autoclose'] = 'true'
+ widget.options['todayHighlight'] = 'true'
+
+
+class CustomForm(BSForm):
form_admin_name = ""
form_slug = ""
need_user_for_initialization = True
@@ -192,6 +218,8 @@ class CustomForm(object):
self.fields = fields
+ self._post_init()
+
def are_available(self, keys):
for k in keys:
if k not in self.fields:
@@ -447,7 +475,7 @@ class FormHeader(object):
</div>""")
-class IshtarForm(forms.Form):
+class IshtarForm(forms.Form, BSForm):
TYPES = [] # FieldType list
PROFILE_FILTER = {} # profile key associated to field list
HEADERS = {} # field key associated to FormHeader instance
@@ -464,22 +492,7 @@ class IshtarForm(forms.Form):
return
for field in self.TYPES:
self._init_type(field)
- for k in self.fields:
- if not hasattr(self.fields[k].widget, 'NO_FORM_CONTROL'):
- cls = 'form-control'
- if 'class' in self.fields[k].widget.attrs:
- cls = self.fields[k].widget.attrs['class'] + " " + cls
- self.fields[k].widget.attrs['class'] = cls
- widget = self.fields[k].widget
- if not isinstance(widget, DatePicker):
- continue
- lang = translation.get_language()
- widget.options['language'] = lang
- if lang in DATE_FORMAT:
- widget.options['format'] = DATE_FORMAT[lang]
- if 'autoclose' not in widget.options:
- widget.options['autoclose'] = 'true'
- widget.options['todayHighlight'] = 'true'
+ self._post_init()
def _init_type(self, field):
if field.key not in self.fields: