From cd5ab51eca5ca95c31eaa12192234938bc1435cb Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 7 Nov 2013 01:08:39 -0600 Subject: support query string and anchor on external static urls --- pyramid/config/views.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 69f68e422..3b768b0e9 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -36,6 +36,8 @@ from pyramid.interfaces import ( from pyramid import renderers from pyramid.compat import ( + native_, + text_type, string_types, urlparse, url_quote, @@ -44,6 +46,8 @@ from pyramid.compat import ( is_nonstr_iter ) +from pyramid.encode import urlencode + from pyramid.exceptions import ( ConfigurationError, PredicateMismatch, @@ -1902,7 +1906,18 @@ class StaticURLInfo(object): url = urlparse.urlunparse(url_parse( url, scheme=request.environ['wsgi.url_scheme'])) subpath = url_quote(subpath) - return urljoin(url, subpath) + result = urljoin(url, subpath) + if '_query' in kw: + query = kw.pop('_query') + if isinstance(query, text_type): + result += '?' + native_(query) + elif query: + result += '?' + urlencode(query, doseq=True) + if '_anchor' in kw: + anchor = kw.pop('_anchor') + anchor = native_(anchor, 'utf-8') + result += '#' + anchor + return result raise ValueError('No static URL definition matching %s' % path) -- cgit v1.2.3