def search_by_user_and_leisure(user, leisure): data = None d = db.get_dict('ratings', 'user', user) for r in d: data = d[r] if data['leisure'] == leisure: break else: data = None if data is not None: return data else: return f'No rating has been found with user id : "{user}" and leisure id : "{leisure}".'
def __init__(self, key=None, email=None, username=None, password=None): # e.g. __init__(key) if key is not None and email is None and username is None and password is None: u = db.search_by_key('users', key) self.email = u['email'] self.username = u['username'] self.password = u['password'] self.ratings = db.get_dict('ratings', 'user', key) # e.g. __init__(email=email, username=username, password=password) elif key is None and email is not None and username is not None and password is not None: db.create('users', { 'email': email, 'username': username, 'password': password }) self.email = email self.username = username self.password = password
def search_by_name(name): return db.get_dict('trophies', 'name', name)
def get_dict(): return db.get_dict('trophies')
def search_by_leisure(leisure): r = db.get_dict('ratings', 'leisure', leisure) if r is not None: return r else: return f'No rating has been found with leisure id : "{leisure}".'
def search_by_user(user): r = db.get_dict('ratings', 'user', user) if r is not None: return r else: return f'No rating has been found with user id : "{user}".'
def get_dict(): return db.get_dict('ratings')
def search_by_username(username): r = db.get_dict('users', 'username', username) if r is None: return f'No user has been found with username : "******".' else: return r
def search_by_email(email): r = db.get_dict('users', 'email', email) if r is None: return f'No user has been found with email : "{email}".' else: return r
def get_dict(): return db.get_dict('users')