本文整理汇总了Python中models.Token.user_id方法的典型用法代码示例。如果您正苦于以下问题:Python Token.user_id方法的具体用法?Python Token.user_id怎么用?Python Token.user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Token
的用法示例。
在下文中一共展示了Token.user_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_token
# 需要导入模块: from models import Token [as 别名]
# 或者: from models.Token import user_id [as 别名]
def save_token(token, request, *args, **kwargs):
# app.logger.debug('save_token')
#toks = db.session.query(Token).filter_by(client_id=request.client.client_id,
# user_id=request.user.id).all()
#app.logger.debug('client_id={client_id}, user_id={user_id}'.format(client_id=request.client.client_id, user_id=request.user.id))
#app.logger.debug(toks)
## make sure that every client has only one token connected to a user
#db.session.delete(toks)
expires_in = token.pop('expires_in')
expires = datetime.utcnow() + timedelta(seconds=expires_in)
# app.logger.debug(token)
#from pprint import pprint
# import pprint
# from inspect import getmembers
#
# pp = pprint.PrettyPrinter(indent=4)
#
# app.logger.debug('=' * 80)
# app.logger.debug(pp.pformat(getmembers(request)))
# app.logger.debug('=' * 80)
# app.logger.debug(pp.pformat(getmembers(current_user)))
# app.logger.debug('=' * 80)
#app.logger.debug(current_user.dir())
tok = Token(**token)
tok.expires = expires
tok.client_id = request.client.client_id
if not request.user:
tok.user_id = current_user.id
else:
tok.user_id = request.user.id
#if hasattr(request, 'user'):
#tok.user_id = request.user.id
#elif current_user.id:
#tok.user_id = current_user.id
#tok.user_id = current_user.id
db.session.add(tok)
db.session.commit()
return tok