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
评论列表
文章目录