Commits

Mark Lavin committed 65c127a

Condensed update_query_parameters and added tests.

Comments (0)

Files changed (2)

selectable/forms/widgets.py

         return attrs
 
 
-class AutoCompleteSelectWidget(forms.MultiWidget, SelectableMediaMixin):
+class SelectableMultiWidget(forms.MultiWidget):
+
+    def update_query_parameters(self, qs_dict):
+        self.widgets[0].update_query_parameters(qs_dict)
+
+
+class AutoCompleteSelectWidget(SelectableMultiWidget, SelectableMediaMixin):
 
     def __init__(self, lookup_class, *args, **kwargs):
         self.lookup_class = lookup_class
         ]
         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()
         return attrs
 
 
-class AutoComboboxSelectWidget(forms.MultiWidget, SelectableMediaMixin):
+class AutoComboboxSelectWidget(SelectableMultiWidget, SelectableMediaMixin):
 
     def __init__(self, lookup_class, *args, **kwargs):
         self.lookup_class = 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()
         return attrs
 
 
-class AutoCompleteSelectMultipleWidget(forms.MultiWidget, SelectableMediaMixin):
+class AutoCompleteSelectMultipleWidget(SelectableMultiWidget, SelectableMediaMixin):
 
     def __init__(self, lookup_class, *args, **kwargs):
         self.lookup_class = 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 and isinstance(value, list) and len(value) == 2 and isinstance(value[1], list):
             return value
         return super(AutoCompleteSelectMultipleWidget, self).render(name, value, attrs)
 
 
-class AutoComboboxSelectMultipleWidget(forms.MultiWidget, SelectableMediaMixin):
+class AutoComboboxSelectMultipleWidget(SelectableMultiWidget, SelectableMediaMixin):
 
     def __init__(self, lookup_class, *args, **kwargs):
         self.lookup_class = lookup_class
         ]
         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 and isinstance(value, list) and len(value) == 2 and isinstance(value[1], list):
             return value

selectable/tests/widgets.py

+from urlparse import urlparse
+
 from django import forms
+from django.utils.http import urlencode
 
 from selectable.forms import widgets
 from selectable.tests import Thing, ThingLookup
         self.assertTrue('data-selectable-type' in attrs)
         self.assertTrue('data-selectable-allow-new' in attrs)
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        attrs = widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
+
 
 class AutoCompleteSelectWidgetTestCase(BaseWidgetTestCase):
     widget_cls = widgets.AutoCompleteSelectWidget
         self.assertTrue('data-selectable-type' in attrs)
         self.assertEqual(attrs['data-selectable-type'], 'hidden')
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        sub_widget = widget.widgets[0]
+        attrs = sub_widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
+
 
 class AutoComboboxWidgetTestCase(BaseWidgetTestCase):
     widget_cls = widgets.AutoComboboxWidget
         self.assertTrue('data-selectable-type' in attrs)
         self.assertTrue('data-selectable-allow-new' in attrs)
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        attrs = widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
+
 
 class AutoComboboxSelectWidgetTestCase(BaseWidgetTestCase):
     widget_cls = widgets.AutoComboboxSelectWidget
         self.assertTrue('data-selectable-type' in attrs)
         self.assertEqual(attrs['data-selectable-type'], 'hidden')
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        sub_widget = widget.widgets[0]
+        attrs = sub_widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
+
 
 class AutoCompleteSelectMultipleWidgetTestCase(BaseWidgetTestCase):
     widget_cls = widgets.AutoCompleteSelectMultipleWidget
             self.assertTrue(ev in rendered_value,
                 "Did not find:\n\t%s\nin rendered value:\n\t%s" % (ev, rendered_value))
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        sub_widget = widget.widgets[0]
+        attrs = sub_widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
+
+
 class AutoComboboxSelectMultipleWidgetTestCase(BaseWidgetTestCase):
     widget_cls = widgets.AutoComboboxSelectMultipleWidget
     lookup_cls = ThingLookup
             self.assertTrue(ev in rendered_value,
                 "Did not find:\n\t%s\nin rendered value:\n\t%s" % (ev, rendered_value))
 
+    def test_update_query_parameters(self):
+        params = {'active': 1} 
+        widget = self.get_widget_instance()
+        widget.update_query_parameters(params)
+        sub_widget = widget.widgets[0]
+        attrs = sub_widget.build_attrs()
+        url = attrs['data-selectable-url']
+        parse = urlparse(url)
+        query = parse.query
+        self.assertEqual(query, urlencode(params))
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.