From 17dc2e0fe41229687149f44ca7f84be3cfe55a85 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Wed, 18 Mar 2020 16:57:51 +0100 Subject: Autocomplete widget: add "tips" message on autocomplete field --- .../ishtar/wizard/wizard_preventiveplanning.html | 116 --------------------- ishtar_common/widgets.py | 58 ++++++----- 2 files changed, 34 insertions(+), 140 deletions(-) delete mode 100644 archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html diff --git a/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html b/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html deleted file mode 100644 index 95e8e8841..000000000 --- a/archaeological_files_pdl/templates/ishtar/wizard/wizard_preventiveplanning.html +++ /dev/null @@ -1,116 +0,0 @@ -{% extends "ishtar/wizard/default_wizard.html" %} -{% load i18n range table_form %} -{% block wizard_form %} -
{% csrf_token %} -
-{{ wizard.form.media }} -{{ wizard.management_form }} - - - -{% if wizard.form.name.errors %} - -{% endif %} - - - - - - - - -
{{wizard.form.name.errors}}
{{wizard.form.name|safe}}
- -

Localisation

- - -{% if wizard.form.main_town.errors %} - -{% endif %} - - - - - - - -{% if wizard.form.department.errors %} - -{% endif %} - - - - - - - -{% if wizard.form.locality.errors %} - -{% endif %} - - - - - - - -{% if wizard.form.address.errors %} - -{% endif %} - - - - - - - -{% if wizard.form.postal_code.errors %} - -{% endif %} - - - - - - - -
{{wizard.form.main_town.errors}}
{{wizard.form.town|safe}}
{{wizard.form.department.errors}}
{{wizard.form.department|safe}}
{{wizard.form.locality.errors}}
{{wizard.form.locality|safe}}
{{wizard.form.address.errors}}
{{wizard.form.address|safe}}
{{wizard.form.postal_code.errors}}
{{wizard.form.postal_code|safe}}
- -

Surfaces

- - -{% if wizard.form.total_surface.errors %} - -{% endif %} - - - - - - - -{% if wizard.form.total_developed_surface.errors %} - -{% endif %} - - - - - - - -
{{wizard.form.total_surface.errors}}
{{wizard.form.total_surface|safe}}
{{wizard.form.total_developed_surface.errors}}
{{wizard.form.total_developed_surface|safe}}
- - -{{ previous_fields|safe }} - {% block "footer" %} - - {% endblock %} -
-
-{% endblock %} diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index d75769ffa..bf0f90a6c 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -599,13 +599,17 @@ class ModelJQueryAutocompleteField(ModelFieldMixin, forms.CharField): class JQueryAutoComplete(forms.TextInput): def __init__(self, source, associated_model=None, options=None, attrs=None, new=False, url_new='', multiple=False, limit=None, - dynamic_limit=None): + dynamic_limit=None, tips=""): """ Source can be a list containing the autocomplete values or a string containing the url used for the request. """ self.source = source self.associated_model = associated_model + if callable(tips): + self.tips = tips() + else: + self.tips = tips self.options = None if options and len(options) > 0: @@ -702,29 +706,35 @@ class JQueryAutoComplete(forms.TextInput): attrs_select['class'] += ' form-control' new = '' html = u"" - if self.new: - # WARNING: the modal for the form must be in the main template - # "extra_form_modals" list is used for that in form or view - - html = u"
" - model_name = self.associated_model._meta.object_name.lower() - limits = [] - for k in self.limit: - limits.append(k + "__" + "-".join( - [str(v) for v in self.limit[k]])) - args = [attrs_select['id']] - if limits: - args.append(';'.join(limits)) - url_new = 'new-' + model_name - if self.url_new: - url_new = self.url_new - url_new = reverse(url_new, args=args) - new = """ - - + -
- """.format(url_new, model_name, model_name) + if self.tips or self.new: + html = "
" + if self.tips: + new = """ + {} + """.format(self.tips) + if self.new: + # WARNING: the modal for the form must be in the main template + # "extra_form_modals" list is used for that in form or view + + model_name = self.associated_model._meta.object_name.lower() + limits = [] + for k in self.limit: + limits.append(k + "__" + "-".join( + [str(v) for v in self.limit[k]])) + args = [attrs_select['id']] + if limits: + args.append(';'.join(limits)) + url_new = 'new-' + model_name + if self.url_new: + url_new = self.url_new + url_new = reverse(url_new, args=args) + new += """ + + + + + """.format(url_new, model_name, model_name) + new += "
" old_value = "" if 'value' in attrs_select and attrs_select['value']: -- cgit v1.2.3