1.1 --- a/WebStack/Adapters/Django.py Thu Nov 16 23:40:10 2006 +0000
1.2 +++ b/WebStack/Adapters/Django.py Thu Nov 16 23:40:31 2006 +0000
1.3 @@ -22,23 +22,27 @@
1.4
1.5 import WebStack.Django
1.6 from WebStack.Generic import EndOfResponse
1.7 +from WebStack.Adapters.Helpers.Error import ErrorResource
1.8
1.9 -def deploy(resource, authenticator=None, address=None, handle_errors=1):
1.10 +def deploy(resource, authenticator=None, address=None, handle_errors=1, error_resource=None):
1.11
1.12 """
1.13 Deploy the given 'resource', employing the optional 'authenticator' to
1.14 protect it. The optional 'handle_errors' parameter (if true) causes handlers
1.15 - to deal with uncaught exceptions cleanly.
1.16 + to deal with uncaught exceptions cleanly, and the optional 'error_resource'
1.17 + specifies an alternative error message generation resource, if desired.
1.18
1.19 The optional 'address' parameter is deliberately ignored.
1.20 """
1.21
1.22 def _deploy(request, *args, **kw):
1.23 return respond(request, resource, authenticator=authenticator,
1.24 - virtual_path_info=kw.get("vp"), handle_errors=handle_errors)
1.25 + virtual_path_info=kw.get("vp"), handle_errors=handle_errors,
1.26 + error_resource=error_resource)
1.27 return _deploy
1.28
1.29 -def respond(request, resource, authenticator=None, virtual_path_info=None, handle_errors=1):
1.30 +def respond(request, resource, authenticator=None, virtual_path_info=None, handle_errors=1,
1.31 + error_resource=None):
1.32
1.33 """
1.34 Dispatch to the root application-specific 'resource'. Employ the optional
1.35 @@ -47,9 +51,12 @@
1.36 given 'resource'.
1.37
1.38 The optional 'handle_errors' parameter (if true) causes handlers to deal
1.39 - with uncaught exceptions cleanly.
1.40 + with uncaught exceptions cleanly, and the optional 'error_resource'
1.41 + specifies an alternative error message generation resource.
1.42 """
1.43
1.44 + error_resource = error_resource or ErrorResource()
1.45 +
1.46 trans = WebStack.Django.Transaction(request)
1.47 if virtual_path_info:
1.48 trans.set_virtual_path_info(virtual_path_info)
1.49 @@ -62,7 +69,9 @@
1.50 pass
1.51 except Exception, exc:
1.52 if handle_errors:
1.53 + trans.rollback()
1.54 trans.set_response_code(500) # Internal error
1.55 + error_resource.respond(trans)
1.56 else:
1.57 raise
1.58 else: