diff options
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | docs/whatsnew-1.5.rst | 3 | ||||
| -rw-r--r-- | pyramid/tests/test_url.py | 44 | ||||
| -rw-r--r-- | pyramid/url.py | 21 |
5 files changed, 71 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index e9533ab48..0479e3011 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -168,6 +168,17 @@ Bug Fixes - The ``alchemy`` scaffold would break when the database was MySQL during tables creation. See https://github.com/Pylons/pyramid/pull/1049 +- The ``current_route_url`` method now attaches the query string to the URL by + default. See + https://github.com/Pylons/pyramid/issues/1040 + +Backwards Incompatibilities +--------------------------- + +- Modified the ``current_route_url`` method in pyramid.Request. The method + previously returned the URL without the query string by default, it now does + attach the query string unless it is overriden. + 1.4 (2012-12-18) ================ diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 0cecc93df..be9f36338 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -208,3 +208,5 @@ Contributors - Junaid Ali, 2013/08/10 - Chris Davies, 2013/08/11 + +- Jonathan Villemaire-Krajden, 2013/08/13 diff --git a/docs/whatsnew-1.5.rst b/docs/whatsnew-1.5.rst index b987fa77f..89bfdbee3 100644 --- a/docs/whatsnew-1.5.rst +++ b/docs/whatsnew-1.5.rst @@ -134,7 +134,8 @@ The feature additions in Pyramid 1.5 follow. Backwards Incompatibilities --------------------------- -This release has no known backwards incompatibilities with Pyramid 1.4.X. +- Modified the ``current_route_url`` method in pyramid.Request. The method previously returned the URL without the query string by default, it now does attach the query string unless it is overriden. + Deprecations ------------ diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index e33eeebfd..9841c143e 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -485,6 +485,48 @@ 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_request_query_duplicate_entries(self): + from pyramid.interfaces import IRoutesMapper + from webob.multidict import GetDict + request = self._makeOne() + request.GET = GetDict([('q', '123'), ('b', '2'), ('b', '2'), ('q', '456')], {}) + 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&b=2&b=2&q=456') + + 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() @@ -497,7 +539,7 @@ class TestURLMethodsMixin(unittest.TestCase): result = request.current_route_path('extra1', 'extra2', _query={'a':1}, _anchor=text_(b"foo")) self.assertEqual(result, '/script_name/1/2/3/extra1/extra2?a=1#foo') - + def test_route_path_with_elements(self): from pyramid.interfaces import IRoutesMapper request = self._makeOne() diff --git a/pyramid/url.py b/pyramid/url.py index 83f0d1eab..b135c361a 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -124,15 +124,18 @@ class URLMethodsMixin(object): ``*remainder`` replacement value, it is tacked on to the URL after being URL-quoted-except-for-embedded-slashes. - If a keyword argument ``_query`` is present, it will be used to - compose a query string that will be tacked on to the end of the - URL. The value of ``_query`` must be a sequence of two-tuples - *or* a data structure with an ``.items()`` method that returns a + If no ``_query`` keyword argument is provided, the request + query string will be returned in the URL. If it is present, it + will be used to compose a query string that will be tacked on + to the end of the URL, replacing any request query string. + The value of ``_query`` must be a sequence of two-tuples *or* + a data structure with an ``.items()`` method that returns a sequence of two-tuples (presumably a dictionary). This data - structure will be turned into a query string per the documentation - of :func:`pyramid.encode.urlencode` function. After the query - data is turned into a query string, a leading ``?`` is prepended, - and the resulting string is appended to the generated URL. + structure will be turned into a query string per the + documentation of :func:`pyramid.encode.urlencode` function. + After the query data is turned into a query string, a leading + ``?`` is prepended, and the resulting string is appended to + the generated URL. .. note:: @@ -221,6 +224,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') |
