From e50e6712077a7b4911672088838e203db41ffb80 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 26 May 2014 20:54:16 +0200 Subject: Contextual filter on fields for new items window (refs #1715) --- ishtar_common/widgets.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'ishtar_common/widgets.py') diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py index 2105b73e3..71d88d062 100644 --- a/ishtar_common/widgets.py +++ b/ishtar_common/widgets.py @@ -134,7 +134,7 @@ class JQueryDate(forms.TextInput): class JQueryAutoComplete(forms.TextInput): def __init__(self, source, associated_model=None, options={}, attrs={}, - new=False, multiple=False): + new=False, multiple=False, limit={}): """ Source can be a list containing the autocomplete values or a string containing the url used for the request. @@ -148,6 +148,7 @@ class JQueryAutoComplete(forms.TextInput): self.attrs.update(attrs) self.new = new self.multiple = multiple + self.limit = limit def value_from_datadict(self, data, files, name): if self.multiple: @@ -222,7 +223,14 @@ class JQueryAutoComplete(forms.TextInput): new = '' if self.new: model_name = self.associated_model._meta.object_name.lower() - url_new = reverse('new-' + model_name, args=[attrs_select['id']]) + limits = [] + for k in self.limit: + limits.append(k + "__" + "-".join( + [unicode(v) for v in self.limit[k]])) + args = [attrs_select['id']] + if limits: + args.append(';'.join(limits)) + url_new = reverse('new-' + model_name, args=args) new = u' +' % url_new html = u'''%(new)s\ -- cgit v1.2.3