Esempio n. 1
0
def add(table):
    """
    Asks user for input and adds it into the table.
    :param table: list of all items in database
    :return: updated table
    """
    new_record = []
    new_record.append(common.generate_random(table))
    new_record.append(input("Enter " + update_options[0] + ": "))
    i = 1
    while i < len(update_options):
        handle_inputs = input("Enter " + update_options[i] + ": ")
        if common.check_if_input_is_number(handle_inputs):
            if common.check_if_data_is_in_range(i, handle_inputs,
                                                border_conditions):
                new_record.append(handle_inputs)
                i += 1
        else:
            ui.print_error_message("error!")

    updated_table = table + [new_record]
    data_manager.write_table_to_file(file_name, table=updated_table)
    show_table(updated_table)

    return updated_table
Esempio n. 2
0
def add(table):
    """
    Asks user for input and adds it into the table.
    :param table: text file where are included some information.
    :return: list with a new record
    """
    new_record = []
    new_record.append(common.generate_random(table))
    new_record.append(input("Enter " + update_options[0] + ": "))
    new_record.append(input("Enter " + update_options[1] + ": "))
    new_record.append(input("Enter " + update_options[2] + ": "))
    i = 3
    while i < len(update_options):
        handle_inputs = input("Enter " + update_options[i] + ": ")
        if common.check_if_input_is_number(handle_inputs):
            if common.check_if_data_is_in_range(i, handle_inputs,
                                                border_conditions):
                new_record.append(handle_inputs)
                i += 1
        else:
            ui.print_error_message("Something went wrong!")

    updated_table = table + [new_record]
    data_manager.write_table_to_file(file_name, table=updated_table)
    show_table(updated_table)

    return updated_table
Esempio n. 3
0
def update(table, id_):
    """
    Updates specified record in the table. Ask users for new data.
    :param table: list of all items in database
    :param id_: input where user enter id
    :return: updated table
    """
    searched_record = [record for record in table if id_ in record]
    ui.print_table(searched_record, title_list)
    searched_record = searched_record[0]  # unpack from list of lists
    id_place = 1
    # due to id in on the 0 position in list

    i = 0
    while i < 1:
        user_input = input("What do you want change?").lower()
        if user_input in update_options:
            chosen_option = update_options.index(user_input) + id_place
            new_data = input("Actual " + user_input + ": " +
                             searched_record[chosen_option] + "\nEnter new: ")

            if chosen_option == 1:
                searched_record[chosen_option] = new_data
                i += 1
            elif common.check_if_input_is_number(
                    new_data) and common.check_if_data_is_in_range(
                        chosen_option - +id_place, new_data,
                        border_conditions):
                searched_record[chosen_option] = new_data
                i += 1
            else:
                ui.print_error_message(
                    "some kind of error, to wide range for day month year etc")
        else:
            ui.print_error_message("Provide correct value")
    data_manager.write_table_to_file(file_name, table=table)
    ui.print_table([searched_record], title_list)
    return table