summaryrefslogtreecommitdiff
path: root/pecan/hooks.py
diff options
context:
space:
mode:
authorJonathan LaCour <jonathan@cleverdevil.org>2011-06-17 14:46:03 -0400
committerJonathan LaCour <jonathan@cleverdevil.org>2011-06-17 14:46:03 -0400
commitcc648f80c53dc5f053b57538c2df19bd4ff98216 (patch)
tree73e20155bc01e518e019801061fc8b661f98b191 /pecan/hooks.py
parentf1bd2b237a33ec71caacecea617fd5ee95c33025 (diff)
downloadpecan-cc648f80c53dc5f053b57538c2df19bd4ff98216.tar.gz
Adding a feature for decorating methods to perform an action after a
commit is issued by the transaction hook.
Diffstat (limited to 'pecan/hooks.py')
-rw-r--r--pecan/hooks.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/pecan/hooks.py b/pecan/hooks.py
index a3e8e3c..c1d0037 100644
--- a/pecan/hooks.py
+++ b/pecan/hooks.py
@@ -1,7 +1,7 @@
from inspect import getmembers
from webob.exc import HTTPFound
-from util import iscontroller
+from util import iscontroller, _cfg
__all__ = ['PecanHook', 'TransactionHook', 'HookController']
@@ -117,7 +117,7 @@ class TransactionHook(PecanHook):
controller = getattr(state, 'controller', None)
if controller:
- force_transactional = getattr(state.controller, '__transactional__', False)
+ force_transactional = _cfg(controller).get('transactional', False)
else:
force_transactional = False
@@ -146,11 +146,9 @@ class TransactionHook(PecanHook):
# (e.g., shouldn't consider them rollback-worthy)
# don't set `state.request.error = True`.
#
- transactional_ignore_redirects = getattr(
- getattr(state, 'controller', None),
- '__transactional_ignore_redirects__',
- state.request.method not in ('GET', 'HEAD')
- )
+ transactional_ignore_redirects = state.request.method not in ('GET', 'HEAD')
+ if hasattr(state, 'controller'):
+ transactional_ignore_redirects = _cfg(state.controller).get('transactional_ignore_redirects', transactional_ignore_redirects)
if type(e) is HTTPFound and transactional_ignore_redirects is True:
return
state.request.error = True
@@ -161,4 +159,8 @@ class TransactionHook(PecanHook):
self.rollback()
else:
self.commit()
+ controller = getattr(state, 'controller', None)
+ actions = _cfg(controller).get('after_commit', [])
+ for action in actions:
+ action()
self.clear()