I submitted a bug: https://bugs.launchpad.net/webpy/+bug/560278 (sorry
about the launchpad update mess)
The way I suggested to fix it would force a single FieldStorage object
to be wrapped in a list. Which might not be ok for consistency. If
backwards compatibility isn't an issue, then how about always
returning the FieldStorage object (filename is needed most of the
time) freeing up userfile=[] to do it's usual job.


Also:
It would be nice if web.input() had a way to put multiple form values
with the same attribute name in a list; without doing
web.input(name=[]). Makes it easier when your form fields change
between different calls to the same web.input() line.

Is adding something like web.inputs() an agreeable idea?

I'm not sure which is more convenient:
1. Returning all form fields wrapped in lists
2. Just wrap multiple form values with the same name

So I made it do both:

>From 55fad93d5945bc71523b0740a161683f988e6cab Mon Sep 17 00:00:00 2001
From: Hudson Lee <[email protected]>
Date: Mon, 12 Apr 2010 10:20:18 -0400
Subject: [PATCH] Added web.inputs() which wraps form fields in lists
without the need todo web.input(aField=[])
 web.inputs(wrapall=False) only wraps form elements with the same name
in a list.
 Also fixed a bug where web.input(fname={}) only returned the last
<input type="file"> with the same name.

---
 web/utils.py  |    8 ++++++--
 web/webapi.py |    7 ++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/web/utils.py b/web/utils.py
index 2bf456c..0bb50a0 100755
--- a/web/utils.py
+++ b/web/utils.py
@@ -126,6 +126,8 @@ def storify(mapping, *requireds, **defaults):
         <Storage {'x': u'a'}>
     """
     _unicode = defaults.pop('_unicode', False)
+    _wrapall = defaults.pop('wrapall', False)
+    _lastItemOnly = defaults.pop('_lastItemOnly', True)
     def unicodify(s):
         if _unicode and isinstance(s, str): return safeunicode(s)
         else: return s
@@ -144,9 +146,11 @@ def storify(mapping, *requireds, **defaults):
         if isinstance(value, list):
             if isinstance(defaults.get(key), list):
                 value = [getvalue(x) for x in value]
-            else:
+            elif _lastItemOnly and not isinstance(defaults.get(key),
dict):
                 value = value[-1]
-        if not isinstance(defaults.get(key), dict):
+        elif _wrapall:
+            value = [value]
+        if _lastItemOnly and not isinstance(defaults.get(key), dict):
             value = getvalue(value)
         if isinstance(defaults.get(key), list) and not
isinstance(value, list):
             value = [value]
diff --git a/web/webapi.py b/web/webapi.py
index 56e2f86..22dc7dd 100644
--- a/web/webapi.py
+++ b/web/webapi.py
@@ -6,7 +6,7 @@ Web API (wrapper around WSGI)
 __all__ = [
     "config",
     "header", "debug",
-    "input", "data",
+    "input", "inputs", "data",
     "setcookie", "cookies",
     "ctx",
     "HTTPError",
@@ -280,6 +280,11 @@ def input(*requireds, **defaults):
     except KeyError:
         raise badrequest()

+def inputs(*requireds, **defaults):
+    defaults.setdefault('wrapall', True)
+    defaults.setdefault('_lastItemOnly', False)
+    return input(*requireds, **defaults)
+
 def data():
     """Returns the data sent with the request."""
     if 'data' not in ctx:
--
1.7.0



-- 
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/webpy?hl=en.

Reply via email to