tg.url() multiple values for one key

38 views
Skip to first unread message

imix

unread,
Jul 25, 2007, 2:49:48 PM7/25/07
to TurboGears
Hi
the function url (from controllers.py) as it is does not support
multiple values for the same key.
How about a change along the lines of the following patch? This would
permit to use lists as values. A list would then be translated to
multiple args with the same key and the values from the list.

--- controllers.py.old 2007-07-25 20:37:35.000000000 +0200
+++ controllers.py 2007-07-25 20:36:38.000000000 +0200
@@ -496,9 +496,14 @@
for key, value in tgparams.iteritems():
if value is None:
continue
- if isinstance(value, unicode):
- value = value.encode("utf8")
- args.append("%s=%s" % (k, urllib.quote(str(v))))
+ if type(value) == list:
+ pairs = [(key, v) for v in value]
+ else:
+ pairs = [(key, value)]
+ for (k,v) in pairs:
+ if isinstance(value, unicode):
+ value = value.encode("utf8")
+ args.append("%s=%s" % (k, urllib.quote(str(v))))
if args:
result += "?" + "&".join(args)
return result

regards

Stefan

Christopher Arndt

unread,
Jul 25, 2007, 4:07:49 PM7/25/07
to turbo...@googlegroups.com
imix schrieb:

> the function url (from controllers.py) as it is does not support
> multiple values for the same key.
> How about a change along the lines of the following patch?

Looks good. Care to create a patch [1] and maybe a test in
tests/test_controller.py as well and put it in a ticket?

I would make one small change:

- args.append("%s=%s" % (k, urllib.quote(str(v))))

+ if isinstance(value, (list, tuple)):

Be sure to do "svn update" before you create the patch because I have
just changed that function.

Chris

[1] http://docs.turbogears.org/patching_guidelines

imix

unread,
Jul 26, 2007, 1:09:03 PM7/26/07
to TurboGears
Hi,
the ticket can be found here:
http://trac.turbogears.org/ticket/1456

The patch includes the change, a test case and an addition to the
description of the function.

regards

Stefan

Christopher Arndt

unread,
Jul 26, 2007, 5:58:05 PM7/26/07
to turbo...@googlegroups.com
imix schrieb:

> the ticket can be found here:
> http://trac.turbogears.org/ticket/1456
>
> The patch includes the change, a test case and an addition to the
> description of the function.

Applied in r3383 and r3385. Thanks!

Chris

Reply all
Reply to author
Forward
0 new messages