brewman/brewman/transactional_view_deriver.py
tanshu be8f71259c Changed: Moved from global DBSession to dbsession injected into request
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
2016-12-24 17:11:01 +05:30

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',)