diff options
author | Ben Bangert <ben@groovie.org> | 2008-03-10 14:10:51 -0700 |
---|---|---|
committer | Ben Bangert <ben@groovie.org> | 2008-03-10 14:10:51 -0700 |
commit | 0436ec37b0fa9dedc13fde0f712a73590b3db82f (patch) | |
tree | 225fc6e2b0a5c2787391a93a841a6fc54203aa9d | |
parent | 21cbabb729035f46d1f1bbbf725fdb6b67e9825c (diff) | |
download | routes-0436ec37b0fa9dedc13fde0f712a73590b3db82f.tar.gz |
* Fixed url_for to handle lists as keyword args when generating query
parameters.
--HG--
branch : trunk
-rw-r--r-- | CHANGELOG | 2 | ||||
-rw-r--r-- | routes/base.py | 15 | ||||
-rw-r--r-- | routes/util.py | 12 |
3 files changed, 23 insertions, 6 deletions
@@ -2,6 +2,8 @@ Routes Changelog ======================== -- 1.8 (**tip**) +* Fixed url_for to handle lists as keyword args when generating query + parameters. * WARNING: Changed map.resource to not use ';', for actions, but the normal '/'. This means that formatted URL's will also now have the format come AFTER the action. Ie: /messsages/4.xml;rss -> /messages/4/rss.xml diff --git a/routes/base.py b/routes/base.py index 8b892b9..02d07c9 100644 --- a/routes/base.py +++ b/routes/base.py @@ -539,9 +539,18 @@ class Route(object): if _append_slash and not url.endswith('/'): url += '/' url += '?' - url += urllib.urlencode([(key, kargs[key]) for key in kargs \ - if key in extras and \ - (key != 'action' or key != 'controller')]) + fragments = [] + for key in extras: + if key == 'action' or key == 'controller': + continue + val = kargs[key] + if isinstance(val, (tuple, list)): + for value in val: + fragments.append((key, value)) + else: + fragments.append((key, val)) + + url += urllib.urlencode(fragments) elif _append_slash and not url.endswith('/'): url += '/' return url diff --git a/routes/util.py b/routes/util.py index a9cc740..bcdbd1d 100644 --- a/routes/util.py +++ b/routes/util.py @@ -170,9 +170,15 @@ def url_for(*args, **kargs): url += '?' query_args = [] for key, val in kargs.iteritems(): - query_args.append("%s=%s" % ( - urllib.quote_plus(unicode(key).encode(encoding)), - urllib.quote_plus(unicode(val).encode(encoding)))) + if isinstance(val, (list, tuple)): + for value in val: + query_args.append("%s=%s" % ( + urllib.quote_plus(unicode(key).encode(encoding)), + urllib.quote_plus(unicode(value).encode(encoding)))) + else: + query_args.append("%s=%s" % ( + urllib.quote_plus(unicode(key).encode(encoding)), + urllib.quote_plus(unicode(val).encode(encoding)))) url += '&'.join(query_args) if not static: route_args = [] |