user.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:modern-paste 作者: LINKIWI 项目源码 文件源码
def get_user_by_api_key(api_key, active_only=False):
    """
    Get a User object by api_key, whose attributes match those in the database.

    :param api_key: API key to query by
    :param active_only: Set this flag to True to only query for active users
    :return: User object for that user ID
    :raises UserDoesNotExistException: If no user exists with the given user_id
    """
    if active_only:
        user = models.User.query.filter_by(api_key=api_key, is_active=True).first()
    else:
        user = models.User.query.filter_by(api_key=api_key).first()
    if not user:
        raise UserDoesNotExistException('No user with api_key {api_key} exists'.format(api_key=api_key))
    return user
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号