Ticket #3114: multiple_choice.patch
File multiple_choice.patch, 2.6 KB (added by , 18 years ago) |
---|
-
django/newforms/fields.py
277 277 val = smart_unicode(val) 278 278 new_value.append(val) 279 279 # Validate that each value in the value list is in self.choices. 280 valid_values = set([ kfor k, v in self.choices])280 valid_values = set([smart_unicode(k) for k, v in self.choices]) 281 281 for val in new_value: 282 282 if val not in valid_values: 283 283 raise ValidationError(gettext(u'Select a valid choice. %s is not one of the available choices.') % val) -
django/newforms/forms.py
2 2 Form classes 3 3 """ 4 4 5 from django.utils.datastructures import SortedDict 5 from django.utils.datastructures import SortedDict, MultiValueDict 6 6 from django.utils.html import escape 7 7 from fields import Field 8 8 from widgets import TextInput, Textarea, HiddenInput … … 38 38 39 39 def __init__(self, data=None, auto_id=False): # TODO: prefix stuff 40 40 self.ignore_errors = data is None 41 self.data = data or {}41 self.data = data or MultiValueDict() 42 42 self.auto_id = auto_id 43 43 self.clean_data = None # Stores the data after clean() has been called. 44 44 self.__errors = None # Stores the errors after clean() has been called. … … 210 210 211 211 def _data(self): 212 212 "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) 213 215 return self.form.data.get(self.name, None) 214 216 data = property(_data) 215 217 -
django/newforms/widgets.py
10 10 11 11 from util import StrAndUnicode, smart_unicode 12 12 from django.utils.html import escape 13 from django.utils.datastructures import MultiValueDict 14 13 15 from itertools import chain 14 16 15 17 try: … … 43 45 Given a dictionary of data and this widget's name, returns the value 44 46 of this widget. Returns None if it's not provided. 45 47 """ 48 if isinstance(data, MultiValueDict) and self.requires_data_list: 49 return data.getlist(name) 46 50 return data.get(name, None) 47 51 48 52 def id_for_label(self, id_):