def run(): options = ["Display data as a table", "Add new data", "Remove data", "Update", "Get amount of games by each manufactor", "Get amount of games by manufacture"] table_titles = ["id", "title", "manufacturer", "price", "in_stock"] choice = None while choice != "0": terminal_view.print_menu("Store manager menu ", options, "Go back to main menu") inputs = terminal_view.get_inputs(["Please enter a number: "], "") choice = inputs[0] #reading data from file data_table = data_manager.get_table_from_file("model/store/games.csv") if choice == "1": terminal_view.print_table(data_table, table_titles) elif choice == "2": table_titles.pop(0) store.add(data_table, table_titles) elif choice == "3": store.remove(data_table, get_user_id("remove")) elif choice == "4": store.update(data_table, get_user_id("update"), common.get_user_record(table_titles[1:])) elif choice == "5": sales_controller.run() elif choice == "6": crm_controller.run() elif choice == "0": root_controller.run() else: terminal_view.print_error_message("There is no such choice.")
def basic_submenu(): title = "Store manager\n" options = [ "(1) View table", "(2) Add to table", "(3) Remove from table", "(4) Update table", "(6) Return to main menu" ] argument = None choice = None while argument != "0": choice = terminal_view.get_choice(options) if choice == "1": store.show(table) elif choice == "2": store.add(table, record) elif choice == "3": store.remove(table, id_) elif choice == "4": store.update(table, id_, record) elif choice == "6": os.system('cls||clear') root_controller.run() else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ common.clear() title = 'Store menu' options = [ "Add new record to table", "Remove a record with a given id from the table.", "Updates specified record in the table.", "How many different kinds of game are available of each manufacturer?", "What is the average amount of games in stock of a given manufacturer?" ] exit_message = "Back to main menu" title_list = ["ID", "TITLE", "MANUFACTURER", "PRICE", "IN STOCK"] table = store.data_manager.get_table_from_file('model/store/games.csv') choice = None while choice != "0": terminal_view.print_table(table, title_list) choice = terminal_view.get_choice(title, options, exit_message) if choice == "1": record = terminal_view.get_inputs( title_list, 'Please add following informations :', table) updated_table = store.add(table, record) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "2": id_ = terminal_view.get_inputs(['Id'], 'Please give ID to remove :', table) updated_table = store.remove(table, id_) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "3": id_ = terminal_view.get_inputs(['Id'], 'Please give ID of changed line :', table) record = terminal_view.get_inputs( title_list, 'Please add following informations :', table) updated_table = store.update(table, id_, record) store.data_manager.write_table_to_file('model/store/games.csv', updated_table) common.exit_prompt() common.clear() elif choice == "4": label = "The kinds of game that are available of each manufacturer: " result = store.get_counts_by_manufacturers(table) terminal_view.print_result(result, label) common.exit_prompt() common.clear() elif choice == "5": manufacturer = terminal_view.get_inputs( ['Manufacturer : '], 'Please select a manufacturer :') manufacturer = manufacturer[0] result = str(store.get_average_by_manufacturer( table, manufacturer)) label = "The average amount of games in stock of {} ".format( manufacturer) terminal_view.print_result(result, label) common.exit_prompt() common.clear() elif choice != 0: terminal_view.print_error_message("There is no such choice.")
def test_update_record(self): table = data_manager.get_table_from_file(self.data_file) expected_updated_record = ["kH34Ju#&", 'x', 'x', 'x', 'x'] updated_data_row = ['x', 'x', 'x', 'x'] store.update(table, "kH34Ju#&", updated_data_row) self.assertListEqual(table[0], expected_updated_record)
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ title = "Store manager" options = ["Add item", "Remove item", "Update item", "Show how many different kinds of game are available of each manufacturer", "Show average amount of games in stock of a given manufacturer"] exit_message = "Back to main menu" title_list = [ ['Name'], ['Manufacturer'], ['Price'], ['Number in stock']] data_file = "model/store/games.csv" table = data_manager.get_table_from_file(data_file) terminal_view.print_table(table, title_list) choice = None while choice != "0": choice = terminal_view.get_choice(title, options, exit_message) if choice == "1": record = [] index = 0 inputs = terminal_view.get_inputs(title_list, title) for i in inputs: record.insert(index, i) index += 1 store.add(table, record) terminal_view.print_table(table, title_list) elif choice == "2": user_input = terminal_view.get_inputs(["Enter ID: "], "") store.remove(table, user_input[0]) terminal_view.print_table(table, title_list) elif choice == "3": record = [] index = 0 user_input = terminal_view.get_inputs(["Enter ID: "], "") inputs = terminal_view.get_inputs(title_list, title) for i in inputs: record.insert(index, i) index += 1 store.update(table, user_input[0], record) terminal_view.print_table(table, title_list) elif choice == "4": store.get_counts_by_manufacturers(table) terminal_view.print_result(store.get_counts_by_manufacturers( table), 'how many different kinds of game are available of each manufacturer: ') elif choice == "5": user_input = input('Enter manufacturer:') store.get_average_by_manufacturer(table, user_input) terminal_view.print_result(store.get_average_by_manufacturer( table, user_input), 'Average amount of games in stock. Manufacturer: ' + user_input) else: terminal_view.print_error_message("You have chosen back to menu.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ _FILENAME = 'model/store/games.csv' _options = [ "Add a new game", "Remove a game", "Update a game", "See count of games for each manufacturer", "See the average games stock for an specific manufacturer" ] title_list = ['Id', 'Title', 'Manufacturer', 'Price', 'Stock'] is_running = True while is_running is True: table = common.get_table(_FILENAME) choice = terminal_view.get_choice('Store menu', _options, 'Back to main menu') if choice == "1": game = terminal_view.get_inputs( ['Title', 'Manufacturer', 'Price', 'in stock'], 'Please provide game information') updated_table = store.add(table, game) common.write_table(updated_table, _FILENAME) elif choice == "2": terminal_view.print_table(table, title_list) index = terminal_view.get_inputs( ['Choose Id of the game to be removed: '], '') id_ = common.find_id(table, int(index[0])) updated_table = store.remove(table, id_) common.write_table(updated_table, _FILENAME) elif choice == "3": terminal_view.print_table(table, title_list) index = terminal_view.get_inputs( ['Choose Id of the game to be edited: '], '') id_ = common.find_id(table, int(index[0])) game = terminal_view.get_inputs( ['Title', 'Manufacturer', 'Price', 'in stock'], 'Please provide updated information for this game: ') updated_table = store.update(table, id_, game) common.write_table(updated_table, _FILENAME) elif choice == "4": count = store.get_counts_by_manufacturers(table) terminal_view.print_result( count, 'Count of games available for each manufacturer: ') elif choice == "5": manufacturer = terminal_view.get_inputs(['Manufacturer: '], '') average_stock = store.get_average_by_manufacturer( table, manufacturer[0]) terminal_view.print_result(str(average_stock), 'Average game stock: ') elif choice == "0": is_running = False else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ table = store.get_store_table_from_file() title_list = ["ID", "Title", "Manufacturer", "Price [$]", "In stock"] options = [ "View records", "Add record", "Remove record", "Update record", "How many different kinds of game are available of each manufacturer?", "What is the average amount of games in stock of a given manufacturer?" ] choice = None while choice != "0": choice = terminal_view.get_choice_inner_menu(options, "Store manager") if choice == "1": terminal_view.print_table(table, title_list) elif choice == "2": record = terminal_view.get_inputs(title_list[1::], "Please provide new item data") if record[2].isdigit() and record[3].isdigit(): table = store.add(table, record) else: terminal_view.print_error_message("Wrong input!") elif choice == "3": id_to_delete_table = terminal_view.get_inputs(["ID"], "Item to delete") id_to_delete = id_to_delete_table[0] table = store.remove(table, id_to_delete) elif choice == "4": records = terminal_view.get_inputs(title_list, "Edit item") record_id = records[0] table = store.update(table, record_id, records) elif choice == "5": amount_of_games = store.get_counts_by_manufacturers(table) list_from_dict = amount_of_games.items() manufacturer_count = ["MANUFACTURERS", "GAMES"] terminal_view.print_table(list_from_dict, manufacturer_count) elif choice == "6": choose_manufacturer = terminal_view.get_inputs([ "Manufacturer" ], "For which manufacturer would you like to check the average amount of games in stock?" ) manufacturer = choose_manufacturer[0] avg_amount = store.get_average_by_manufacturer(table, manufacturer) while avg_amount == False: choose_manufacturer = terminal_view.get_inputs( ["Put existing manufacturer"], "No such manufacturer in list:") manufacturer = choose_manufacturer[0] avg_amount = store.get_average_by_manufacturer( table, manufacturer) title_two = ["Manufacturer", "Average amount of games in stock"] table_two = [[manufacturer, str(avg_amount)]] terminal_view.print_table(table_two, title_two) elif choice != "0": terminal_view.print_error_message("There is no such choice.")
def run(): terminal_view.clear() options = [ "Print list", "Add record", "Update record", "Remove record", "Get counts by manufacturers", "Get averege by manufacturer", "Get oldest game", "Get chepest game", "Get age by", "Get game by" ] file_list = "./model/store/games.csv" list_labels = [ 'id: ', 'title: ', 'manufacturer: ', 'price: ', 'release_date (yyyy-mm-dd): ' ] remove = [''] choice = None while choice != "0": choice = terminal_view.get_choice('GAMES MENU', options) terminal_view.clear() if choice == "1": terminal_view.print_table( data_manager.get_table_from_file(file_list), 'GAMES list') elif choice == "2": store.create( data_manager.get_table_from_file(file_list), terminal_view.get_inputs(list_labels, 'Enter personal data here:', file_list), file_list) elif choice == "3": store.update( data_manager.get_table_from_file(file_list), terminal_view.get_inputs( remove, 'Enter id, name or e-mail to update: ', ''), terminal_view.get_inputs(list_labels[1:], 'Enter id, name or e-mail to remove', file_list), file_list) elif choice == "4": store.delete( data_manager.get_table_from_file(file_list), terminal_view.get_inputs( remove, 'Enter id, name or e-mail to remove: ', ''), file_list) elif choice == "5": terminal_view.print_table( store.get_counts_by_manufacturers( data_manager.get_table_from_file(file_list)), 'The record is') elif choice == "6": terminal_view.print_result( store.get_average_by_manufacturer( data_manager.get_table_from_file(file_list), terminal_view.get_inputs(remove, 'Enter the game title', '')), 'Average by manufacturer: ') elif choice == "7": terminal_view.print_result( store.get_oldest_game( data_manager.get_table_from_file(file_list)), 'Get the oldest game') elif choice == "8": terminal_view.print_result( store.get_cheapest_game( data_manager.get_table_from_file(file_list)), 'Get the the cheapest game') elif choice == "9": terminal_view.print_result( store.get_age_by( terminal_view.get_inputs(remove, 'Enter the game title', ''), data_manager.get_table_from_file(file_list), terminal_view.get_inputs(remove, 'Enter the current year: ', '')), 'The age is: ') elif choice == "10": terminal_view.print_table( store.get_game_by( terminal_view.get_inputs(remove, 'Enter the game title', ''), data_manager.get_table_from_file(file_list)), 'The game is/are: ') else: terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ options = [ "Add new record to table", "Remove a record with a given id from the table", "Update specified record in the table", "Number of different kinds of game that are available of each manufacturer", "Average amount of games in stock of a given manufacturer", "Print table" ] title_list = ["*id", "* title", "* manufacturer", "* price", "* in_stock"] os.system('clear') choice = None while choice != "0": terminal_view.print_menu("What do you want to do:", options, "Back to main menu") choice = terminal_view.get_choice(options) os.system('clear') if choice == "1": # to jest dzialajacy plik model/store/games.csv file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) record = terminal_view.get_inputs(title_list, "Enter data: ") table = store.add(table, record) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been added ***') common.waiting() os.system("clear") elif choice == "2": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) id_ = common.get_input("Get id to removed: ") table = store.remove(table, id_) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been removed ***') common.waiting() os.system("clear") elif choice == "3": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) id_ = common.get_input("Enter id to update: ") record = terminal_view.get_inputs(title_list, "Enter data: ") table = store.update(table, id_, record) common.write_table_to_file(file_name, table) os.system("clear") terminal_view.gprint('*** Record has been updated ***') common.waiting() os.system("clear") elif choice == "4": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) dictionary = store.get_counts_by_manufacturers(table) terminal_view.print_dictionary( "Number of different kinds of game that are" + "available of each manufacturer:", dictionary) common.waiting() os.system("clear") elif choice == "5": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) manufacturer = common.get_input("Enter a manufacturer: ") print(store.get_average_by_manufacturer(table, manufacturer)) common.waiting() os.system("clear") elif choice == "6": file_name = common.get_input("Choose a file: ") if file_name == "": file_name = "model/store/games.csv" table = common.get_table_from_file(file_name) terminal_view.print_table(table, title_list) common.waiting() os.system("clear") else: if choice != "0": terminal_view.print_error_message("There is no such choice.")
def run(): """ Starts this module and displays its menu. * User can access default special features from here. * User can go back to main menu from here. Returns: None """ list_of_games = store.get_data_to_list() # your code options = [ "Add new record", "Remove a record", "Update record", "Count games each manufacturer", "Average of games", "Print table" ] choice = None title_list = ["ID", "TITLE", "MANUFACTURER", "PRICE", "IN STOCK"] while choice != "0": choice = terminal_view.get_choice(options, "Back to main menu") if choice == "1": new_record = terminal_view.get_inputs( ["Title: ", "Manufacturer: ", "Price: ", "In stock: "], "Please enter value: ") new_record.insert(0, store.get_random_id(list_of_games)) list_of_games = store.add(list_of_games, new_record) elif choice == "2": id_of_record_to_remove = ask_untill_correct(list_of_games) list_of_games = store.remove( list_of_games, common.check_id_by_number(list_of_games, int(id_of_record_to_remove))) elif choice == "3": id_of_record_to_update = ask_untill_correct(list_of_games) updated_record = terminal_view.get_inputs( ["Title: ", "Manufacturer: ", "Price: ", "In stock: "], "Please enter value: ") list_of_games = store.update( list_of_games, common.check_id_by_number(list_of_games, int(id_of_record_to_update)), updated_record) elif choice == "4": label = "The kinds of game that are available of each manufacturer: " result = store.get_counts_by_manufacturers(list_of_games) terminal_view.print_result(result, label) elif choice == "5": manufacturer = terminal_view.get_inputs( ['Manufacturer : '], 'Please select a manufacturer :') manufacturer = manufacturer[0] result = str( store.get_average_by_manufacturer(list_of_games, manufacturer)) label = "The average amount of games in stock of {} ".format( manufacturer) terminal_view.print_result(result, label) elif choice == '6': terminal_view.print_table(list_of_games, title_list) elif choice == "0": store.export_list_to_file(list_of_games) else: terminal_view.print_error_message("There is no such choice.")