def login(username): '''A function that takenano s in a username and returns a user object''' _log.info('Attempting to retrieve user from database') query_dict = {'username': username} user_dict = _scl.users.find_one(query_dict) _log.debug(user_dict) return User.from_dict(user_dict) if user_dict else None
def get_teachers(): dict_list = _scl.users.find({'role': 'teacher'}) return [User.from_dict(user) for user in dict_list]
def get_students(): dict_list = _scl.users.find({'role': 'student'}) return [User.from_dict(user) for user in dict_list]
def get_users(): '''Read all the users from the collection''' _log.info('Attempting to retrieve all users from database') dict_list = _scl.users.find() return [User.from_dict(user) for user in dict_list]
def get_requirements(requirements): '''Gets all requirements''' _log.info('Attempting to retrieve all users from database') dict_list = _scl.users.find({'username': requirements}) return [User.from_dict(user) for user in dict_list]
def get_user_by_id(db_id: int): '''Returns a user by their id''' return User.from_dict(_scl.users.find_one({'_id': db_id}))