summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Miller <rob@mochimedia.com>2010-12-28 21:54:34 -0800
committerRob Miller <rob@mochimedia.com>2010-12-28 21:54:34 -0800
commit73877f08d25eb77b87f0cd3aa35472165b9b50ba (patch)
tree7b4f0b878ea73c8919bf4591c4d465f47f73edfe
parentbae647592ee4913ed7e52409c89815c3ebb37ef7 (diff)
downloadpyramid-73877f08d25eb77b87f0cd3aa35472165b9b50ba.tar.gz
pyramid-73877f08d25eb77b87f0cd3aa35472165b9b50ba.tar.bz2
pyramid-73877f08d25eb77b87f0cd3aa35472165b9b50ba.zip
Added support for an _action_decorator classmethod on handler classes.
-rw-r--r--pyramid/config.py10
-rw-r--r--pyramid/tests/test_config.py16
2 files changed, 23 insertions, 3 deletions
diff --git a/pyramid/config.py b/pyramid/config.py
index 083e2a328..5c3bf7002 100644
--- a/pyramid/config.py
+++ b/pyramid/config.py
@@ -941,6 +941,8 @@ class Configurator(object):
pattern = route.pattern
+ action_decorator = getattr(handler, '_action_decorator', None)
+
path_has_action = ':action' in pattern or '{action}' in pattern
if action and path_has_action:
@@ -970,7 +972,8 @@ class Configurator(object):
preds.append(ActionPredicate(action))
view_args['custom_predicates'] = preds
self.add_view(view=handler, attr=method_name,
- route_name=route_name, **view_args)
+ route_name=route_name,
+ decorator=action_decorator, **view_args)
else:
method_name = action
if method_name is None:
@@ -993,14 +996,15 @@ class Configurator(object):
view_args = expose_config.copy()
del view_args['name']
self.add_view(view=handler, attr=meth_name,
- route_name=route_name, **view_args)
+ route_name=route_name,
+ decorator=action_decorator, **view_args)
# Now register the method itself
method = getattr(handler, method_name, None)
configs = getattr(method, '__exposed__', [{}])
for expose_config in configs:
self.add_view(view=handler, attr=action, route_name=route_name,
- **expose_config)
+ decorator=action_decorator, **expose_config)
return route
diff --git a/pyramid/tests/test_config.py b/pyramid/tests/test_config.py
index a0bdf95ad..22f491eb4 100644
--- a/pyramid/tests/test_config.py
+++ b/pyramid/tests/test_config.py
@@ -1977,6 +1977,22 @@ class ConfiguratorTests(unittest.TestCase):
self.assertEqual(view['attr'], 'action')
self.assertEqual(view['view'], MyView)
+ def test_add_handler_with_action_decorator(self):
+ config = self._makeOne(autocommit=True)
+ views = []
+ def dummy_add_view(**kw):
+ views.append(kw)
+ config.add_view = dummy_add_view
+ class MyView(object):
+ @classmethod
+ def _action_decorator(cls, fn): # pragma: no cover
+ return fn
+ def action(self): # pragma: no cover
+ return 'response'
+ config.add_handler('name', '/{action}', MyView)
+ self.assertEqual(len(views), 1)
+ self.assertEqual(views[0]['decorator'], MyView._action_decorator)
+
def test_add_handler_doesnt_mutate_expose_dict(self):
config = self._makeOne(autocommit=True)
views = []