mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #3114 -- newforms MultipleChoiceField now handles MultiValueDicts properly. Thanks for the patch, Honza Král
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4196 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Form classes
|
||||
"""
|
||||
|
||||
from django.utils.datastructures import SortedDict
|
||||
from django.utils.datastructures import SortedDict, MultiValueDict
|
||||
from django.utils.html import escape
|
||||
from fields import Field
|
||||
from widgets import TextInput, Textarea, HiddenInput
|
||||
@@ -221,6 +221,8 @@ class BoundField(StrAndUnicode):
|
||||
|
||||
def _data(self):
|
||||
"Returns the data for this BoundField, or None if it wasn't given."
|
||||
if self.field.widget.requires_data_list and isinstance(self.form.data, MultiValueDict):
|
||||
return self.form.data.getlist(self.name)
|
||||
return self.form.data.get(self.name, None)
|
||||
data = property(_data)
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ __all__ = (
|
||||
)
|
||||
|
||||
from util import StrAndUnicode, smart_unicode
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.html import escape
|
||||
from itertools import chain
|
||||
|
||||
@@ -64,6 +65,7 @@ class Input(Widget):
|
||||
type='radio', which are special).
|
||||
"""
|
||||
input_type = None # Subclasses must define this.
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
if value is None: value = ''
|
||||
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
|
||||
@@ -146,6 +148,11 @@ class SelectMultiple(Widget):
|
||||
output.append(u'</select>')
|
||||
return u'\n'.join(output)
|
||||
|
||||
def value_from_datadict(self, data, name):
|
||||
if isinstance(data, MultiValueDict):
|
||||
return data.getlist(name)
|
||||
return data.get(name, None)
|
||||
|
||||
class RadioInput(StrAndUnicode):
|
||||
"An object used by RadioFieldRenderer that represents a single <input type='radio'>."
|
||||
def __init__(self, name, value, attrs, choice, index):
|
||||
|
||||
Reference in New Issue
Block a user