From 15141c1a97c0b14ae28a5d934715e8de5d671510 Mon Sep 17 00:00:00 2001 From: Johannes Date: Thu, 8 Dec 2011 01:20:29 +0000 Subject: [PATCH] Put multiple form data values with same key into lists To avoid flattening the form data when converting to json, multiple values with the same key need to be in lists. Fixes issue #19 --- httpbin/helpers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/httpbin/helpers.py b/httpbin/helpers.py index f3482b6..9924aa3 100644 --- a/httpbin/helpers.py +++ b/httpbin/helpers.py @@ -85,6 +85,13 @@ def get_dict(*keys, **extras): if not form.values().pop(): data = form.keys().pop() form = None + + if form: + nonflat_dict = form.to_dict(flat=False) + for k, v in nonflat_dict.items(): + if len(v) == 1: + nonflat_dict[k] = v[0] + form = nonflat_dict d = dict( url=request.url,