summaryrefslogtreecommitdiff
path: root/ishtar_common/widgets.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-05 18:11:39 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2016-12-05 18:11:39 +0100
commitfcf63a61bdcab906aad45c69eb95167850e2c40a (patch)
tree130e1e4178642d87e5337d9473f975a14611d3ff /ishtar_common/widgets.py
parent9de3367a92a1f22bdd843e578b134cd39aa4c8fa (diff)
downloadIshtar-fcf63a61bdcab906aad45c69eb95167850e2c40a.tar.bz2
Ishtar-fcf63a61bdcab906aad45c69eb95167850e2c40a.zip
Fix bad initialization of multiple checkbox field
Diffstat (limited to 'ishtar_common/widgets.py')
-rw-r--r--ishtar_common/widgets.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/ishtar_common/widgets.py b/ishtar_common/widgets.py
index e21ce7a2a..7696d67da 100644
--- a/ishtar_common/widgets.py
+++ b/ishtar_common/widgets.py
@@ -24,7 +24,8 @@ from django.conf import settings
from django.core.urlresolvers import reverse
from django.db.models import fields
from django.forms import ClearableFileInput
-from django.forms.widgets import flatatt
+from django.forms.widgets import flatatt, \
+ CheckboxSelectMultiple as CheckboxSelectMultipleBase
from django.template import Context, loader
from django.template.defaultfilters import slugify
from django.utils.encoding import smart_unicode
@@ -56,6 +57,20 @@ class Select2Multiple(forms.SelectMultiple):
return super(Select2Multiple, self).render(name, value, attrs,
choices)
+class CheckboxSelectMultiple(CheckboxSelectMultipleBase):
+ """
+ Fix initialization bug.
+ Should be corrected on recent Django version.
+ TODO: test and remove (test case: treatment type not keep on modif)
+ """
+ def render(self, name, value, attrs=None, choices=()):
+ if type(value) in (str, unicode):
+ value = value.split(',')
+ if type(value) not in (list, tuple):
+ value = [value]
+ return super(CheckboxSelectMultiple, self).render(name, value, attrs,
+ choices)
+
class MultipleAutocompleteField(forms.MultipleChoiceField):
def __init__(self, *args, **kwargs):