summaryrefslogtreecommitdiff
path: root/ishtar_common/widgets.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@proxience.com>2015-02-03 00:49:58 +0100
committerÉtienne Loks <etienne.loks@proxience.com>2015-02-03 00:49:58 +0100
commit5d3e9a1435a575dd27695e3c0ff0e6282acc0c0f (patch)
tree9afd7c785b7c1fa04abcf1b2a2d5a477f85e9e48 /ishtar_common/widgets.py
parentb3e9441a212d033a3282dd63e1fa336e8abd60ce (diff)
downloadIshtar-5d3e9a1435a575dd27695e3c0ff0e6282acc0c0f.tar.bz2
Ishtar-5d3e9a1435a575dd27695e3c0ff0e6282acc0c0f.zip
Implement Select2 selection as a multi select widget
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r--ishtar_common/widgets.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index 404d5fabe..0ba4061a8 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -37,6 +37,24 @@ import models
reverse_lazy = lazy(reverse, unicode)
+
+class Select2Multiple(forms.SelectMultiple):
+ class Media:
+ css = {
+ 'all': ('select2/css/select2.css',)
+ }
+ js = ('select2/js/select2.min.js',
+ 'select2/js/init.js')
+
+ def render(self, name, value, attrs=None, choices=()):
+ klass = attrs and attrs.get('class') or ''
+ klass += ' ' if klass else '' + 'js-select2'
+ if not attrs:
+ attrs = {}
+ attrs['class'] = klass
+ return super(Select2Multiple, self).render(name, value, attrs,
+ choices)
+
class MultipleAutocompleteField(forms.MultipleChoiceField):
def __init__(self, *args, **kwargs):
self.model = None