本文整理匯總了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