summaryrefslogtreecommitdiff
path: root/ishtar_common/widgets.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r--ishtar_common/widgets.py58
1 files changed, 34 insertions, 24 deletions
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"<div class='input-group'>"
- 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 = """
- <span class="input-group-append">
- <a href="#" class="add-button input-group-text"
- onclick="dt_qa_open('{}', 'modal-dynamic-form-{}');">+</a>
- </span></div>
- """.format(url_new, model_name, model_name)
+ if self.tips or self.new:
+ html = "<div class='input-group'>"
+ if self.tips:
+ new = """<span class="input-group-append">
+ <span class="add-button input-group-text"><em>{}</em></span></span>
+ """.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 += """
+ <span class="input-group-append">
+ <a href="#" class="add-button input-group-text"
+ onclick="dt_qa_open('{}', 'modal-dynamic-form-{}');">+</a>
+ </span>
+ """.format(url_new, model_name, model_name)
+ new += "</div>"
old_value = ""
if 'value' in attrs_select and attrs_select['value']: