Codebase list python-repoze.tm2 / e4ba54b
document commit veto Chris McDonough 13 years ago
2 changed file(s) with 44 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
00 Next release
11 ============
22
3 - ...
3 - Documented commit veto hook.
44
55 1.0a5 (2009/9/7)
66 ================
9090 from repoze.tm import TM
9191 new_wsgiapp = TM(mywsgiapp)
9292
93 Using A Commit Veto
94 -------------------
95
96 If you'd like to veto commits based on the status code returned by the
97 downstream application, use a commit veto callback.
98
99 First, define the callback somewhere in your application:
100
101 .. code-block:: python
102
103 def commit_veto(environ, status, headers):
104 for good in ('1', '2', '3'):
105 if not status.startswith(good):
106 return True
107 for header_name, header_value in headers:
108 if header_name.lower() == 'x-tm-abort':
109 return True
110
111 Then configure it into your middleware.
112
113 Via Python:
114
115 .. code-block:: python
116
117 from otherplace import mywsgiapp
118 from my.package import commit_veto
119
120 from repoze.tm import TM
121 new_wsgiapp = TM(mywsgiapp, commit_veto=commit_veto)
122
123 Via PasteDeploy:
124
125 .. code-block:: ini
126
127 [filter:tm]
128 commit_veto = my.package:commit_veto
129
130 In the PasteDeploy example, the path is a Python dotted name, where the dots
131 separate module and package names, and the colon separates a module from its
132 contents. In the above example, the code would be implemented as a
133 "commit_veto" function which lives in the "package" submodule of the "my"
134 package.
135
93136 Mocking Up A Data Manager
94137 -------------------------
95138