Exemplo n.º 1
0
def round_user_input(people_list):
    end_loop = False
    while not end_loop:
        try:
            os.system("clear")
            global round_id_list
            round_id_list = []
            for my_dict in all_rounds_list:
                round_id_list.append(my_dict["RoundID"])

            round_num = input("Enter a new Round ID number: ")
            #check if num already in all rounds
            if not round_num or round_num.isspace():
                print("You have not entered anything!")
                nav.try_again()
            elif round_num.isnumeric() == False:
                print("Please enter a number only.")
                nav.try_again()
            elif round_num in round_id_list:
                print("Round ID number already has been assigned.")
                nav.try_again()
            else:
                owner = input("Enter Round Owner's name: ").capitalize()
                if not owner or owner.isspace():
                    print("You have entered nothing!")
                    nav.try_again()
                elif any(num in owner for num in "0123456789"):
                    print("No numbers can be included in name.")
                    nav.try_again()
                elif owner not in people_list:
                    print("Only an User can be the owner of a round.")
                    nav.try_again()
                else:
                    #add can only be from user table constraint
                    brewer = input("Enter Brewer's name: ").capitalize()
                    #anyone right now
                    active = input("Enter a round active status, Yes or No: "
                                   ).capitalize()
                    #activation constraint of must be yes or no
                    confirmation = nav.confirm()
                    if confirmation:
                        owner = Round_Handler(round_num, owner, brewer, active)
                        round_dict = {
                            'RoundID': owner.round_id,
                            'Owner': owner.owner,
                            'Brewer': owner.brewer,
                            'ActiveStatus': owner.active_status
                        }
                        all_rounds_list.append(round_dict)
                        print(
                            f"{owner.owner}\'s new round has been successfully created!"
                        )
                    else:
                        print("No changes have been made.")
                        pass
                    end_loop = True
        except ValueError:
            print("No valid input.")
            nav.try_again()
    return all_rounds_list
Exemplo n.º 2
0
def user_remove_pref(my_dict):
    """Removes key:value pair, specified through user input, from specified dictionary."""
    tab.print_table_dict("Preferences", "names", "favourite drink", my_dict)
    try:
        person_name = input("""Here are the available people on our list.
Choose the person whose preference you want to remove.
Enter their name please: """)
        if not person_name or person_name.isspace():
            print("You have not entered in anything!")
        elif person_name.capitalize() not in my_dict.keys():
            print(
                f"{person_name.capiltalize()} does not have a preference already."
            )
        elif any(num in person_name for num in "01234567890"):
            print(f"No numbers can be included. Try again.")
        elif person_name.capitalize() in my_dict.keys():
            print(
                f"""{person_name.capitalize()}'s drink preference will be removed."""
            )
            confirmation = confirm()
            if confirmation:
                remove_from_dict(my_dict, person_name)
            else:
                print("No changes have been made.")
                pass
    except ValueError:
        print("Not a valid input!")
        input("Enter any key to try again: ")
    return my_dict
Exemplo n.º 3
0
def user_remove_round(object_list):
    print("Here are all the rounds in our database.")
    end_loop = False
    while not end_loop:
        try:
            global round_id_list
            round_id_list = []
            for obj in object_list:
                round_id_list.append(obj.round_id)
            round_num = input(
                """Enter the round id number of the round you want to remove: """
            )
            if not round_num or round_num.isspace():
                print("You have not entered anything!")
                nav.try_again()
            elif round_num.isnumeric() == False:
                print("Please enter a number only.")
                nav.try_again()
            elif round_num not in round_id_list:
                print("Please enter round id number of an existing round.")
                nav.try_again()
            else:
                for obj in object_list:
                    if obj.round_id == round_num:
                        confirmation = nav.confirm()
                        if confirmation:
                            com.remove_round(obj.owner, round_num)
                        else:
                            print("No changes have been made.")
                        end_loop = True
        except ValueError:
            print("No valid input.")
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
def user_add_pref(my_list1, my_list2, my_dict):
    """ Appends to the specified dictionary, through user inputs, a chosen element from each list
as a key and value respectively. """
    end_loop = False
    while not end_loop:
        try:
            tab.print_counter_var_table("Preferences", "id_number", "names",
                                        my_list1)
            person_id = num_selection(
                """Here are the available people on our list.
Choose the person whose preference you want to change/add.
Enter their id number please: """)
            if 0 < person_id <= len(my_list1):
                try:
                    name = my_list1[person_id - 1]
                    tab.print_counter_var_table("Available Drink Selection",
                                                "Number", "Drink", my_list2)
                    fav_drink_num = input(
                        f"""Great! What is {name}\'s favourite drink? 
Select only from the available drinks menu. Enter a number: """)
                    if not fav_drink_num or fav_drink_num.isspace():
                        print("You have not entered anything!")
                        try_again()
                    elif fav_drink_num.isnumeric() == True:
                        if 0 < int(fav_drink_num) <= len(my_list2):
                            fav_drink = my_list2[int(fav_drink_num) - 1]
                            print(
                                f"""{fav_drink.capitalize()} will be added as {name.capitalize()}'s favourite drink! """
                            )
                            confirmation = confirm()
                            if confirmation:
                                add_to_dict(my_dict, name, fav_drink)
                            else:
                                print("No changes have been made.")
                                pass
                            end_loop = True
                        else:
                            print("Please enter a valid number.")
                            try_again()
                    else:
                        print(f"Please enter only a number.")
                        try_again()
                except ValueError:
                    print("Not a valid input!")
                    try_again()
            else:
                print("Not a valid id number.")
                try_again()
        except ValueError:
            print("You have not entered a number. Try again.")
            try_again()
    return my_dict
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
def remove_order_from_round(object_list):
    print("Here are all the rounds in our database.")
    end_loop = False
    while not end_loop:
        try:
            global round_id_list
            round_id_list = []
            for obj in object_list:
                round_id_list.append(obj.round_id)
            round_num = input(
                """Enter the round id number of the round, whose order history
 you would like to see and remove an order from: """)
            if not round_num or round_num.isspace():
                print("You have not entered anything!")
                nav.try_again()
            elif round_num.isnumeric() == False:
                print("Please enter a number only.")
                nav.try_again()
            elif round_num not in round_id_list:
                print("Please enter round id number of an existing round.")
                nav.try_again()
            else:
                for obj in object_list:
                    if obj.round_id == round_num:
                        global order_id_list
                        order_id_list = []
                        for order in obj.round_history:
                            order_id_list.append(order["OrderID"])
                        os.system("clear")
                        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)
                        order_num = input(
                            "Enter the order id number of the order you want to remove:  "
                        )
                        if not order_num or order_num.isspace():
                            print("You have not entered anything!")
                            nav.try_again()
                        elif order_num.isnumeric() == False:
                            print("Please enter a number only.")
                            nav.try_again()
                        elif order_num not in order_id_list:
                            print(
                                "Please enter order id number of an existing order."
                            )
                            nav.try_again()
                        else:
                            confirmation = nav.confirm()
                            if confirmation:
                                remove_order_from_round_db(
                                    obj.owner, round_num, order_num)
                            else:
                                print("No changes have been made.")
                            end_loop = True
        except ValueError:
            print("No valid input.")
Exemplo n.º 9
0
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
Exemplo n.º 10
0
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