summaryrefslogtreecommitdiff
path: root/ishtar_common/widgets.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2014-05-26 20:54:16 +0200
committerÉtienne Loks <etienne.loks@proxience.com>2014-05-26 20:54:16 +0200
commite50e6712077a7b4911672088838e203db41ffb80 (patch)
tree1e5f1f46e640673d701d74d7783335c4bb795b53 /ishtar_common/widgets.py
parent01d3cdaacabcdca55bd08d67df5339ea5bfa92d7 (diff)
downloadIshtar-e50e6712077a7b4911672088838e203db41ffb80.tar.bz2
Ishtar-e50e6712077a7b4911672088838e203db41ffb80.zip
Contextual filter on fields for new items window (refs #1715)
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r--ishtar_common/widgets.py12
1 files changed, 10 insertions, 2 deletions
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' <a href="#" class="add-button" '\
u'onclick="open_window(\'%s\');">+</a>' % url_new
html = u'''<input%(attrs_select)s/>%(new)s\