Exemple #1
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
    """

    # check is id_ exists in table
    index_to_update = common.find_index_by_id(table, id_)

    if index_to_update is None:
        ui.print_error_message('no such id')
        return table

    # keep previous id
    record = [id_]

    # data structure
    ds = get_data_structure()

    # append record by data from user
    record += ask_user_for_data(ds)

    # change data
    table = remove(table, id_)
    table.append(record)

    pass
Exemple #2
0
def remove(table, id_):
    """
    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.
    """

    index_to_delete = common.find_index_by_id(table, id_)
    if index_to_delete is None:
        ui.print_error_message('no item of this id')
    else:
        table.pop(index_to_delete)

    pass
Exemple #3
0
def remove(table, id_):
    """
    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.
    """

    index_to_delete = common.find_index_by_id(table, id_)

    if index_to_delete is None:
        ui.print_error_message('no item of this id')
    else:
        table.pop(index_to_delete)

    file_name = './hr/persons.csv'
    data_manager.write_table_to_file(file_name, table)

    return table