def round_user_input(people_list): end_loop = False while not end_loop: try: os.system("clear") tab.print_table_list("Users", people_list) owner_name = input("Enter Round Owner's name: ").capitalize() if not owner_name or owner_name.isspace(): print("You have entered nothing!") nav.try_again() elif any(num in owner_name for num in "0123456789"): print("No numbers can be included in name.") nav.try_again() elif owner_name not in people_list: print("Only an existing user can be the owner of a round.") nav.try_again() else: end_loop = True end_loop2 = False brewer_name = input("Enter Brewer's name: ").capitalize() if not brewer_name or brewer_name.isspace(): print("You have not entered anything!") nav.try_again() elif any(num in brewer_name for num in "0123456789"): print("No numbers can be included in name.") nav.try_again() else: end_loop2 = True end_loop3 = False active = input("""Enter a round active status. [1] No or [2] Yes Please enter a number: """) if not active or active.isspace(): print("You have not entered anything!") nav.try_again() elif active.isnumeric() == True: if 0 < int(active) < 3: if int(active) == 1: active = "No" else: active = "Yes" confirmation = nav.confirm() if confirmation: com.add_round(owner_name, brewer_name, active) else: print("No changes have been made.") end_loop3 = True else: print( "You have not entered a valid number. Please enter a number between 1 or 2." ) nav.try_again() else: print("Please enter a number only.") nav.try_again() except ValueError: print("No valid input.") nav.try_again()
def user_input(): "User input interface for menu." #loading data from database sql.load_data_from_sql() people_list = sql.people_list drinks_list = sql.drinks_list #loading from CSV files using ClASS FUNCTIONS drinks_file = File_Store(drinks_filepath) #drinks_list = drinks_file.load_into_list() people_file = File_Store(people_filepath) #people_list = people_file.load_into_list() preferences_file = File_store_dict(preferences_filepath) preferences = preferences_file.load_into_dict() menu_options_file = File_Store(menu_options_filepath) menu_options_list = menu_options_file.load_into_list() round_file = rd.File_store_round(round_filepath) all_rounds_list = round_file.load_file_to_dict_round() end_loop = False while not end_loop: try: os.system("clear") print_counter_var_table("BrewCo Options Menu :)", "number", "options", menu_options_list) print(" Welcome to BrewCo!") choice = num_selection("Select an option by entering a number: ") if choice == 2: os.system("clear") print_table_list("Users", people_list) hold() elif choice == 3: os.system("clear") print_table_list("Drinks", drinks_list) hold() elif choice == 6: os.system("clear") print("Add a new User?") confirmation = confirm() if confirmation: os.system("clear") print_table_list("Users", people_list) person = input( """Here are the users currently in our database. Please use an unique name. Enter a new user's name: """) confirmation = confirm() if confirmation: people_list = add_list_element(people_list, person) else: print("No changes have been made.") pass else: pass hold() elif choice == 10: os.system("clear") print("Remove an User?") confirmation = confirm() if confirmation: os.system("clear") print_counter_var_table("User database", "id", "name", people_list) person_id = num_selection( """Here are the people in our database. Note: Both the user and their preference (if one exists) will be removed. Enter user's I.D. number to remove them: """) if 0 < person_id <= len(people_list): name = people_list[person_id - 1] print(f"{name} will be removed from the database.") confirmation = confirm() if confirmation: people_list = remove_list_element( people_list, name) if name in preferences.keys(): preferences.pop(name) else: pass else: print("No changes have been made.") pass else: print("Please enter a valid number. Try again.") else: pass hold() elif choice == 7: os.system("clear") print("Add a new drink?") confirmation = confirm() if confirmation: os.system("clear") print_table_list("Drink Selection", drinks_list) drink = input( """Here is the currently available drinks selection. Enter a new drink option: """) confirmation = confirm() if confirmation: drinks_list = add_list_element(drinks_list, drink) for key, value in preferences.items(): if drink + " (discontinued)" == value: preferences[key] = drink else: pass else: print("No changes have been made.") pass else: pass hold() elif choice == 11: os.system("clear") print("Remove a drink?") confirmation = confirm() if confirmation: os.system("clear") print_counter_var_table("Available Drinks Selection", "i.d.", "drink", drinks_list) drink_id = num_selection( """Here are all the drinks available currently. Enter the drink's I.D. number to remove it: """) if 0 < drink_id <= len(drinks_list): drink_name = drinks_list[drink_id - 1] print( f"{drink_name} will be removed from the database and no longer available." ) confirmation = confirm() if confirmation: drinks_list = remove_list_element( drinks_list, drink_name) for name, drink in preferences.items(): if drink_name == drink: preferences[ name] = drink + " (discontinued)" else: pass else: print("No changes have been made.") pass else: print("Please enter a valid number. Try again.") else: pass pass hold() elif choice == 8: os.system("clear") print("Add a new User preference?") confirmation = confirm() if confirmation: os.system("clear") preferences = user_add_pref(people_list, drinks_list, preferences) else: pass hold() elif choice == 12: os.system("clear") print("Remove an User preference?") confirmation = confirm() if confirmation: os.system("clear") user_remove_pref(preferences) else: pass hold() elif choice == 4: os.system("clear") print_table_dict("User Preferences", "name", "favourite drink", preferences) hold() elif choice == 5: os.system("clear") rd.print_all_rounds_table(all_rounds_list, "All Rounds", "Round ID", "Owner", "Brewer", "Active Status") hold() elif choice == 9: os.system("clear") print("Begin a new round?") confirmation = confirm() if confirmation: all_rounds_list = rd.round_user_input(people_list) else: pass hold() elif choice == 1: drinks_file.save_list_to_file(drinks_list) people_file.save_list_to_file(people_list) preferences_file.save_dict_to_file(preferences) round_file.save_all_rounds_to_file(all_rounds_list) drinks_file = File_Store(drinks_filepath) people_file = File_Store(people_filepath) drinks_file.save_list_to_file(drinks_list) people_file.save_list_to_file(people_list) sql.load_from_csv_to_sql() os.system("clear") print(f"Thanks for using the app!{cat}") end_loop = True #while loop termination condition or exit() elif choice > len(menu_options_list) or choice < 1: print("Not a valid number. Try again") hold() except ValueError: print("Please enter a number. Try again") hold()
def user_input(): "User input interface for menu." end_loop = False while not end_loop: try : #loading data from database people_list, drinks_list, preferences, all_rounds_object_list = db_persist.load_data_from_sql() menu_options_file = File_Store_list(menu_options_filepath) menu_options_list = menu_options_file.load_into_list() os.system("clear") print_menu_options( menu_options_list) print("Welcome to BrewCo!") choice = num_selection("Select an option by entering a number: ") if choice == 2: os.system("clear") print_table_list("Users", people_list) hold() elif choice == 3: os.system("clear") print_table_list("Drinks", drinks_list) hold() elif choice ==7: os.system("clear") print("Add a new User?") confirmation = confirm() if confirmation: os.system("clear") print_table_list("Users", people_list) person = input("""Here are the users currently in our database. Please use an unique name. Enter a new user's name: """).capitalize() confirmation = confirm() if confirmation: #people_list = add_list_element(people_list, person) com.add_person(person) print(f"{person} has been added as an user!") else: print("No changes have been made.") pass else: pass hold() elif choice == 12: os.system("clear") print("Remove an User?") confirmation = confirm() if confirmation: os.system("clear") print_counter_var_table("User database","id","name", people_list) person_id = num_selection("""Here are the people in our database. Note: Both the user and their preference (if one exists) will be removed. Enter user's I.D. number to remove them: """) if 0 < person_id <= len(people_list): name = people_list[person_id-1] print(f"{name} will be removed from the database.") confirmation = confirm() if confirmation: com.remove_person(name) else: print("No changes have been made.") pass else: print("Please enter a valid number. Try again.") else: pass hold() elif choice ==8: os.system("clear") print("Add a new drink?") confirmation = confirm() if confirmation: os.system("clear") print_table_list("Drink Selection", drinks_list) drink = input("""Here is the currently available drinks selection. Enter a new drink option: """).capitalize() confirmation = confirm() if confirmation: com.add_drink(drink) else: print("No changes have been made.") pass else: pass hold() elif choice == 13: os.system("clear") print("Remove a drink?") confirmation = confirm() if confirmation: os.system("clear") print_counter_var_table("Available Drinks Selection", "i.d.", "drink",drinks_list) drink_id = num_selection("""Here are all the drinks available currently. Enter the drink's I.D. number to remove it: """) if 0 < drink_id <= len(drinks_list): drink_name = drinks_list[drink_id-1] print(f"{drink_name} will be removed from the database and no longer available.") confirmation = confirm() if confirmation: com.remove_drink(drink_name) print(f'{drink_name} has been removed from the drinks selection!') else: print("No changes have been made.") pass else: print("Please enter a valid number. Try again.") else: pass pass hold() elif choice ==9: os.system("clear") print("Add a new User preference?") confirmation = confirm() if confirmation: os.system("clear") com.user_add_pref(people_list, drinks_list, preferences) else: pass hold() elif choice == 14: os.system("clear") print("Remove an User preference?") confirmation = confirm() if confirmation: os.system("clear") com.user_remove_pref(preferences) else: pass hold() elif choice == 4: os.system("clear") print_table_dict("User Preferences", "name", "favourite drink", preferences) hold() elif choice == 5: os.system("clear") longest_col1 = tab.long_col1(all_rounds_object_list) longest_col2 = tab.long_col2(all_rounds_object_list) longest_col3 = tab.long_col3(all_rounds_object_list) longest_col4 = tab.long_col4(all_rounds_object_list) width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4) tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4) hold() elif choice == 10: os.system("clear") print("Begin a new round?") confirmation = confirm() if confirmation: com.round_user_input(people_list) else: pass hold() elif choice ==6: os.system("clear") print("See a round's order history?") confirmation = confirm() if confirmation: os.system("clear") longest_col1 = tab.long_col1(all_rounds_object_list) longest_col2 = tab.long_col2(all_rounds_object_list) longest_col3 = tab.long_col3(all_rounds_object_list) longest_col4 = tab.long_col4(all_rounds_object_list) width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4) tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4) com.user_see_round_history( all_rounds_object_list) else: pass hold() elif choice == 11: os.system("clear") print("Add an order to a round?") confirmation = confirm() if confirmation: longest_col1 = tab.long_col1(all_rounds_object_list) longest_col2 = tab.long_col2(all_rounds_object_list) longest_col3 = tab.long_col3(all_rounds_object_list) longest_col4 = tab.long_col4(all_rounds_object_list) width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4) tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4) com.user_add_order_to_round(all_rounds_object_list, people_list, drinks_list) else: pass hold() elif choice == 15: os.system("clear") print("Remove a round?") confirmation = confirm() if confirmation: os.system("clear") longest_col1 = tab.long_col1(all_rounds_object_list) longest_col2 = tab.long_col2(all_rounds_object_list) longest_col3 = tab.long_col3(all_rounds_object_list) longest_col4 = tab.long_col4(all_rounds_object_list) width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4) tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4) com.user_remove_round(all_rounds_object_list) else: pass hold() elif choice ==16: os.system("clear") print("Remove an order from round?") confirmation = confirm() if confirmation: os.system("clear") longest_col1 = tab.long_col1(all_rounds_object_list) longest_col2 = tab.long_col2(all_rounds_object_list) longest_col3 = tab.long_col3(all_rounds_object_list) longest_col4 = tab.long_col4(all_rounds_object_list) width = tab.all_rounds_table_width("All Rounds","Round ID","Owner","Brewer","Active Status", longest_col1, longest_col2, longest_col3, longest_col4) tab.print_all_rounds_table(all_rounds_object_list,"All Rounds","Round ID","Owner","Brewer","Active Status", width, longest_col1, longest_col2, longest_col3, longest_col4) com.remove_order_from_round(all_rounds_object_list) else: pass hold() elif choice == 1: os.system("clear") print(f"Thanks for using the app!{cat}") end_loop = True #while loop termination condition or exit() elif choice > len(menu_options_list) or choice < 1: print("Not a valid number. Try again") hold() except ValueError: print("Please enter a number. Try again") hold()
def user_add_order_to_round(object_list, people_list, drinks_list): round_id_list = [] for obj in object_list: round_id_list.append(obj.round_id) end_loop = False while not end_loop: round_num = input( "Choose whose round would you like to add a new order to. Enter their round id: " ) if not round_num or round_num.isspace(): print("You have not entered anything!") nav.try_again() elif round_num.isnumeric() == False: print("Enter only a positive whole number.") nav.try_again() elif round_num not in round_id_list: print("Please enter a valid round id number.") nav.try_again() else: end_loop = True end_loop3 = False os.system("clear") owner = "" for obj in object_list: if obj.round_id == round_num: owner = obj.owner print(f"Adding to {owner}\'s round. \n") tab.print_table_list("Users", people_list) print("Here are all the existing users: ") while not end_loop3: name = input( "Enter the name of the person adding the order from existing users: " ).capitalize() if not name or name.isspace(): print("You have not entered anything!") nav.try_again() elif any(num in name for num in "0123456789"): print("Names can not contain any numbers.") nav.try_again() elif name not in people_list: print( "Sorry, only an existing user can add an order to a round." ) nav.try_again() else: end_loop3 = True end_loop = True end_loop4 = False os.system("clear") for obj in object_list: if obj.round_id == round_num: long_col1 = tab.long_col1_round_history( obj.round_history) long_col2 = tab.long_col2_round_history( obj.round_history) long_col3 = tab.long_col3_round_history( obj.round_history) width = tab.round_history_table_width( f"{obj.owner}\'s round", "Order ID", "Name", "Drink", long_col1, long_col2, long_col3) tab.print_round_history(obj.round_history, width, f"{obj.owner}\'s round", "Order ID", "Name", "Drink", long_col1, long_col2, long_col3) print(f"Here is {owner}\'s current round histroy.") tab.print_table_list("Drinks", drinks_list) print("Here are the available drinks.") while not end_loop4: drink = input("Choose a drink to add to the round: " ).capitalize() if not drink or drink.isspace(): print("You have not entered anything!") nav.try_again() elif any(num in drink for num in "0123456789"): print("Drink names can not contain numbers.") nav.try_again() elif drink not in drinks_list: print( "Sorry this drink is not available. Please choose from the available drinks." ) nav.try_again() else: end_loop4 = True end_loop3 = True end_loop = True os.system("clear") print(f"Add {drink} order to {owner}\'s round?") confirmation = nav.confirm() if confirmation: for obj in object_list: if obj.round_id == round_num: com.add_order_to_round( round_num, owner, name, drink) else: print("No changes have been made.") end_loop = True
def user_add_order_to_round(object_list, people_list, drinks_list): round_id_list = [] for obj in object_list: round_id_list.append(obj.round_id) end_loop = False while not end_loop: round_num = input( "Choose whose round would you like to add a new order to. Enter their round id: " ) if not round_num or round_num.isspace(): print("You have not entered anything!") nav.try_again() elif round_num.isnumeric() == False: print("Enter only a positive whole number.") nav.try_again() elif round_num not in round_id_list: print("Please enter a valid round id number.") nav.try_again() else: owner = "" for obj in object_list: if obj.round_id == round_num: owner = obj.owner order_id_list = [] for my_order in obj.round_history: order_id_list.append(my_order["OrderID"]) end_loop = True end_loop2 = False os.system("clear") for obj in object_list: if obj.round_id == round_num: long_col1 = long_col1_round_history(obj.round_history) long_col2 = long_col2_round_history(obj.round_history) long_col3 = long_col3_round_history(obj.round_history) width = round_history_table_width(f"{obj.owner}\'s round", "Order ID", "Name", "Drink", long_col1, long_col2, long_col3) print_round_history(obj.round_history, width, f"{obj.owner}\'s round", "Order ID", "Name", "Drink", long_col1, long_col2, long_col3) while not end_loop2: order_id = input("To add a new order, enter a new order id: ") if not order_id or order_id.isspace(): print("You have not entered anything!") nav.try_again() elif order_id.isnumeric() == False: print("Enter only a positive whole number.") nav.try_again() elif int(order_id) < 1: print( "Please choose a positive whole number for order id.") nav.try_again() elif isinstance(int(order_id), float) == True: print("Please choose only a whole number for order id.") nav.try_again() elif order_id in order_id_list: print( "Order id number already assigned. Please choose another id number." ) nav.try_again() else: end_loop2 = True end_loop = True end_loop3 = False os.system("clear") tab.print_table_list("Users", people_list) print("Here all the existing users.") while not end_loop3: name = input( "Enter the name of the person adding the order: " ).capitalize() if not name or name.isspace(): print("You have not entered anything!") nav.try_again() elif any(num in name for num in "0123456789"): print("Names can not contain any numbers.") nav.try_again() elif name not in people_list: print( "Sorry, only an existing user can add an order to a round." ) nav.try_again() else: end_loop3 = True end_loop2 = True end_loop = True end_loop4 = False os.system("clear") tab.print_table_list("Drinks", drinks_list) print( "Here are all the drinks that are available.") while not end_loop4: drink = input( "Choose a drink to add to the round: " ).capitalize() if not drink or drink.isspace(): print("You have not entered anything!") nav.try_again() elif any(num in drink for num in "0123456789"): print( "Drink names can not contain numbers.") nav.try_again() elif drink not in drinks_list: print( "Sorry this drink is not available. Please choose from the available drinks." ) nav.try_again() else: end_loop4 = True end_loop3 = True end_loop2 = True end_loop = True os.system("clear") print( f"Add {drink} order to {owner}\'s round?" ) confirmation = nav.confirm() if confirmation: for obj in object_list: if obj.round_id == round_num: #add to orders table so order id created there obj.add_to_round( order_id, name, drink) print( f"The order has been added to {obj.owner}\'s round!" ) else: print("No changes have been made.") end_loop = True