<s> from django . db import transaction <EOL> class TransactionMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> transaction . enter_transaction_management ( ) <EOL> transaction . managed ( True ) <EOL> def process_exception ( self , request , exception ) : <EOL> """<STR_LIT>""" <EOL> if transaction . is_dirty ( ) : <EOL> transaction . rollback ( ) <EOL> transaction . leave_transaction_management ( ) <EOL> def process_response ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> if transaction . is_managed ( ) : <EOL> if transaction . is_dirty ( ) : <EOL> transaction . commit ( ) <EOL> transaction . leave_transaction_management ( ) <EOL> return response </s>
