be8f71259c
Version: Bumped to 4.0 Added: Dependency of pyramid_tm Changed: Changed from ACL Authorization to custom Permission Authorization Policy Using more of inbuilt functions. This should reduce the number of DB hits and improve performance
25 lines
831 B
Python
25 lines
831 B
Python
from pyramid.response import Response
|
|
from sqlalchemy.exc import OperationalError, IntegrityError, DBAPIError
|
|
import transaction
|
|
from brewman.models.validation_exception import ValidationError
|
|
|
|
|
|
def transactional_view(view, info):
|
|
if info.options.get('trans'):
|
|
def wrapper_view(context, request):
|
|
try:
|
|
response = view(context, request)
|
|
except (ValidationError, ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError,
|
|
DBAPIError) as ex:
|
|
transaction.abort()
|
|
response = Response("Failed validation: {0}".format(str(ex)))
|
|
response.status_int = 500
|
|
finally:
|
|
return response
|
|
|
|
return wrapper_view
|
|
return view
|
|
|
|
|
|
transactional_view.options = ('trans',)
|