def update(table, id_, record): """ Updates specified record in the table. Args: table: list in which record should be updated id_ (str): id of a record to update record (list): updated record Returns: list: table with updated record """ index_id = 0 record.insert(index_id, common.generate_random(table)) table.append(record) data_manager.write_table_to_file("model/hr/persons.csv", table) entry_index = 0 for entry in table: entry_id_ = entry[0] if entry_id_ == id_: del table[entry_index] entry_index += 1 return table
def run(): input_file = "resource/input/rawData3.txt" output_file = "resource/output/output3.txt" lines = data_manager.read_table_from_file(input_file) int_account_numbers = convert_line_account_numbers_to_int_account_numbers( lines) data_manager.write_table_to_file(output_file, int_account_numbers)
def update_employee(updated_employee_id, updated_employee_data): new_table = data_manager.read_table_from_file(DATAFILE) for employee in new_table: if employee[ID_INDEX] == updated_employee_id: updated_employee_data.insert(0, employee[ID_INDEX]) new_table[new_table.index(employee)] = updated_employee_data data_manager.write_table_to_file(DATAFILE, new_table, ";")
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 = "Human resources manager" options = [ "Add item", "Remove item", "Update item", "Show the oldest person", "Show person closest to average age" ] exit_message = "Back to main menu" title_list = [['Name'], ['Date of birth']] data_file = "model/hr/persons.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 hr.add(table, record) data_manager.write_table_to_file(data_file, table) terminal_view.print_table(table, title_list) elif choice == "2": user_input = terminal_view.get_inputs(["Enter ID: "], "") hr.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 hr.update(table, user_input[0], record) terminal_view.print_table(table, title_list) elif choice == "4": terminal_view.print_result(hr.get_oldest_person(table), "Oldest person") elif choice == "5": terminal_view.print_result( hr.get_persons_closest_to_average(table), "Person closest to average") else: terminal_view.print_error_message("You have chosen back to menu.")
def remove_record(record_id): table=data_manager.read_table_from_file(DATAFILE, separator=';') for n in range(0, len(table)): if table[n][0] == record_id: del table[n] data_manager.write_table_to_file(DATAFILE, table, separator=';') return table
def update_customer(update_info: list): customer_index = int(update_info[0]) data_index = int(update_info[1]) new_info = update_info(2) list_of_crm = crmcsv_to_list_of_lists() list_of_crm[customer_index][data_index] = new_info data_manager.write_table_to_file(DATAFILE, list_of_crm)
def add_transaction(customer: str, product: str, price: float) -> List[List[str]]: list_of_lists = sales_to_list_of_lists()[1:] date, _ = datetime.now().isoformat().split("T") new_transaction = [util.generate_id(), customer, product, str(price), date] list_of_lists.append(new_transaction) data_manager.write_table_to_file(FILE_NAME, list_of_lists) return list_of_lists
def modify_item(record_id, Customer, Product, Price, Date): table=data_manager.read_table_from_file(DATAFILE, separator=';') for n in range(0, len(table)): if table[n][0] == record_id: table[n]=[record_id, Customer, Product, Price, Date] print(table) data_manager.write_table_to_file(DATAFILE, table, separator=';') return table
def update_record(table, id, inputs, filename): counter = 0 update_id = None for item in table: if str(item[0]) in str(id): update_id = counter new_list = common.update(table, update_id, make_record(get_data(), inputs)) counter += 1 data_manager.write_table_to_file(filename, new_list)
def delete(table, id_, file_name): for line in table: id_s = ''.join(id_) if id_s in line: table.remove(line) print('Remove OK') else: pass data_manager.write_table_to_file(file_name, table) return table
def make_record_to_add(inputs): generated_id = common.generate_random(table) record = [] record.append(generated_id) for i in inputs: record.append(i) table_to_write = add(table, record) data_manager.write_table_to_file(file_name, table)
def make_update(inputs, file_name, id_, function_): table = data_manager.get_table_from_file(file_name) record = [] record.append(id_) for i in inputs: record.append(i) table_to_write = function_(table, id_, record) data_manager.write_table_to_file(file_name, table_to_write)
def update(table, id_, record, file_name): id_s = ''.join(id_) for line in table: if id_s in line: line[1:] = record print('Update OK') else: pass data_manager.write_table_to_file(file_name, table) return record
def delete_record(table, id, filename): s = "".join(id) counter = 0 remove_id = None for item in table: if str(item[0]) in str(s): remove_id = counter new_list = common.remove(table, remove_id) counter += 1 data_manager.write_table_to_file(filename, new_list)
def delete_transaction(id): transactions = get_transactions_list() for i in range(len(transactions)): if transactions[i][ID_TRANSACTION_INDEX] == id: transactions.pop(i) break data_manager.write_table_to_file(DATAFILE, transactions) return transactions # czy potrzebne?
def update_transaction(id, index, value): updated_transaction = [] transactions = data_manager.read_table_from_file(DATAFILE) for i in range(len(transactions)): if transactions[i][ID_TRANSACTION_INDEX] == id: transactions[i][index] = value updated_transaction.append(transactions[i]) data_manager.write_table_to_file(DATAFILE, transactions) return updated_transaction
def make_record_to_add(inputs, file_name, function_): table = data_manager.get_table_from_file(file_name) generated_id = generate_random(table) record = [] record.append(generated_id) for i in inputs: record.append(i) table_to_write = function_(table, record) data_manager.write_table_to_file(file_name, table_to_write)
def add_customer(): index_customer_name = 1 index_Id = 0 table = crm.get_table() Id = list(crm.get_Id()) name = view.get_input("Customer name: ") email = view.get_input("Customer email:") subscribtion = view.get_input("Is subscribed to the newsletter? 1: yes, 0: no:") table.insert(0, Id) view.print_table(table) data_manager.write_table_to_file("model/crm/crm.csv", table, separator= ';') return table
def delete_customer_account(id, name, email): customers = get_customers_list() for i in range(len(customers)): if customers[i][CUSTOMER_ID_INDEX] == id: customers.pop(i) elif customers[i][CUSTOMER_NAME_INDEX] == name: customers.pop(i) elif customers[i][EMAIL_INDEX] == email: customers.pop(i) data_manager.write_table_to_file(DATAFILE, customers)
def valid_input(list_of_transactions): user_input = view.get_input( "Do you want to save changes? Yes or No?").upper() if user_input == "YES" or user_input == "Y": data_manager.write_table_to_file(DATAFILE, list_of_transactions, separator=';') elif user_input == "NO" or user_input == "N": return user_input else: new_valid_input = valid_input(list_of_transactions) return new_valid_input
def add_item(link_to_csv, labels): new_record = terminal_view.get_inputs([ 'Name of item: ', 'Manufacturer: ', 'Year of purchase: ', 'Years it can be used: ' ], 'Please input information about platform: ') table = data_manager.get_table_from_file(link_to_csv) new_record.insert(0, model.common.generate_random(table)) ready_table = inventory.add(table, new_record) data_manager.write_table_to_file(link_to_csv, ready_table) terminal_view.print_table(ready_table, labels)
def update_customer_account(id, index, value): updated_customer = [] customers = get_customers_list() for i in range(len(customers)): if customers[i][CUSTOMER_ID_INDEX] == id: customers[i][index] = value updated_customer = customers[i] data_manager.write_table_to_file(DATAFILE, customers) return updated_customer
def add(table, labels): """ Add new record to table Args: table (list): table to add new record to record (list): new record Returns: list: Table with a new record """ table = common.add_new_record(table, labels) data_manager.write_table_to_file("model/crm/customers.csv", table) return table
def remove(table, id_): """ Remove a record with a given id from the table. Args: table (list): table to remove a record from id_ (str): id of a record to be removed Returns: list: Table without specified record. """ updated_table = common.remove_item_by_id(table, id_) data_manager.write_table_to_file("model/store/games.csv", updated_table) return updated_table
def create_new_account(lista): customers = get_customers_list() customers_id_list = [position[CUSTOMER_ID_INDEX] for position in customers] id = util.generate_unique_id(customers_id_list) new_customer = [id] for i in range(len(lista)): new_customer.append(lista[i]) customers.append(new_customer) data_manager.write_table_to_file(DATAFILE, customers) return new_customer
def create_data(id_number, em_name, bday_date, dept, clearance_level): ''' adding a new employee ''' employees_list = data_manager.read_table_from_file(DATAFILE) emp_list = [] for element in employees_list: emp_list.append(element) new_employee = [id_number, em_name, bday_date, dept, clearance_level] emp_list.append(new_employee) data_manager.write_table_to_file(DATAFILE, emp_list) return emp_list
def update(table, id_, record): """ Updates specified record in the table. Args: table: list in which record should be updated id_ (str): id of a record to update record (list): updated record Returns: list: table with updated record """ updated_table = common.update_item_by_id(table, id_, record) data_manager.write_table_to_file("model/store/games.csv", updated_table) return updated_table
def add(table, record): """ Add new record to table Args: table (list): table to add new record to record (list): new record Returns: list: Table with a new record """ index_id = 0 record.insert(index_id, common.generate_random(table)) table.append(record) data_manager.write_table_to_file("model/inventory/inventory.csv", table) return table
def remove(table, id_): """ Remove a record with a given id from the table. Args: table (list): table to remove a record from id_ (str): id of a record to be removed Returns: list: Table without specified record. """ for i, record in enumerate(table, 1): if str(i) == id_: del table[i - 1] data_manager.write_table_to_file("model/inventory/inventory.csv", table) return table
def delete_data(id_number): ''' deleting employee based on id ''' cos = [] employees_list = data_manager.read_table_from_file(DATAFILE) for employee_lst in employees_list: if id_number in employee_lst: pass else: cos.append(employee_lst) employees_list = cos data_manager.write_table_to_file(DATAFILE, employees_list) return employees_list