From 7a7c8c788bbc739f25eb1fb3754999270cd87fb6 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 3 Sep 2011 20:33:36 -0400 Subject: - 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. --- CHANGES.txt | 10 ++++++++++ pyramid/config/__init__.py | 20 ++++++++++++++------ pyramid/tests/test_config/test_init.py | 10 ++++++++++ 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): -- cgit v1.2.3 From 1feefdb0a789c89e1c4dd201a99aac6418a15b68 Mon Sep 17 00:00:00 2001 From: Charlie Choiniere Date: Sat, 3 Sep 2011 20:51:40 -0400 Subject: Updated environment documentation to include an example of accessing the settings dictionary inside an includeme function --- docs/narr/environment.rst | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 -- cgit v1.2.3