def get_dishes_by_menu(self, idmenu): """Gets dishes of menu with id idmenu from db :param idmenu: the menu id we need to get dishes from :return: dishes of menu with idmenu id """ data = execute_selection(sql=_SQL_SELECT_DISH, values=(idmenu)) return data
def get_user(self, userid): """Gets user naem and user type :param userid: id of the current user :returns: user object as user(user name,user type) """ user = User(**execute_selection(sql=_SQL_GET_USER, values=(userid))[0]) return user
def get_menu(self, chosen_date): """Gets menu details of the menu served on date chosen_date :param chosen_date: date of menu to be returned :returns: menu of the date chosen_date """ data = execute_selection(sql=_SQL_MENU_BY_DATE, values=(chosen_date)) return data
def get_menus_dates(self): """ :returns: all the dates with menu data """ res = execute_selection(sql=_SQL_GET_MENUS_DATES) data = [] for index in range(len(res)): data.append(res[index]['menu_date']) return data
def check_if_dish_exist(self, dish): """checks if dish exist in dish table :param dish: dish name :reutrns: True if exist, False if not. """ values = (dish) res = execute_selection(_SQL_GET_DISH_BY_NAME, values) if len(res) > 0: return True else: return False
def authenticate(self, username, password): """Check if the username and password are ok. :param username: user name :param password: user password :returns: True - if username and password are a match. False - if no match or if an error occurred """ self.user_type = '' data = execute_selection(sql=_SQL_GET_USER_PASSWORD_HASH, values=(username)) if len(data) == 0: return False hash = data[0]['password'] userid = data[0]['userid'] # if the user and pass are ok return userid if self.verify_password(hash, password) else False
def get_all_dishes(self): """ :returns: all dishes """ res = execute_selection(_SQL_GET_ALL_DISHES) return res