Changeset 4196
- Timestamp:
- 12/13/06 00:26:04 (2 years ago)
- Files:
-
- django/trunk/django/newforms/forms.py (modified) (2 diffs)
- django/trunk/django/newforms/widgets.py (modified) (3 diffs)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/forms.py
r4194 r4196 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 … … 222 222 def _data(self): 223 223 "Returns the data for this BoundField, or None if it wasn't given." 224 if self.field.widget.requires_data_list and isinstance(self.form.data, MultiValueDict): 225 return self.form.data.getlist(self.name) 224 226 return self.form.data.get(self.name, None) 225 227 data = property(_data) django/trunk/django/newforms/widgets.py
r4163 r4196 10 10 11 11 from util import StrAndUnicode, smart_unicode 12 from django.utils.datastructures import MultiValueDict 12 13 from django.utils.html import escape 13 14 from itertools import chain … … 65 66 """ 66 67 input_type = None # Subclasses must define this. 68 67 69 def render(self, name, value, attrs=None): 68 70 if value is None: value = '' … … 147 149 return u'\n'.join(output) 148 150 151 def value_from_datadict(self, data, name): 152 if isinstance(data, MultiValueDict): 153 return data.getlist(name) 154 return data.get(name, None) 155 149 156 class RadioInput(StrAndUnicode): 150 157 "An object used by RadioFieldRenderer that represents a single <input type='radio'>." django/trunk/tests/regressiontests/forms/tests.py
r4194 r4196 1672 1672 <li><label><input checked="checked" type="checkbox" name="composers" value="P" /> Paul McCartney</label></li> 1673 1673 </ul> 1674 1675 Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict 1676 conveniently work with this. 1677 >>> data = {'name': 'Yesterday', 'composers': ['J', 'P']} 1678 >>> f = SongForm(data) 1679 >>> f.errors 1680 {} 1681 >>> from django.http import QueryDict 1682 >>> data = QueryDict('name=Yesterday&composers=J&composers=P') 1683 >>> f = SongForm(data) 1684 >>> f.errors 1685 {} 1686 >>> from django.utils.datastructures import MultiValueDict 1687 >>> data = MultiValueDict(dict(name='Yesterday', composers=['J', 'P'])) 1688 >>> f = SongForm(data) 1689 >>> f.errors 1690 {} 1674 1691 1675 1692 When using CheckboxSelectMultiple, the framework expects a list of input and
