user.py 文件源码

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

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

    :param user_id: User ID 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(user_id=user_id, is_active=True).first()
    else:
        user = models.User.query.filter_by(user_id=user_id).first()
    if not user:
        raise UserDoesNotExistException('No user with user_id {user_id} exists'.format(user_id=user_id))
    return user
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号