Commits

Karen Tracey committed 1e86b48

Add abilility to influence callback url for lookup dynamically.

Comments (0)

Files changed (1)

selectable/forms/widgets.py

 from django import forms
 from django.conf import settings
 from django.forms.util import flatatt
+from django.utils.http import urlencode
 from django.utils.encoding import force_unicode
 from django.utils.safestring import mark_safe
 
     def __init__(self, lookup_class, *args, **kwargs):
         self.lookup_class = lookup_class
         self.allow_new = kwargs.pop('allow_new', False)
+        self.qs = {}
         super(AutoCompleteWidget, self).__init__(*args, **kwargs)
 
+    def update_query_parameters(self, qs_dict):
+        self.qs.update(qs_dict)
+
     def build_attrs(self, extra_attrs=None, **kwargs):
         attrs = super(AutoCompleteWidget, self).build_attrs(extra_attrs, **kwargs)
-        attrs[u'data-selectable-url'] = self.lookup_class.url()
+        url = self.lookup_class.url()
+        if self.qs:
+            url = '%s?%s' % (url, urlencode(self.qs))
+        attrs[u'data-selectable-url'] = url
         attrs[u'data-selectable-type'] = 'text'
         attrs[u'data-selectable-allow-new'] = str(self.allow_new).lower()
         return attrs
         ]
         super(AutoCompleteSelectWidget, self).__init__(widgets, *args, **kwargs)
 
+    def update_query_parameters(self, qs_dict):
+        self.widgets[0].update_query_parameters(qs_dict)
+
     def decompress(self, value):
         if value:
             lookup = self.lookup_class()
         ]
         super(AutoComboboxSelectWidget, self).__init__(widgets, *args, **kwargs)
 
+    def update_query_parameters(self, qs_dict):
+        self.widgets[0].update_query_parameters(qs_dict)
+
     def decompress(self, value):
         if value:
             lookup = self.lookup_class()
         ]
         super(AutoCompleteSelectMultipleWidget, self).__init__(widgets, *args, **kwargs)
 
+    def update_query_parameters(self, qs_dict):
+        self.widgets[0].update_query_parameters(qs_dict)
+
     def decompress(self, value):
         if value:
             if not hasattr(value, '__iter__'):
         ]
         super(AutoComboboxSelectMultipleWidget, self).__init__(widgets, *args, **kwargs)
 
+    def update_query_parameters(self, qs_dict):
+        self.widgets[0].update_query_parameters(qs_dict)
+
     def decompress(self, value):
         if value:
             if not hasattr(value, '__iter__'):