Exemple #1
0
def add(table):
    """
    Asks user for input and adds it into the table.

    Args:
        table: table to add new record to

    Returns:
        Table with a new record
    """
    list_labels = ["title: ", "manufacturer: ", "price: ", "in_stock: "]
    check = True
    while check:
        new_product = ui.get_inputs(list_labels,
                                    "Please provide product information")
        validation = common.validate_data(
            ["title: ", "manufacturer: ", "price: ", "in_stock: "],
            new_product)
        if not validation:
            ui.print_error_message("Input not valid.\n")
            continue
        new_product.insert(0, common.generate_random(table))
        table.append(new_product)
        what_to_do = ui.get_inputs(
            [""], "Press 0 to save & exit or 1 to add another game.")[0]
        if what_to_do == "0":
            check = False
            data_manager.write_table_to_file("store/games.csv", table)
    return table
def add(table):
    """
    Asks user for input and adds it into the table.

    Args:
        table: table to add new record to

    Returns:
        Table with a new record
    """
    check = True
    while check:
        list_labels = ['Name: ', 'Birth date: ']
        new_item = ui.get_inputs(list_labels, "Please provide information")
        validation = common.validate_data(list_labels, new_item)
        if not validation:
            ui.print_error_message("Input not valid.\n")
            continue
        new_item.insert(0, common.generate_random(table))
        table.append(new_item)
        what_to_do = ui.get_inputs(
            [""], "Press 0 to exit or 1 to add another person.")
        if what_to_do[0] == '0':
            check = False
            os.system('clear')
        os.system('clear')
        show_table(table)
    data_manager.write_table_to_file("hr/persons_test.csv", table)
    return table
def add(table):
    """
    Asks user for input and adds it into the table.

    Args:
        table: table to add new record to

    Returns:
        Table with a new record
    """
    check = True
    while check:
        list_labels = ["Title: ", "Price: ", "Month: ", "Day: ", "Year:"]
        new_item = ui.get_inputs(list_labels, "Please provide information")
        validation = common.validate_data(list_labels, new_item)
        if not validation:
            ui.print_error_message("Input not valid.\n")
            continue
        new_item.insert(0, common.generate_random(table))
        table.append(new_item)
        what_to_do = ui.get_inputs([""], "Press 0 to exit or 1 to add another game.")
        if what_to_do[0] == "0":
            check = False
    data_manager.write_table_to_file("sales/sales.csv", table)

    return table
def add(table):
    """
    Asks user for input and adds it into the table.

    Args:
        table: table to add new record to

    Returns:
        Table with a new record
    """

    # your code
    check = True
    while check:

        list_labels = ["Name", "E-Mail", "Newsletter"]
        new_item = ui.get_inputs(list_labels,
                                 "Please provide your personal information")
        validation = common.validate_data(list_labels, new_item)
        if not validation:
            ui.print_error_message("Input not valid.\n")
            continue
        new_item.insert(0, common.generate_random(table))
        table.append(new_item)
        what_to_do = ui.get_inputs([""], "Press 0 or exit or 1 to add record.")
        if what_to_do[0] == "0":
            check = False
            os.system("clear")
        os.system("clear")
        show_table(table)
    data_manager.write_table_to_file("crm/customers.csv", table)

    return table
def update(table, id_):
    """
    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
    """
    check = True
    while check:
        table_dict = common.creat_dict_from_table(table)
        if id_[0] in list(table_dict.keys()):
            list_labels = ['Name: ', 'Birth date: ']
            updated_item = ui.get_inputs(
                list_labels, "Please provide personal information")
            validation = common.validate_data(list_labels, updated_item)
            if not validation:
                ui.print_error_message("Input not valid.\n")
                continue
            updated_item.insert(0, id_[0])
            table_dict[id_[0]] = updated_item
            table = list(
                table_dict.values()
            )  # zrobiłem listę, wcześniej bez 'list'(gdyby nie działało to zmien tutaj)
            data_manager.write_table_to_file("hr/persons_test.csv", table)
            os.system('clear')
            show_table(table)
            what_to_do = ui.get_inputs(
                [""], "Press 0 to exit or 1 to update another information.")
            if what_to_do[0] == '0':
                check = False
                os.system('clear')
            else:
                os.system('clear')
                show_table(table)
                id_ = ui.get_inputs(["Please type ID to update: "], "\n")
        else:
            ui.print_error_message("There is no such element.\n")
            what_to_do = ui.get_inputs(
                [""], "Press 0 to exit or 1 to try one more time.")
            if what_to_do[0] == '0':
                check = False
                os.system('clear')
            else:
                os.system('clear')
                show_table(table)
                id_ = ui.get_inputs(["Please type ID to update: "], "\n")
    return table
