def choose(): inputs = ui.get_inputs(["Please enter a number"], "") option = inputs[0] table = data_manager.get_table_from_file(FILE_NAME) common.add_short_id(table) if option == "1": show_table(table) elif option == "2": table = add(table) elif option == "3": update(table, ui.get_id()) # id_ z funkcji z common elif option == "4": table = remove(table, ui.get_id()) elif option == "5": longest_name_id = get_longest_name_id(table) ui.print_result(longest_name_id, 'Longest name id\n') elif option == "6": newsletter_customers = get_subscribed_emails(table) ui.print_result(newsletter_customers, 'Customers with newsletter subscription\n') elif option == "0": return False else: raise KeyError("There is no such option") common.remove_short_id(table) data_manager.write_table_to_file(FILE_NAME, table) return True
def delete_recipe(): get_id = ui.get_id() try: rows_deleted = db.delete_recipe_by_id(get_id) ui.message(f"Successfully deleted {rows_deleted} row\n") except peewee.DoesNotExist: ui.message("The record you are trying to delete doesn't exist. ")
def update(table): """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: table with updated record """ show_table(table) id_ = ui.get_id() # get item by id # for each element in record: (excluding short id and full id:) # ask for new data # if new data is empty, do not update # else: update this data index = None for i, row in enumerate(table): if row[ID_INDEX] == id_ or row[SHORT_ID_INDEX] == id_: index = i break if index is not None: buffer = ui.update_element(table[index][NAME_INDEX], 'name') table[index][NAME_INDEX] = buffer.strip() buffer = ui.update_element(table[index][AGE_INDEX], 'birth year') if common.is_year(buffer): table[index][AGE_INDEX] = buffer return table
def update(table): """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: table with updated record """ show_table(table) index = common.find_by_id(table, ui.get_id()) if index is not None: buffer = ui.update_element(table[index][NAME], 'Item name') table[index][NAME] = buffer.strip() buffer = ui.update_element(table[index][MANUFACTURER], 'Manufacturer name') table[index][MANUFACTURER] = buffer.strip() buffer = ui.update_element(table[index][DATE], 'Purchase date') if common.is_positive_int(buffer): table[index][DATE] = buffer buffer = ui.update_element(table[index][DURABILITY], 'Durability (years)') if common.is_positive_int(buffer): table[index][DURABILITY] = buffer return table
def event_sale_records(): '''Get Event ID # from user, then query for results''' #show list of events for user reference (they probably haven't memorized event ID #'s) event_list = merch_orm.event_list() ui.show_event_list(event_list) #get event id from user id = ui.get_id() #TODO query db for sales information based on Event ID # merch_orm.sales_by_eventID(id)
def merch_sale_records(): '''Get Merch ID # from user, then query for results''' #show list of merch items for user reference (they probably haven't memorized merch ID #'s) merch_list = merch_orm.merch_list() ui.show_list(merch_list) #get merch id from user id = ui.get_id() #TODO query db for sales information based on Merch ID # merch_orm.sales_by_merchID(id)
def remove(table): """ Remove a record with a given id from the table. Args: table: table to remove a record from id_ (str): id of a record to be removed Returns: Table without specified record. """ show_table(table) id_ = ui.get_id() for i, row in enumerate(table): if row[ID_INDEX] == id_ or row[SHORT_ID_INDEX] == id_: del table[i] return table return table
def merch_sale_records(): '''Get Merch ID # from user, then query for results''' #show list of merch items for user reference (they probably haven't memorized merch ID #'s) merch_list = merch_orm.merch_list() ui.show_list(merch_list) #show list of sales for user reference sales_list = merch_orm.sales_list() ui.show_sales_list(sales_list) #get merch id from user print( 'To get total sales for a specific Merch item, enter Merch ID below:') id = ui.get_id() #query db for sales information based on Merch ID # merch_orm.sales_by_merchID(id)
def update(table): """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: table with updated record """ id_ = ui.get_id() element_index = None for i, row in enumerate(table): if row[ID_INDEX] == id_ or row[SHORT_ID_INDEX] == id_: element_index = i break if element_index is not None: table[element_index][NAME_INDEX] = ui.update_element(table[element_index][NAME_INDEX], 'name') table[element_index][EMAIL_INDEX] = ui.update_element(table[element_index][EMAIL_INDEX], 'e-mail') table[element_index][SUBSCRIBE_INDEX] = ui.update_element(table[element_index][SUBSCRIBE_INDEX], 'newsletter subscription') return table
def update(table): """ Updates specified record in the table. Ask users for new data. Args: table: list in which record should be updated id_ (str): id of a record to update Returns: table with updated record """ show_table(table) id_ = ui.get_id() # get item by id # for each element in record: (excluding short id and full id:) # ask for new data # if new data is empty, do not update # else: update this data index = None for i, row in enumerate(table): if row[ID] == id_ or row[SHORT_ID] == id_: index = i break if index is not None: buffer = ui.update_element(table[index][TITLE], 'Game title') table[index][TITLE] = buffer.strip() buffer = ui.update_element(table[index][MANUFACTURER], 'Manufacturer name') table[index][MANUFACTURER] = buffer.strip() buffer = ui.update_element(table[index][PRICE], 'Price') if common.is_positive_int(buffer): table[index][PRICE] = buffer buffer = ui.update_element(table[index][IN_STOCK], 'Amount in stock') if common.is_positive_int(buffer): table[index][IN_STOCK] = buffer return table