From fe8c0f5f2de669941015c222005be1b5e62e39ed Mon Sep 17 00:00:00 2001 From: Jonathan Villemaire-Krajden Date: Tue, 13 Aug 2013 11:26:43 -0400 Subject: Request.current_route_url() now returns the query string by default. --- pyramid/tests/test_url.py | 28 ++++++++++++++++++++++++++++ pyramid/url.py | 2 ++ 2 files changed, 30 insertions(+) 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') -- cgit v1.2.3 From e160a44cc459baf5e30ad19e18b7c95b0a6397ac Mon Sep 17 00:00:00 2001 From: Jonathan Villemaire-Krajden Date: Tue, 13 Aug 2013 12:33:41 -0400 Subject: Updated doc string for Request.current_route_url. --- pyramid/url.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pyramid/url.py b/pyramid/url.py index feb304fb8..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:: -- cgit v1.2.3 From 0f1bc5286f772d2001bbcab8235bf5f7805b7634 Mon Sep 17 00:00:00 2001 From: Jonathan Villemaire-Krajden Date: Tue, 13 Aug 2013 13:10:47 -0400 Subject: Updated CHANGES Fixes 1040. --- CHANGES.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index e9533ab48..1b4c3492c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -168,6 +168,9 @@ Bug Fixes - The ``alchemy`` scaffold would break when the database was MySQL during tables creation. See https://github.com/Pylons/pyramid/pull/1049 +- The route ``current_route_url`` method now attaches the query string to the URL by default. See + https://github.com/Pylons/pyramid/issues/1040 + 1.4 (2012-12-18) ================ @@ -205,6 +208,8 @@ Backwards Incompatibilities similar way to the changes described to ``_depth`` above. This argument remains undocumented, but might be used in the wild by some insane person. +- 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.4b1 (2012-11-21) ================== -- cgit v1.2.3 From 33e0fe18037d99312d8d4d966a8e01baffc2e62d Mon Sep 17 00:00:00 2001 From: Jonathan Villemaire-Krajden Date: Tue, 13 Aug 2013 13:25:17 -0400 Subject: Fixes to documentation, added change to what's new. --- CHANGES.txt | 9 ++++++--- docs/whatsnew-1.5.rst | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 1b4c3492c..42b3e7546 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -168,9 +168,14 @@ Bug Fixes - The ``alchemy`` scaffold would break when the database was MySQL during tables creation. See https://github.com/Pylons/pyramid/pull/1049 -- The route ``current_route_url`` method now attaches the query string to the URL by default. See +- 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) ================ @@ -208,8 +213,6 @@ Backwards Incompatibilities similar way to the changes described to ``_depth`` above. This argument remains undocumented, but might be used in the wild by some insane person. -- 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.4b1 (2012-11-21) ================== 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 ------------ -- cgit v1.2.3 From 6a4a3413756a94f5e7ebbe7720788f28ca280a72 Mon Sep 17 00:00:00 2001 From: Jonathan Villemaire-Krajden Date: Tue, 13 Aug 2013 14:01:25 -0400 Subject: Fixed documentation width, signed contributors agreement and added a test for duplicate query strings. --- CHANGES.txt | 7 +++++-- CONTRIBUTORS.txt | 2 ++ pyramid/tests/test_url.py | 16 +++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 42b3e7546..0479e3011 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -168,13 +168,16 @@ 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 +- 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. +- 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/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index 2830f8f10..9841c143e 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -499,6 +499,20 @@ class TestURLMethodsMixin(unittest.TestCase): 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 @@ -525,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() -- cgit v1.2.3 From b4ae4260ea434a39e5d3dfa026a7f6e70ef8d70c Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 13 Aug 2013 15:10:18 -0500 Subject: fix line length --- docs/whatsnew-1.5.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/whatsnew-1.5.rst b/docs/whatsnew-1.5.rst index 89bfdbee3..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,9 @@ The feature additions in Pyramid 1.5 follow. 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. +- 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 -- cgit v1.2.3 From a54d7d6f33904e925da27e74d34039f56b7b68e1 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 13 Aug 2013 15:22:07 -0500 Subject: fix a regression with the current_route_url changes in #1081 --- pyramid/url.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pyramid/url.py b/pyramid/url.py index b135c361a..3d95d7cc9 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -224,8 +224,6 @@ 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') @@ -684,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) -- cgit v1.2.3