renamings + corrected a bug

This commit is contained in:
spiq 2011-03-09 14:07:06 +02:00
parent d053cc892d
commit 899233bf99

View File

@ -82,23 +82,23 @@ class DataFlatener(object):
#TODO : document + test #TODO : document + test
def flatten_data(self, data): def flatten_data(self, data):
"""Given a data dictionary ``{<attr_name>: <value_list>}``, returns a flattened dictionary according to :meth:`FormParser.is_a_list`. """Given a data dictionary ``{<key>: <value_list>}``, returns a flattened dictionary according to :meth:`FormParser.is_a_list`.
""" """
flatdata = dict() flatdata = dict()
for attr_name, attr_value in data.items(): for key, attr_value in data.items():
if self.is_a_list(attr_name): if self.is_a_list(key):
if isinstance(attr_value, list): if isinstance(attr_value, list):
flatdata[attr_name] = attr_value flatdata[key] = attr_value
else: else:
flatdata[attr_name] = [attr_value] flatdata[key] = [attr_value]
else: else:
if isinstance(attr_value, list): if isinstance(attr_value, list):
flatdata[attr_name] = attr_value[0] flatdata[key] = attr_value[0]
else: else:
flatdata[attr_name] = attr_value flatdata[key] = attr_value
return flatdata return flatdata
def is_a_list(self, attr_name): def is_a_list(self, key):
""" """ """ """
return False return False
@ -120,7 +120,7 @@ class FormParser(BaseParser, DataFlatener):
data = parse_qs(input) data = parse_qs(input)
elif request.method == 'POST': elif request.method == 'POST':
# Django has already done the form parsing for us. # Django has already done the form parsing for us.
data = request.POST data = dict(request.POST.iterlists())
# Flatening data and removing EMPTY_VALUEs from the lists # Flatening data and removing EMPTY_VALUEs from the lists
data = self.flatten_data(data) data = self.flatten_data(data)