def add_people(): if request.method == "GET": drinks = get_table("drink") return render_template("addPerson.html", item_list=drinks) elif request.method == "POST": drinks = get_table("drink") person_name = request.form.get("person-name") person_name = web_name_cleaner(person_name) drink_id = int(request.form.get("preference-name")) drink_name = preference_ids_to_name([drink_id])[0] drink_ids = [drink['drink_id'] for drink in drinks] all_names = list(table_to_dict("person").values()) if person_name not in all_names: if drink_id in drink_ids: add_data("person", "name", [person_name]) update_data("person", "name", "preference", {person_name: drink_id}) return render_template('addPerson.html', item_list=drinks, name=person_name, preference=drink_name, success=True) else: print(f"Your drink chosen was: Drink ID= {drink_id} and Drink Name: {drink_name}") return render_template('addPerson.html', item_list=drinks, name=person_name, preference=drink_name, error=True) else: print(f"Your name has already been entered {person_name}") return render_template('addPerson.html', item_list=drinks, name=person_name, preference=drink_name, repeated=True)
def addOrder(): if request.method == "GET": drinks = get_table("drink") people = get_table("person") return render_template('yourname.html', people=people, drinks=drinks) elif request.method == "POST": person_id = request.form.get("people-name") drink_id = request.form.get("drink-name") round_id = get_round_id() add_order(person_id, drink_id, round_id) drinks = table_to_dict("drink") people = table_to_dict("person") last_order = get_last_order() return render_template('rounds.html', people=people, drinks=drinks, orders=last_order, round_active=True)
def remove_people(): if request.method == "GET": people = get_table("person") return render_template('removePerson.html', item_list=people) elif request.method == "POST": people = get_table("person") person_id = int(request.form.get("people-name")) people_ids = list(table_to_dict("person").keys()) if person_id in people_ids: person_name = table_to_dict("person")[person_id] remove_data_by_id("person", [person_id]) people = get_table("person") return render_template('removePerson.html', item_list=people, name=person_name, success=True) else: print(f"You attempted to remove: Person ID= {person_id}") return render_template('removePerson.html', item_list=people, error=True)
def remove_drinks(): if request.method == "GET": drinks = get_table("drink") return render_template('removeDrink.html', item_list=drinks) elif request.method == "POST": drinks = get_table("drink") drink_id = int(request.form.get("drink-name")) drink_ids = list(table_to_dict("drink").keys()) if drink_id in drink_ids: drink_name = table_to_dict("drink")[drink_id] remove_data_by_id("drink", [drink_id]) drinks = get_table("drink") return render_template('removePerson.html', item_list=drinks, name=drink_name, success=True) else: print(f"You attempted to remove: Person ID= {drink_id}") return render_template('removePerson.html', item_list=drinks, error=True)
def update_data(data_name, input_data, dictionary, ids=[], mode="add"): if mode == "add": for item in input_data: if item == "": input_data.remove(item) db.add_data(data_name, "name", input_data) dictionary = db.table_to_dict(data_name) elif mode == "remove": dictionary = update_data_remove(data_name, input_data, ids, dictionary) return dictionary
def add_drinks(): if request.method == "GET": return render_template("addDrink.html") elif request.method == "POST": drinks = get_table("drink") drink = request.form.get("drink-name") drink = web_name_cleaner(drink) all_drinks = list(table_to_dict("drink").values()) if drink not in all_drinks: add_data("drink", "name", [drink]) return render_template('addDrink.html', item_list=drinks, name=drink, success=True) else: print(f"This drink has already been entered {drink}") return render_template('addDrink.html', name=drink, repeated=True)
def people_list(): if request.method == "GET": people = get_table("person") drinks = table_to_dict("drink") return render_template("people.html", table=people, drinks=drinks)
def begin_ordering(): if request.method == "GET": drinks = table_to_dict("drink") people = table_to_dict("person") last_order = get_last_order() return render_template('rounds.html', people=people, drinks=drinks, orders=last_order, round_active=True)
def rounds_list(): if request.method == "GET": drinks = table_to_dict("drink") people = table_to_dict("person") last_order = get_last_order() return render_template('rounds.html', people=people, drinks=drinks, orders=last_order)
def start_app(): try: user_exit = False menu_options = { 1: "List of people", 2: "List of drinks", 3: "List of people and drinks", 4: "Edit people", 5: "Edit drinks", 6: "List of preferences", 7: "Edit preferences", 8: "Start round", 9: "View last round", 10: "Exit" } edit_list_options = {1: "ADD", 2: "REMOVE"} edit_preferences_options = {1: "ADD/CHANGE", 2: "REMOVE"} edit_round_options = {1: "ADD/CHANGE", 2: "REMOVE", 3: "COMPLETE"} people_dict = table_to_dict("person") drinks_dict = table_to_dict("drink") preferences_dict = table_to_dict("preference") last_order_dict = table_to_dict("orders") while not user_exit: os.system("clear") user_selection = draw_menu(menu_options, draw_brIW()) user_selection = int(user_selection) if user_selection > len(menu_options) or user_selection <= 0: input( "\nPlease only enter a number from the options provided. Press 'Enter' to try again." ) continue elif user_selection == 1: people_dict = table_to_dict("person") os.system("clear") draw_table("people", people_dict) elif user_selection == 2: drinks_dict = table_to_dict("drink") os.system("clear") draw_table("drinks", drinks_dict) elif user_selection == 3: people_dict = table_to_dict("person") drinks_dict = table_to_dict("drink") os.system("clear") draw_table("people and drinks", [people_dict, drinks_dict], 2) elif user_selection == 4: os.system("clear") draw_table("people", people_dict) editing_choice = edit_menu(edit_list_options) if editing_choice == "ADD": people_dict = add_data("person", people_dict) elif editing_choice == "REMOVE": people_dict = remove_data("person", people_dict) elif user_selection == 5: os.system("clear") draw_table("drinks", drinks_dict) editing_choice = edit_menu(edit_list_options) if editing_choice == "ADD": drinks_dict = add_data("drink", drinks_dict) elif editing_choice == "REMOVE": drinks_dict = remove_data("drink", drinks_dict) elif user_selection == 6: preferences_dict = table_to_dict("preference") os.system("clear") preferences_data = ids_to_data(preferences_dict, people_dict, drinks_dict) draw_table("preferences", preferences_data, 2) elif user_selection == 7: os.system("clear") preferences_data = ids_to_data(preferences_dict, people_dict, drinks_dict) draw_table("preferences", preferences_data, 2) editing_choice = edit_menu(edit_preferences_options) if editing_choice == "ADD/CHANGE": preferences_dict = add_entries(preferences_dict, "preferences", people_dict, drinks_dict) elif editing_choice == "REMOVE": preferences_dict = remove_entries(preferences_dict, "preferences", people_dict, drinks_dict) elif user_selection == 8: os.system("clear") last_order_dict = round_menu(edit_round_options, people_dict, drinks_dict, last_order_dict) elif user_selection == 9: last_order_dict = table_to_dict("orders") os.system("clear") last_order_data = ids_to_data(last_order_dict, people_dict, drinks_dict) draw_table("orders", last_order_data, 2) elif user_selection == 10: exit_screen() user_exit = True if user_selection != 10: input("Press ENTER to return to the Main Menu.") except Exception as err: print("Error") print(err)