Ticket #7195: mergedict.diff
File mergedict.diff, 2.2 KB (added by , 17 years ago) |
---|
-
django/newforms/widgets.py
10 10 import copy 11 11 from itertools import chain 12 12 13 from django.utils.datastructures import MultiValueDict 13 from django.utils.datastructures import MultiValueDict, MergeDict 14 14 from django.utils.html import escape, conditional_escape 15 15 from django.utils.translation import ugettext 16 16 from django.utils.encoding import StrAndUnicode, force_unicode … … 128 128 for v in value])) 129 129 130 130 def value_from_datadict(self, data, files, name): 131 if isinstance(data, MultiValueDict) :131 if isinstance(data, MultiValueDict) or isinstance(data, MergeDict): 132 132 return data.getlist(name) 133 133 return data.get(name, None) 134 134 … … 263 263 return mark_safe(u'\n'.join(output)) 264 264 265 265 def value_from_datadict(self, data, files, name): 266 if isinstance(data, MultiValueDict) :266 if isinstance(data, MultiValueDict) or isinstance(data, MergeDict): 267 267 return data.getlist(name) 268 268 return data.get(name, None) 269 269 -
tests/regressiontests/forms/forms.py
539 539 <li><label><input type="checkbox" name="composers" value="P" id="composers_id_1" /> Paul McCartney</label></li> 540 540 </ul> 541 541 542 Data for a MultipleChoiceField should be a list. QueryDict and MultiValueDict543 conveniently work with this.542 Data for a MultipleChoiceField should be a list. QueryDict, MultiValueDict and 543 MergeDict conveniently work with this. 544 544 >>> data = {'name': 'Yesterday', 'composers': ['J', 'P']} 545 545 >>> f = SongForm(data) 546 546 >>> f.errors … … 555 555 >>> f = SongForm(data) 556 556 >>> f.errors 557 557 {} 558 >>> from django.utils.datastructures import MergeDict 559 >>> data = MergeDict(MultiValueDict(dict(name=['Yesterday'], composers=['J', 'P']))) 560 >>> f = SongForm(data) 561 >>> f.errors 562 {} 558 563 559 564 The MultipleHiddenInput widget renders multiple values as hidden fields. 560 565 >>> class SongFormHidden(Form):