diff options
| author | Paul Everitt <paul@agendaless.com> | 2013-08-13 16:39:56 -0400 |
|---|---|---|
| committer | Paul Everitt <paul@agendaless.com> | 2013-08-13 16:39:56 -0400 |
| commit | fef73e0cb80ec71b7cccc96e1adcee6ffc26bce8 (patch) | |
| tree | 51be51552313df4e197d841c94d84b5e1d7e8694 | |
| parent | 0dfacfa09dcf62e5a41c3762e7f9b5d1467b54e6 (diff) | |
| parent | a54d7d6f33904e925da27e74d34039f56b7b68e1 (diff) | |
| download | pyramid-fef73e0cb80ec71b7cccc96e1adcee6ffc26bce8.tar.gz pyramid-fef73e0cb80ec71b7cccc96e1adcee6ffc26bce8.tar.bz2 pyramid-fef73e0cb80ec71b7cccc96e1adcee6ffc26bce8.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
| -rw-r--r-- | CHANGES.txt | 11 | ||||
| -rw-r--r-- | CONTRIBUTORS.txt | 2 | ||||
| -rw-r--r-- | docs/whatsnew-1.5.rst | 9 | ||||
| -rw-r--r-- | pyramid/tests/test_url.py | 44 | ||||
| -rw-r--r-- | pyramid/url.py | 22 |
5 files changed, 76 insertions, 12 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..445eb84ae 100644 --- a/docs/whatsnew-1.5.rst +++ b/docs/whatsnew-1.5.rst @@ -123,8 +123,8 @@ The feature additions in Pyramid 1.5 follow. :func:`pyramid.paster.get_appsettings`. This also allowed the generated ``initialize_db`` script from the ``alchemy`` scaffold to grow support for options in the form ``a=1 b=2`` so you can fill in values in a parameterized - ``.ini`` file, e.g. ``initialize_myapp_db etc/development.ini a=1 b=2``. See - https://github.com/Pylons/pyramid/pull/911 + ``.ini`` file, e.g. ``initialize_myapp_db etc/development.ini a=1 b=2``. + See https://github.com/Pylons/pyramid/pull/911 - The ``request.session.check_csrf_token()`` method and the ``check_csrf`` view predicate now take into account the value of the HTTP header named @@ -134,7 +134,10 @@ 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..3d95d7cc9 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:: @@ -679,6 +682,9 @@ class URLMethodsMixin(object): if route_name is None: raise ValueError('Current request matches no route') + if '_query' not in kw: + kw['_query'] = self.GET + newkw = {} newkw.update(self.matchdict) newkw.update(kw) |
