Michael Merickel
2017-07-08 2e3d988956c37afa49cdf3b8f24e1c04286f0c25
Merge pull request #3121 from mmerickel/backport-3105-to-1.9-branch

backport 3105 to 1.9 branch
3 files modified
48 ■■■■ changed files
CONTRIBUTORS.txt 2 ●●●●● patch | view | raw | blame | history
pyramid/tests/test_view.py 20 ●●●●● patch | view | raw | blame | history
pyramid/view.py 26 ●●●●● patch | view | raw | blame | history
CONTRIBUTORS.txt
@@ -308,3 +308,5 @@
- Volker Diels-Grabsch, 2017/06/09
- Denis Rykov, 2017/06/15
- Tosh Lyons, 2017/06/27
pyramid/tests/test_view.py
@@ -566,6 +566,26 @@
        decorator(foo)
        self.assertEqual(venusian.depth, 2)
    def test_call_withoutcategory(self):
        decorator = self._makeOne()
        venusian = DummyVenusian()
        decorator.venusian = venusian
        def foo(): pass
        decorator(foo)
        attachments = venusian.attachments
        category = attachments[0][2]
        self.assertEqual(category, 'pyramid')
    def test_call_withcategory(self):
        decorator = self._makeOne(_category='not_pyramid')
        venusian = DummyVenusian()
        decorator.venusian = venusian
        def foo(): pass
        decorator(foo)
        attachments = venusian.attachments
        category = attachments[0][2]
        self.assertEqual(category, 'not_pyramid')
class Test_append_slash_notfound_view(BaseTest, unittest.TestCase):
    def _callFUT(self, context, request):
        from pyramid.view import append_slash_notfound_view
pyramid/view.py
@@ -185,14 +185,21 @@
    :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.  The default value is
    ``0`` and should be specified relative to the ``view_config`` invocation.
    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.
    Two additional keyword arguments which will be passed to the
    :term:`venusian` ``attach`` function are ``_depth`` and ``_category``.
    ``_depth`` is provided for people who wish to reuse this class from another
    decorator. The default value is ``0`` and should be specified relative to
    the ``view_config`` invocation. 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.
    ``_category`` sets the decorator category name. It can be useful in
    combination with the ``category`` argument of ``scan`` to control which
    views should be processed.
    See the :py:func:`venusian.attach` function in Venusian for more information.
    
    .. seealso::
    
@@ -215,12 +222,13 @@
    def __call__(self, wrapped):
        settings = self.__dict__.copy()
        depth = settings.pop('_depth', 0)
        category = settings.pop('_category', 'pyramid')
        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=category,
                                    depth=depth + 1)
        if info.scope == 'class':