本文整理汇总了Python中session.Session.rollback方法的典型用法代码示例。如果您正苦于以下问题:Python Session.rollback方法的具体用法?Python Session.rollback怎么用?Python Session.rollback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.rollback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BaseHandler
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import rollback [as 别名]
class BaseHandler(tornado.web.RequestHandler):
"""A class to collect common handler methods - all other handlers should
subclass this one.
"""
tornado.web.RequestHandler.write_error = error_handler
def get_current_user(self):
"""
Returns the models.User object representing the currently
logged in user.
The get_current_user will only work if the the user is both
logged in and has purchased the film
There is also an override for admin accounts
"""
user = self.get_secure_cookie('user')
return self.session.query(User).filter_by(link=user).first()
def show_error_message(self, message):
self.set_secure_cookie('error_message', message)
def show_message(self, message):
self.set_secure_cookie('message', message)
def login_user(self, user):
self.set_secure_cookie('user', user.link)
def logout_user(self, user):
self.clear_cookie('user')
def prepare(self):
p3p = 'CP="Like Facebook, Santa does not have a P3P policy -Learn why: http://fb.me/p3p"'
self.add_header('Accept-Charset', 'utf-8')
self.set_header('P3P', p3p)
self.session = Session()
def on_finish(self):
try:
self.session.commit()
except Exception as e:
self.session.rollback()
import traceback
logging.critical('Transaction needed to be rolled back because of: \n %s' % traceback.format_exc() )
Session.remove()
def respond_with_json(self, success, message, other_info={}):
response_object = {'success':success, 'message':message}
response_object.update(other_info)
self.write(json.dumps(response_object))
return
def render_template(self, template, **kwargs):
"""
An extension to the render() function.
This adds things linke message, google analytics key, facebook appid,
mixpanel token and the current_user's name to the page at render time.
The args parameter allows you to add adhoc variables to a page as well.
Remember that the args variable must be accessed like args['vari'] in the
tempalte.
"""
current_user = self.get_current_user()
current_user_name = ''
current_user_unique_id = ''
user_has_purchased = False
# Grab the cookie messages
cookie_message = self.get_secure_cookie('message')
error_message = self.get_secure_cookie('error_message')
self.set_secure_cookie("message", '')
self.set_secure_cookie("error_message", '')
kwargs.update({
'user':current_user,
'error_message':error_message,
'message':cookie_message,
'facebook_api_key': settings['facebook_api_key'],
'domain':settings['domain']
})
template = 'templates/%s'%template
return self.render( template, **kwargs)