Esempio n. 1
0
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
Esempio n. 2
0
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 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 add(common_options):
    """
    Asks user for input and adds it into the table.

    Args:
        table (list): table to add new record to

    Returns:
        list: Table with a new record
    """
    sales_table = common.get_table_from(sales_file)
    customers_table = common.get_table_from(customers_file)
    add_options = ["Add for an existing user", "Add new user"]
    customer_titles = ["ID", "Name", "E-mail", "Newsletter subscribtion"]
    customer_input_titles = ["Name: ", "E-mail: ", "Newsletter subscription: "]
    add_options = ["Add for an existing user", "Add new user"]

    os.system("clear")
    terminal_view.print_table(customers_table, customer_titles)
    adding_type = terminal_view.get_choice_submenu(add_options)

    if adding_type == '2':
        record = common.add(customers_file, customer_input_titles)
        os.system("clear")
        customers_table = common.get_table_from(customers_file)
        terminal_view.print_table(customers_table, customer_titles)
    if adding_type == '1' or adding_type == '2':
        id_ = sales_controller.input_for_add_menu()

        exists = False
        for element in customers_table:
            if element[0] == id_:
                exists = True
        if not exists:
            terminal_view.print_error_message("User not found")
        else:
            record = terminal_view.get_inputs(
                [opt for opt in common_options],
                "Please provide following data: ")
            record.append(id_)
            record.insert(0, model_common.generate_random(record))
            sales_table.append(record)
            data_manager.write_table_to_file(sales_file, sales_table)
def make_record(table, inputs):
    output_list = [common.generate_random(table)] + inputs
    return output_list
def get_random_id(table):
    return common.generate_random(table)
def get_inputs(list_labels, title, table=None):
    """
    Gets list of inputs from the user.
    Sample call:
        get_inputs(["Name","Surname","Age"],"Please provide your personal information")
    Sample display:
        Please provide your personal information
        Name <user_input_1>
        Surname <user_input_2>
        Age <user_input_3>

    Args:
        list_labels (list): labels of inputs
        title (string): title of the "input section"

    Returns:
        list: List of data given by the user. Sample return:
            [<user_input_1>, <user_input_2>, <user_input_3>]
    """
    headers = [
        "ID", "MONTH", "DAY", "YEAR", "BIRTH YEAR", "PURCHASE YEAR", "PRICE",
        "IN STOCK", "DURABILITY"
    ]

    head = ['TYPE', "SUBSCRIBED"]
    input_list = []
    print(title)
    for question in list_labels:
        if question == headers[0]:
            answer = common.generate_random(table)
            input_list.append(answer)
        elif question in headers[0:(len(headers) + 1)]:
            answer = input(question + " ")
            if answer.isnumeric():
                input_list.append(answer)
            else:
                command = True
                while command:
                    print('Please give a number.')
                    answer = input(question + " ")
                    if answer.isnumeric():
                        command = False
                input_list.append(answer)
        elif question in head[0]:
            answer = input(question + " ")
            if answer in ['in', 'out']:
                input_list.append(answer)
            else:
                command = True
                while command:
                    print('Please give in/out.')
                    answer = input(question + " ")
                    if answer in ['in', 'out']:
                        command = False
                input_list.append(answer)
        elif question in head[1]:
            answer = input(question + " ")
            if answer in ['0', '1']:
                input_list.append(answer)
            else:
                command = True
                while command:
                    print('Please give 0/1.')
                    answer = input(question + " ")
                    if answer in ['0', '1']:
                        command = False
                input_list.append(answer)
        else:
            answer = input(question + " ")
            input_list.append(answer)

    return input_list