diff options
| -rw-r--r-- | ishtar_common/forms.py | 49 | 
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: | 
