本文整理汇总了Python中database.Session.find方法的典型用法代码示例。如果您正苦于以下问题:Python Session.find方法的具体用法?Python Session.find怎么用?Python Session.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.Session
的用法示例。
在下文中一共展示了Session.find方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: socket_ping
# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import find [as 别名]
def socket_ping(data):
# We pull the user id ourselves to avoid excessive DB queries
if request.cookies.get("sid"):
s = Session.find(request.cookies.get("sid"))
if s:
redis.set("user:%s:ping" % s['user'], time.time())
if 'lobby' in data:
redis.set("user:%s:lobby:%s:ping" % (s['user'], data['lobby']), time.time())
示例2: beforeRequest
# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import find [as 别名]
def beforeRequest():
g.user = None
g.uid = -1
g.state = STATE
if request.path.startswith("/static"):
return
# Normal session
if request.cookies.get("sid"):
s = Session.find(request.cookies.get("sid"))
if s:
# Eventually we should be lazily loading this in, or cacheing it at redis
try:
g.user = User.select().where(User.id == s['user']).get()
g.uid = g.user.id
except User.DoesNotExist:
resp = flashy("Wow! Something really went wrong. Contact support!")
resp.set_cookie('sid', '', expires=0)
return resp