Ticket #3114: multiple_choice.patch

File multiple_choice.patch, 2.6 KB (added by Honza Král <Honza.Kral@…>, 18 years ago)

patch to correct the behaviour

  • django/newforms/fields.py

     
    277277            val = smart_unicode(val)
    278278            new_value.append(val)
    279279        # Validate that each value in the value list is in self.choices.
    280         valid_values = set([k for k, v in self.choices])
     280        valid_values = set([smart_unicode(k) for k, v in self.choices])
    281281        for val in new_value:
    282282            if val not in valid_values:
    283283                raise ValidationError(gettext(u'Select a valid choice. %s is not one of the available choices.') % val)
  • django/newforms/forms.py

     
    22Form classes
    33"""
    44
    5 from django.utils.datastructures import SortedDict
     5from django.utils.datastructures import SortedDict, MultiValueDict
    66from django.utils.html import escape
    77from fields import Field
    88from widgets import TextInput, Textarea, HiddenInput
     
    3838
    3939    def __init__(self, data=None, auto_id=False): # TODO: prefix stuff
    4040        self.ignore_errors = data is None
    41         self.data = data or {}
     41        self.data = data or MultiValueDict()
    4242        self.auto_id = auto_id
    4343        self.clean_data = None # Stores the data after clean() has been called.
    4444        self.__errors = None # Stores the errors after clean() has been called.
     
    210210
    211211    def _data(self):
    212212        "Returns the data for this BoundField, or None if it wasn't given."
     213        if isinstance(self.form.data, MultiValueDict) and self.field.widget.requires_data_list:
     214            return self.form.data.getlist(self.name)
    213215        return self.form.data.get(self.name, None)
    214216    data = property(_data)
    215217
  • django/newforms/widgets.py

     
    1010
    1111from util import StrAndUnicode, smart_unicode
    1212from django.utils.html import escape
     13from django.utils.datastructures import MultiValueDict
     14
    1315from itertools import chain
    1416
    1517try:
     
    4345        Given a dictionary of data and this widget's name, returns the value
    4446        of this widget. Returns None if it's not provided.
    4547        """
     48        if isinstance(data, MultiValueDict) and self.requires_data_list:
     49            return data.getlist(name)
    4650        return data.get(name, None)
    4751
    4852    def id_for_label(self, id_):
Back to Top