def update(table, id_):
    """
    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
    """

    # your code
    check = True
    while check:
        table_dict = common.creat_dict_from_table(table)

        if id_[0] in list(table_dict.keys()):
            list_labels = ["Name", "E-Mail", "Newsletter"]
            updated_item = ui.get_inputs(
                list_labels, "Please, provide customer information")
            validation = common.validate_data(list_labels, updated_item)
            if not validation:
                ui.print_error_message("Input not valid.\n")
                continue
            updated_item.insert(0, id_[0])
            table_dict[id_[0]] = updated_item
            table = list(table_dict.values())
            data_manager.write_table_to_file("crm/customers.csv", table)
            os.system("clear")
            what_to_do = ui.get_inputs(
                [""], "Press 0 or exit or 1 to update another information.")
            if what_to_do[0] == '0':
                check = False
                os.system("clear")
            else:
                os.system("clear")
                show_table(table)
                id_ = ui.get_inputs(["Please type ID to update: "], "\n")
        else:
            ui.print_error_message("There is no such element.")
            what_to_do = ui.get_inputs(
                [""], "Press 0 or exit or 1 to try one more time.")
            if what_to_do[0] == '0':
                check = False
                os.system("clear")
            else:
                os.system("clear")
                show_table(table)
                id_ = ui.get_inputs(["Please, type ID to update: "], "\n")
    return table
def update(table, id_):
    """
    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
    """
    check = True
    while check:
        table_dict = common.creat_dict_from_table(table)

        if id_[0] in list(table_dict.keys()):
            list_labels = ["Title: ", "Price: ", "Month: ", "Day: ", "Year:"]
            updated_item = ui.get_inputs(list_labels, "Please provide product information")
            validation = common.validate_data(list_labels, updated_item)
            if not validation:
                ui.print_error_message("Input not valid.\n")
                continue
            updated_item.insert(0, id_[0])
            table_dict[id_[0]] = updated_item
            table = list(table_dict.values())
            data_manager.write_table_to_file("store/games.csv", table)
            what_to_do = ui.get_inputs([""], "Press 0 to exit or 1 to update another information.")
            if what_to_do[0] == '0':
                check = False
            else:
                id_ = ui.get_inputs(["Please type ID to update: "], "\n")
        else:
            ui.print_error_message("There is no such element.\n")
            what_to_do = ui.get_inputs([""], "Press 0 to exit or 1 to try one more time.")
            if what_to_do[0] == '0':
                check = False
            else:
                id_ = ui.get_inputs(["Please type ID to update: "], "\n")
    return table
Exemple #8
0
def update(table, id_):
    """
    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
    """

    list_labels = ["title: ", "manufacturer: ", "price: ", "in_stock: "]
    check = True
    while check:
        table_dict = common.creat_dict_from_table(table)
        if id_ in list(table_dict.keys()):
            updated_product = ui.get_inputs(
                list_labels, "Please provide product information")
            validation = common.validate_data(list_labels, updated_product)
            if not validation:
                ui.print_error_message("Input not valid.\n")
                continue
            updated_product.insert(0, table_dict[id_][0])
            table_dict[id_] = updated_product
            table = list(table_dict.values())
            data_manager.write_table_to_file("store/games.csv", table)
        else:
            ui.print_error_message("There is no such element.")
        what_to_do = ui.get_inputs(
            [""], "Press 0 to exit or 1 to remove another game.")[0]
        if what_to_do == '0':
            data_manager.write_table_to_file("store/games.csv", table)
            check = False
        else:
            id_ = ui.get_inputs(["Please type ID to update: "], "\n")[0]
            continue
    return table