diff options
| -rw-r--r-- | archaeological_finds/forms.py | 10 | ||||
| -rw-r--r-- | ishtar_common/forms.py | 4 | ||||
| -rw-r--r-- | ishtar_common/widgets.py | 17 | 
3 files changed, 23 insertions, 8 deletions
| diff --git a/archaeological_finds/forms.py b/archaeological_finds/forms.py index a37d6b5f6..3fc8d7c01 100644 --- a/archaeological_finds/forms.py +++ b/archaeological_finds/forms.py @@ -117,13 +117,13 @@ class FindForm(ManageOldType, forms.Form):          model=models.ObjectType, label=_(u"Object types"), required=False)      preservation_to_consider = forms.MultipleChoiceField(          label=_(u"Preservation type"), choices=[], -        widget=forms.CheckboxSelectMultiple, required=False) +        widget=widgets.CheckboxSelectMultiple, required=False)      integritie = forms.MultipleChoiceField(          label=_(u"Integrity / interest"), choices=[], -        widget=forms.CheckboxSelectMultiple, required=False) +        widget=widgets.CheckboxSelectMultiple, required=False)      remarkabilitie = forms.MultipleChoiceField(          label=_(u"Remarkability"), choices=[], -        widget=forms.CheckboxSelectMultiple, required=False) +        widget=widgets.CheckboxSelectMultiple, required=False)      topographic_reference_point = forms.CharField(          label=_(u"Point of topographic reference"),          required=False, max_length=20 @@ -246,7 +246,7 @@ class FindSelect(TableSelect):          validators=[valid_id(ArchaeologicalSite)])      ope_relation_types = forms.MultipleChoiceField(          label=_(u"Search within related operations"), choices=[], -        widget=forms.CheckboxSelectMultiple) +        widget=widgets.CheckboxSelectMultiple)      datings__period = forms.ChoiceField(label=_(u"Period"), choices=[])      # TODO search by warehouse      material_types = forms.ChoiceField(label=_(u"Material type"), choices=[]) @@ -654,7 +654,7 @@ class BaseTreatmentForm(ManageOldType, forms.Form):                                            validators.MaxValueValidator(2100)])      treatment_type = forms.MultipleChoiceField(          label=_(u"Treatment type"), choices=[], -        widget=forms.CheckboxSelectMultiple) +        widget=widgets.CheckboxSelectMultiple)      target_is_basket = forms.NullBooleanField(label=_(u"Target"))      person = forms.IntegerField(          label=_(u"Responsible"), diff --git a/ishtar_common/forms.py b/ishtar_common/forms.py index 043b03f61..42d74f9ef 100644 --- a/ishtar_common/forms.py +++ b/ishtar_common/forms.py @@ -33,6 +33,7 @@ from django.utils.translation import ugettext_lazy as _  import models  import widgets +from wizards import MultiValueDict  # from formwizard.forms import NamedUrlSessionFormWizard @@ -224,7 +225,6 @@ class ManageOldType(object):                  if prefix not in k:                      continue                  new_k = k[len(prefix) + 1:] -                items = []                  if hasattr(kwargs['data'], 'getlist'):                      items = kwargs['data'].getlist(k)                  else: @@ -238,7 +238,6 @@ class ManageOldType(object):          if 'initial' in kwargs and kwargs['initial']:              for k in kwargs['initial']:                  if k not in self.init_data or not self.init_data[k]: -                    items = []                      if hasattr(kwargs['initial'], 'getlist'):                          items = kwargs['initial'].getlist(k)                      else: @@ -249,6 +248,7 @@ class ManageOldType(object):                          if k not in self.init_data:                              self.init_data[k] = []                          self.init_data[k].append(val) +        self.init_data = MultiValueDict(self.init_data)          super(ManageOldType, self).__init__(*args, **kwargs) 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): | 
