Google Groups Home
Help | Sign in
tg.url() multiple values for one key
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
imix  
View profile
 More options Jul 25 2007, 2:49 pm
From: imix <stefan.aeschbac...@gmail.com>
Date: Wed, 25 Jul 2007 18:49:48 -0000
Local: Wed, Jul 25 2007 2:49 pm
Subject: tg.url() multiple values for one key
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Arndt  
View profile
 More options Jul 25 2007, 4:07 pm
From: Christopher Arndt <chris.ar...@web.de>
Date: Wed, 25 Jul 2007 22:07:49 +0200
Local: Wed, Jul 25 2007 4:07 pm
Subject: Re: tg.url() multiple values for one key
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
imix  
View profile
 More options Jul 26 2007, 1:09 pm
From: imix <stefan.aeschbac...@gmail.com>
Date: Thu, 26 Jul 2007 17:09:03 -0000
Local: Thurs, Jul 26 2007 1:09 pm
Subject: Re: tg.url() multiple values for one key
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

On Jul 25, 10:07 pm, Christopher Arndt <chris.ar...@web.de> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christopher Arndt  
View profile
 More options Jul 26 2007, 5:58 pm
From: Christopher Arndt <chris.ar...@web.de>
Date: Thu, 26 Jul 2007 23:58:05 +0200
Local: Thurs, Jul 26 2007 5:58 pm
Subject: Re: tg.url() multiple values for one key
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 to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google