示例#1
0
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 run():
    options = [
        "Display data as a table", "Add new data", "Remove data", "Update",
        "Who is the oldest person?", "Who is the closest to the average age?"
    ]
    choice = None
    while choice != "0":
        terminal_view.print_menu("Human resources menu ", options,
                                 "Go back to main menu")
        inputs = terminal_view.get_inputs(["Please enter a number: "], "")
        choice = inputs[0]
        table_titles = ["id", "name", "year of birth"]
        #reading data from file
        data_table = data_manager.get_table_from_file("model/hr/persons.csv")
        if choice == "1":
            terminal_view.print_table(data_table, table_titles)
        elif choice == "2":
            table_titles.pop(0)
            hr.add(data_table, table_titles)
        elif choice == "3":
            hr.remove(data_table, get_user_id("remove"))
        elif choice == "4":
            hr.update(data_table, get_user_id("update"),
                      common.get_user_record(table_titles[1:]))
        elif choice == "5":
            sales_controller.run()
        elif choice == "6":
            crm_controller.run()
        elif choice == "0":
            root_controller.run()
        else:
            terminal_view.print_error_message("There is no such choice.")
def add_employee():
    view.clear_console()
    view.print_message("Add new employee:\n")

    new_employee = get_employee_data()

    hr.update(new_employee)

    view.print_message("\nnew employee was added correctly!")
    view.wait_for_reaction()
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
    """

    common.clear()
    title = 'Human Resources menu'
    options = ["Add new record to table",
               "Remove a record with a given id from the table.",
               "Updates specified record in the table.",
               "Who is the oldest person?",
               "Who is the closest to the average age?"]
    exit_message = "Back to main menu"

    title_list = ["ID", "NAME", "BIRTH YEAR"]
    table = hr.data_manager.get_table_from_file('model/hr/persons.csv')
    # terminal_view.print_table(table, title_list)

    choice = None
    while choice != "0":
        terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice(title, options, exit_message)
        if choice == "1":
            record = terminal_view.get_inputs(title_list, 'Please add following informations :', table)
            updated_table = hr.add(table, record)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "2":
            id_ = terminal_view.get_inputs(['Id'], 'Please give ID to remove :', table)
            updated_table = hr.remove(table, id_)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "3":
            id_ = terminal_view.get_inputs(['Id'], 'Please give ID of changed line :', table)
            record = terminal_view.get_inputs(title_list, 'Please add following informations :', table)
            updated_table = hr.update(table, id_, record)
            hr.data_manager.write_table_to_file('model/hr/persons.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "4":
            result = hr.get_oldest_person(table)
            label = "The oldest person is: "
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice == "5":
            result = hr.get_persons_closest_to_average(table)
            label = "The closest to the average age is person: ?"
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice != 0:
            terminal_view.print_error_message("There is no such choice.")
示例#5
0
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
    """
    table = hr.get_hr_table_from_file()
    title_list = ["ID", "Name", "BirthYear"]
    options = [
        "View records", "Add record", "Remove record", "Update record",
        "Which person is the oldest?",
        "Which person is the closet to average age?"
    ]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice_inner_menu(options, "HR manager")
        if choice == "1":
            terminal_view.print_table(table, title_list)
        elif choice == "2":
            record = terminal_view.get_inputs(title_list[1::],
                                              "Please provide new item data")
            table = hr.add(table, record)
        elif choice == "3":
            id_to_delete_table = terminal_view.get_inputs(["ID"],
                                                          "Item to delete")
            id_to_delete = id_to_delete_table[0]
            table = hr.remove(table, id_to_delete)
        elif choice == "4":
            records = terminal_view.get_inputs(title_list, "Edit item")
            record_id = records[0]
            table = hr.update(table, record_id, records)
        elif choice == "5":
            oldest_person = hr.get_oldest_person(table)
            terminal_view.print_result(oldest_person, "The oldest person: ")
        elif choice == "6":
            closest_to_average = hr.get_persons_closest_to_average(table)
            terminal_view.print_result(closest_to_average,
                                       "The closest to average is: ")
        elif choice != "0":
            terminal_view.print_error_message("There is no such choice.")
示例#6
0
 def test_update_record(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected_updated_record = ["kH34Ju#&", 'x', 'x', 'x', 'x']
     updated_data_row = ['x', 'x', 'x', 'x']
     hr.update(table, "kH34Ju#&", updated_data_row)
     self.assertListEqual(table[0], expected_updated_record)
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
    """
    list_of_humans = hr.get_data_to_list()

    # your code
    options = [
        "Add new record", "Remove a record", "Update record",
        "Search oldest persons", "Search persons closest to average",
        "Print table"
    ]

    title_list = ["ID", "NAME", "YEAR"]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(options, "Back to main menu")
        if choice == "1":

            new_record = terminal_view.get_inputs(["Name: ", "Birthyear: "],
                                                  "Please enter value: ")

            new_record.insert(0, hr.get_random_id(list_of_humans))
            list_of_humans = hr.add(list_of_humans, new_record)
        elif choice == "2":
            id_of_record_to_remove = ask_untill_correct(list_of_humans)
            list_of_humans = hr.remove(
                list_of_humans,
                common.check_id_by_number(list_of_humans,
                                          int(id_of_record_to_remove)))
        elif choice == "3":
            id_of_record_to_update = ask_untill_correct(list_of_humans)
            updated_record = terminal_view.get_inputs(
                ["Name: ", "Birthyear: "], "Please enter value: ")
            list_of_humans = hr.update(
                list_of_humans,
                common.check_id_by_number(list_of_humans,
                                          int(id_of_record_to_update)),
                updated_record)
        elif choice == "4":
            oldest_persons = hr.get_oldest_person(list_of_humans)
            terminal_view.print_result(oldest_persons,
                                       "List of oldest persons")
        elif choice == "5":
            closest_persons_to_avg = hr.get_persons_closest_to_average(
                list_of_humans)
            terminal_view.print_result(
                closest_persons_to_avg,
                "List of persons closest to average year")
        elif choice == "6":
            terminal_view.print_table(list_of_humans, title_list)
        elif choice == "0":
            hr.export_list_to_file(list_of_humans)
        else:
            terminal_view.print_error_message("There is no such choice.")