- Allow a ``_depth`` argument to ``pyramid.view.view_config``, which will
permit limited compisition reuse of the decorator by other software that
wants to provide custom decorators that are much like view_config.
Closes #637.
| | |
| | | class; that's enough to satisfy WebOb and behave as it did before with the |
| | | monkeypatching. |
| | | |
| | | - Allow a ``_depth`` argument to ``pyramid.view.view_config``, which will |
| | | permit limited composition reuse of the decorator by other software that |
| | | wants to provide custom decorators that are much like view_config. |
| | | |
| | | Bug Fixes |
| | | --------- |
| | | |
| | |
| | | self.assertTrue(renderer is renderer_helper) |
| | | self.assertEqual(config.pkg, pyramid.tests) |
| | | |
| | | def test_call_withdepth(self): |
| | | decorator = self._makeOne(_depth=2) |
| | | venusian = DummyVenusian() |
| | | decorator.venusian = venusian |
| | | def foo(): pass |
| | | decorator(foo) |
| | | self.assertEqual(venusian.depth, 2) |
| | | |
| | | class Test_append_slash_notfound_view(BaseTest, unittest.TestCase): |
| | | def _callFUT(self, context, request): |
| | | from pyramid.view import append_slash_notfound_view |
| | |
| | | self.info = info |
| | | self.attachments = [] |
| | | |
| | | def attach(self, wrapped, callback, category=None): |
| | | def attach(self, wrapped, callback, category=None, depth=1): |
| | | self.attachments.append((wrapped, callback, category)) |
| | | self.depth = depth |
| | | return self.info |
| | | |
| | | class DummyRegistry(object): |
| | |
| | | :meth:`pyramid.config.Configurator.add_view`. If any argument is left |
| | | out, its default will be the equivalent ``add_view`` default. |
| | | |
| | | An additional keyword argument named ``_depth`` is provided for people who |
| | | wish to reuse this class from another decorator. It will be passed in to |
| | | the :term:`venusian` ``attach`` function as the depth of the callstack when |
| | | Venusian checks if the decorator is being used in a class or module |
| | | context. It's not often used, but it can be useful in this circumstance. |
| | | See the ``attach`` function in Venusian for more information. |
| | | |
| | | See :ref:`mapping_views_using_a_decorator_section` for details about |
| | | using :class:`view_config`. |
| | | |
| | |
| | | |
| | | def __call__(self, wrapped): |
| | | settings = self.__dict__.copy() |
| | | depth = settings.pop('_depth', 1) |
| | | |
| | | def callback(context, name, ob): |
| | | config = context.config.with_package(info.module) |
| | | config.add_view(view=ob, **settings) |
| | | |
| | | info = self.venusian.attach(wrapped, callback, category='pyramid') |
| | | info = self.venusian.attach(wrapped, callback, category='pyramid', |
| | | depth=depth) |
| | | |
| | | if info.scope == 'class': |
| | | # if the decorator was attached to a method in a class, or |