Fix multiple value bug in html.parse_html_dict()

It is possible that a key in a MultiValueDict has multiple values, lists
are represented this way. When accessing a key in a MultiValueDict
it only returns the last element of that key. This becomes a problem
when parsing an html dict with a list inside of it.

To fix this problem we have to get and set the value using .getlist()
and .setlist().

This commit solves a bug that caused a list in a nested serializer to
not being properly parsed if it was sent as multipart formated data.
This commit is contained in:
Laurent De Marez 2016-01-11 11:05:08 +01:00
parent 877ed6edc2
commit 163a579c2f

View File

@ -80,10 +80,12 @@ def parse_html_dict(dictionary, prefix=''):
""" """
ret = MultiValueDict() ret = MultiValueDict()
regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix)) regex = re.compile(r'^%s\.(.+)$' % re.escape(prefix))
for field, value in dictionary.items(): for field in dictionary:
match = regex.match(field) match = regex.match(field)
if not match: if not match:
continue continue
key = match.groups()[0] key = match.groups()[0]
ret[key] = value value = dictionary.getlist(field)
ret.setlist(key, value)
return ret return ret