summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt10
-rw-r--r--docs/narr/environment.rst15
-rw-r--r--pyramid/config/__init__.py21
-rw-r--r--pyramid/tests/test_config/test_init.py10
4 files changed, 47 insertions, 9 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/docs/narr/environment.rst b/docs/narr/environment.rst
index a5909e541..da93332c0 100644
--- a/docs/narr/environment.rst
+++ b/docs/narr/environment.rst
@@ -654,7 +654,18 @@ Here's how:
dictionary with the converted version of the variable *before* passing
it to the Configurator: the configurator makes a *copy* of ``settings``,
it doesn't use the one you pass directly.
-
+
+- When creating an ``includeme`` function that will be later added to your
+ application's configuration you may access the ``settings`` dictionary
+ through the instance of the :term:`Configurator` that is passed into the
+ function as its only argument. For Example:
+
+ .. code-block:: python
+
+ def includeme(config):
+ settings = config.registry.settings
+ debug_frobnosticator = settings['debug_frobnosticator']
+
- In the runtime code that you need to access the new settings value, find
the value in the ``registry.settings`` dictionary and use it. In
:term:`view` code (or any other code that has access to the request), the
@@ -662,7 +673,7 @@ Here's how:
.. code-block:: python
- registry = request.registry.settings
+ settings = request.registry.settings
debug_frobnosticator = settings['debug_frobnosticator']
If you wish to use the value in code that does not have access to the
diff --git a/pyramid/config/__init__.py b/pyramid/config/__init__.py
index 0bfefc7f5..03bb13f8c 100644
--- a/pyramid/config/__init__.py
+++ b/pyramid/config/__init__.py
@@ -583,17 +583,24 @@ class Configurator(
The ``route_prefix`` parameter is new as of Pyramid 1.2.
"""
- ## """ <-- emacs gets confused if this isn't here
+ # """ <-- emacs
action_state = self.action_state
- 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 9422f7dfe..1dccd00e1 100644
--- a/pyramid/tests/test_config/test_init.py
+++ b/pyramid/tests/test_config/test_init.py
@@ -699,8 +699,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):