Commit 899233bf by spiq

renamings + corrected a bug

parent d053cc89
...@@ -82,23 +82,23 @@ class DataFlatener(object): ...@@ -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): ...@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment