summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Villemaire-Krajden <odontomachus@gmail.com>2013-08-13 11:26:43 -0400
committerJonathan Villemaire-Krajden <odontomachus@gmail.com>2013-08-13 11:26:43 -0400
commitfe8c0f5f2de669941015c222005be1b5e62e39ed (patch)
tree679e1268eaf3444fb0a646a651de8d4ff1ff343e
parent159ef62eecd4ec6c5759720ca04d7c18f1d5fd8b (diff)
downloadpyramid-fe8c0f5f2de669941015c222005be1b5e62e39ed.tar.gz
pyramid-fe8c0f5f2de669941015c222005be1b5e62e39ed.tar.bz2
pyramid-fe8c0f5f2de669941015c222005be1b5e62e39ed.zip
Request.current_route_url() now returns the query string by default.
-rw-r--r--pyramid/tests/test_url.py28
-rw-r--r--pyramid/url.py2
2 files changed, 30 insertions, 0 deletions
diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py
index e33eeebfd..2830f8f10 100644
--- a/pyramid/tests/test_url.py
+++ b/pyramid/tests/test_url.py
@@ -485,6 +485,34 @@ class TestURLMethodsMixin(unittest.TestCase):
self.assertEqual(result,
'http://example.com:5432/1/2/3/extra1/extra2?a=1#foo')
+ def test_current_route_url_with_request_query(self):
+ from pyramid.interfaces import IRoutesMapper
+ from webob.multidict import GetDict
+ request = self._makeOne()
+ request.GET = GetDict([('q', '123')], {})
+ route = DummyRoute('/1/2/3')
+ mapper = DummyRoutesMapper(route=route)
+ request.matched_route = route
+ request.matchdict = {}
+ request.registry.registerUtility(mapper, IRoutesMapper)
+ result = request.current_route_url()
+ self.assertEqual(result,
+ 'http://example.com:5432/1/2/3?q=123')
+
+ def test_current_route_url_with_query_override(self):
+ from pyramid.interfaces import IRoutesMapper
+ from webob.multidict import GetDict
+ request = self._makeOne()
+ request.GET = GetDict([('q', '123')], {})
+ route = DummyRoute('/1/2/3')
+ mapper = DummyRoutesMapper(route=route)
+ request.matched_route = route
+ request.matchdict = {}
+ request.registry.registerUtility(mapper, IRoutesMapper)
+ result = request.current_route_url(_query={'a':1})
+ self.assertEqual(result,
+ 'http://example.com:5432/1/2/3?a=1')
+
def test_current_route_path(self):
from pyramid.interfaces import IRoutesMapper
request = self._makeOne()
diff --git a/pyramid/url.py b/pyramid/url.py
index 83f0d1eab..feb304fb8 100644
--- a/pyramid/url.py
+++ b/pyramid/url.py
@@ -221,6 +221,8 @@ class URLMethodsMixin(object):
query = kw.pop('_query')
if query:
qs = '?' + urlencode(query, doseq=True)
+ elif getattr(self, 'GET', None):
+ qs = '?' + urlencode(self.GET, doseq=True)
if '_anchor' in kw:
anchor = kw.pop('_anchor')