summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2011-09-03 20:33:36 -0400
committerChris McDonough <chrism@plope.com>2011-09-03 20:33:36 -0400
commit7a7c8c788bbc739f25eb1fb3754999270cd87fb6 (patch)
treed9a9dbf0fdc95259c31e30b908ef1890ddea85d8
parenta7d50d87b447384a30fc2c69eaaef1d974e7562a (diff)
downloadpyramid-7a7c8c788bbc739f25eb1fb3754999270cd87fb6.tar.gz
pyramid-7a7c8c788bbc739f25eb1fb3754999270cd87fb6.tar.bz2
pyramid-7a7c8c788bbc739f25eb1fb3754999270cd87fb6.zip
- The ``route_prefix`` of a configurator was not properly taken into account
when registering routes in certain circumstances. See https://github.com/Pylons/pyramid/issues/260 Closes #260.
-rw-r--r--CHANGES.txt10
-rw-r--r--pyramid/config/__init__.py20
-rw-r--r--pyramid/tests/test_config/test_init.py10
3 files changed, 34 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index b1165cb37..9f2dc67ef 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,13 @@
+Next release
+============
+
+Bug Fixes
+---------
+
+- The ``route_prefix`` of a configurator was not properly taken into account
+ when registering routes in certain circumstances. See
+ https://github.com/Pylons/pyramid/issues/260
+
1.2a4 (2011-09-02)
==================
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index 5e082828f..d5dd5cf35 100644
--- a/pyramid/config/__init__.py
+++ b/pyramid/config/__init__.py
@@ -577,18 +577,26 @@ class Configurator(
The ``route_prefix`` parameter is new as of Pyramid 1.2.
"""
+ # """ <-- emacs
_context = self._ctx
if _context is None:
_context = self._ctx = self._make_context(self.autocommit)
- if self.route_prefix:
- old_prefix = self.route_prefix.rstrip('/') + '/'
- else:
- old_prefix = ''
+ if route_prefix is None:
+ route_prefix = ''
+
+ old_route_prefix = self.route_prefix
+ if old_route_prefix is None:
+ old_route_prefix = ''
- if route_prefix:
- route_prefix = old_prefix + route_prefix.lstrip('/')
+ route_prefix = '%s/%s' % (
+ old_route_prefix.rstrip('/'),
+ route_prefix.lstrip('/')
+ )
+ route_prefix = route_prefix.lstrip('/').rstrip('/')
+ if not route_prefix:
+ route_prefix = None
c = self.maybe_dotted(callable)
module = inspect.getmodule(c)
diff --git a/pyramid/tests/test_config/test_init.py b/pyramid/tests/test_config/test_init.py
index 3d2a0f38a..2a83a0c7a 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -714,8 +714,18 @@ pyramid.tests.test_config.dummy_include2""",
def test_include_with_nested_route_prefix(self):
root_config = self._makeOne(autocommit=True, route_prefix='root')
+ def dummy_subapp2(config):
+ self.assertEqual(config.route_prefix, 'root/nested')
+ def dummy_subapp3(config):
+ self.assertEqual(config.route_prefix, 'root/nested/nested2')
+ config.include(dummy_subapp4)
+ def dummy_subapp4(config):
+ self.assertEqual(config.route_prefix, 'root/nested/nested2')
def dummy_subapp(config):
self.assertEqual(config.route_prefix, 'root/nested')
+ config.include(dummy_subapp2)
+ config.include(dummy_subapp3, route_prefix='nested2')
+
root_config.include(dummy_subapp, route_prefix='nested')
def test_with_context(self):