From a6d77a3a3358463c591900872a8ae62286f9509d Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 13 Feb 2019 12:08:57 +0100 Subject: Search form: manage field ordering and custom fields --- ishtar_common/forms.py | 8 ++++++++ ishtar_common/templates/blocks/bs_field_snippet.html | 5 +++-- ishtar_common/widgets.py | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'ishtar_common') diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 93c6cd8ed..754f63f74 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -164,6 +164,7 @@ class CustomForm(BSForm): form_admin_name = "" form_slug = "" need_user_for_initialization = True + _explicit_ordering = False # explicit call to field ordering def __init__(self, *args, **kwargs): self.current_user = None @@ -173,6 +174,10 @@ class CustomForm(BSForm): except AttributeError: pass super(CustomForm, self).__init__(*args, **kwargs) + if not self._explicit_ordering: + self.custom_form_ordering() + + def custom_form_ordering(self): available, excluded, json_fields = self.check_custom_form( self.current_user) for exc in excluded: @@ -288,6 +293,7 @@ class CustomForm(BSForm): if 'class' in f.widget.attrs: kls = f.widget.attrs['class'] + " " + kls f.widget.attrs['class'] = kls + f.alt_name = slugify(attrs['label']) fields.append((field.order or 1, key, f)) return fields @@ -607,6 +613,7 @@ class HistorySelect(CustomForm, TableSelect): modified_since = forms.DateField( label=_(u"Modified since"), widget=DatePicker, required=False) + _explicit_ordering = True def __init__(self, *args, **kwargs): super(HistorySelect, self).__init__(*args, **kwargs) @@ -620,6 +627,7 @@ class HistorySelect(CustomForm, TableSelect): for k in current_fields: fields[k] = self.fields[k] self.fields = fields + self.custom_form_ordering() def get_now(): diff --git a/ishtar_common/templates/blocks/bs_field_snippet.html b/ishtar_common/templates/blocks/bs_field_snippet.html index f46b15209..bbcc31597 100644 --- a/ishtar_common/templates/blocks/bs_field_snippet.html +++ b/ishtar_common/templates/blocks/bs_field_snippet.html @@ -2,9 +2,10 @@
{% if field.label %}{{ field.label_tag }}{% endif %} - {% if show_field_number and field.field.order_number %} + {% if show_field_number or form.show_field_number %} + {% if field.field.order_number %} {{field.field.order_number}} - {% endif %} + {% endif %}{% endif %} {% if field.help_text %}
{% endif %} diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index cb9250b9c..a1d9aeec6 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -1055,6 +1055,9 @@ class DataTable(Select2Media, forms.RadioSelect): t = loader.get_template('blocks/bs_form_snippet.html') if self.user: form = self.form(user=self.user) + if self.user.ishtaruser and \ + self.user.ishtaruser.show_field_number(): + form.show_field_number = True else: form = self.form() rendered = t.render({'form': form, 'search': True}) -- cgit v1.2.3