diff options
| author | Chris McDonough <chrism@plope.com> | 2011-02-25 00:36:44 -0500 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2011-02-25 00:36:44 -0500 |
| commit | 0a0edfcc42611fc9f815e7a4117674678840abb1 (patch) | |
| tree | edd0426484c1bed7aee310541e2eac9c7b66e0f5 | |
| parent | f6efedac6346f056970d1be13c3ae054ce56b3fb (diff) | |
| download | pyramid-0a0edfcc42611fc9f815e7a4117674678840abb1.tar.gz pyramid-0a0edfcc42611fc9f815e7a4117674678840abb1.tar.bz2 pyramid-0a0edfcc42611fc9f815e7a4117674678840abb1.zip | |
- ``pyramid.url.route_path`` (and the shortcut
``pyramid.request.Request.route_url`` method) now include the WSGI
SCRIPT_NAME at the front of the path if it is not empty (see
https://github.com/Pylons/pyramid/issues/135).
- ``pyramid.testing.DummyRequest`` now has a ``script_name`` attribute (the
empty string).
Closes #135
| -rw-r--r-- | CHANGES.txt | 8 | ||||
| -rw-r--r-- | pyramid/testing.py | 1 | ||||
| -rw-r--r-- | pyramid/tests/test_url.py | 12 | ||||
| -rw-r--r-- | pyramid/url.py | 14 |
4 files changed, 28 insertions, 7 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 37d7a3dfc..85ee1b614 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -24,6 +24,14 @@ Bug Fixes - Don't send port numbers along with domain information in cookies set by AuthTktCookieHelper (see https://github.com/Pylons/pyramid/issues/131). +- ``pyramid.url.route_path`` (and the shortcut + ``pyramid.request.Request.route_url`` method) now include the WSGI + SCRIPT_NAME at the front of the path if it is not empty (see + https://github.com/Pylons/pyramid/issues/135). + +- ``pyramid.testing.DummyRequest`` now has a ``script_name`` attribute (the + empty string). + 1.0 (2011-01-30) ================ diff --git a/pyramid/testing.py b/pyramid/testing.py index 096b260b2..c4ba2584b 100644 --- a/pyramid/testing.py +++ b/pyramid/testing.py @@ -641,6 +641,7 @@ class DummyRequest(object): query_string = '' response_callbacks = () charset = 'UTF-8' + script_name = '' def __init__(self, params=None, environ=None, headers=None, path='/', cookies=None, post=None, **kw): if environ is None: diff --git a/pyramid/tests/test_url.py b/pyramid/tests/test_url.py index a40727e9b..3c70e9028 100644 --- a/pyramid/tests/test_url.py +++ b/pyramid/tests/test_url.py @@ -271,6 +271,17 @@ class TestRoutePath(unittest.TestCase): _anchor=u"foo") self.assertEqual(result, '/1/2/3/extra1/extra2?a=1#foo') + def test_with_script_name(self): + from pyramid.interfaces import IRoutesMapper + request = _makeRequest() + request.script_name = '/foo' + mapper = DummyRoutesMapper(route=DummyRoute('/1/2/3')) + request.registry.registerUtility(mapper, IRoutesMapper) + result = self._callFUT('flub', request, 'extra1', 'extra2', + a=1, b=2, c=3, _query={'a':1}, + _anchor=u"foo") + self.assertEqual(result, '/foo/1/2/3/extra1/extra2?a=1#foo') + class TestStaticUrl(unittest.TestCase): def setUp(self): cleanUp() @@ -328,6 +339,7 @@ class DummyContext(object): class DummyRequest: application_url = 'http://example.com:5432' # app_url never ends with slash + script_name = '' def __init__(self, environ=None): if environ is None: environ = {} diff --git a/pyramid/url.py b/pyramid/url.py index b0dac8630..cb60684e2 100644 --- a/pyramid/url.py +++ b/pyramid/url.py @@ -164,8 +164,8 @@ def route_path(route_name, request, *elements, **kw): This function accepts the same argument as :func:`pyramid.url.route_url` and performs the same duty. It just omits the host, port, and scheme - information in the return value; only the path, query parameters, - and anchor data are present in the returned string. + information in the return value; only the script_name, path, + query parameters, and anchor data are present in the returned string. For example, if you've defined a route named 'foobar' with the path ``/{foo}/{bar}``, this call to ``route_path``:: @@ -175,12 +175,12 @@ def route_path(route_name, request, *elements, **kw): Will return the string ``/1/2``. .. note:: Calling ``route_path('route', request)`` is the same as calling - ``route_url('route', request, _app_url='')``. ``route_path`` is, in - fact, implemented in terms of ``route_url`` in just this way. As a - result, any ``_app_url`` pass within the ``**kw`` values to - ``route_path`` will be ignored. + ``route_url('route', request, _app_url=request.script_name)``. + ``route_path`` is, in fact, implemented in terms of ``route_url`` + in just this way. As a result, any ``_app_url`` passed within the + ``**kw`` values to ``route_path`` will be ignored. """ - kw['_app_url'] = '' + kw['_app_url'] = request.script_name return route_url(route_name, request, *elements, **kw) def resource_url(resource, request, *elements, **kw): |
