summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-10-26 01:58:14 -0400
committerChris McDonough <chrism@plope.com>2010-10-26 01:58:14 -0400
commit8d32c0129c78f7039a82ceb3199c74ca35d11868 (patch)
tree71a5942361899d04915e0731dfd08b1840b98f5d
parent9b8d0ca728b9668d853032dc2ed9136887a9bdf9 (diff)
downloadpyramid-8d32c0129c78f7039a82ceb3199c74ca35d11868.tar.gz
pyramid-8d32c0129c78f7039a82ceb3199c74ca35d11868.tar.bz2
pyramid-8d32c0129c78f7039a82ceb3199c74ca35d11868.zip
add action decorator
-rw-r--r--pyramid/tests/test_view.py22
-rw-r--r--pyramid/view.py10
2 files changed, 32 insertions, 0 deletions
diff --git a/pyramid/tests/test_view.py b/pyramid/tests/test_view.py
index 095ece18e..62d09358b 100644
--- a/pyramid/tests/test_view.py
+++ b/pyramid/tests/test_view.py
@@ -436,6 +436,28 @@ class Test_default_exceptionresponse_view(unittest.TestCase):
result = self._callFUT(context, request)
self.assertEqual(result, 'abc')
+class Test_action(unittest.TestCase):
+ def _makeOne(self, **kw):
+ from pyramid.view import action
+ return action(**kw)
+
+ def test_call_no_previous__exposed__(self):
+ inst = self._makeOne(a=1, b=2)
+ def wrapped():
+ """ """
+ result = inst(wrapped)
+ self.failUnless(result is wrapped)
+ self.assertEqual(result.__exposed__, [{'a':1, 'b':2}])
+
+ def test_call_with_previous__exposed__(self):
+ inst = self._makeOne(a=1, b=2)
+ def wrapped():
+ """ """
+ wrapped.__exposed__ = [None]
+ result = inst(wrapped)
+ self.failUnless(result is wrapped)
+ self.assertEqual(result.__exposed__, [None, {'a':1, 'b':2}])
+
class ExceptionResponse(Exception):
status = '404 Not Found'
app_iter = ['Not Found']
diff --git a/pyramid/view.py b/pyramid/view.py
index 62c37849f..bcd4cd0b7 100644
--- a/pyramid/view.py
+++ b/pyramid/view.py
@@ -527,4 +527,14 @@ See also :ref:`changing_the_notfound_view`.
"""
+class action(object):
+ def __init__(self, **kw):
+ self.kw = kw
+
+ def __call__(self, wrapped):
+ if hasattr(wrapped, '__exposed__'):
+ wrapped.__exposed__.append(self.kw)
+ else:
+ wrapped.__exposed__ = [self.kw]
+ return wrapped