コード例 #1
0
def run():
    options = [
        "Display data as a table", "Add new data", "Remove data", "Update",
        "What is the id of the customer with the longest name?",
        "Which customers has subscribed to the newsletter?"
    ]
    choice = None
    while choice != "0":
        terminal_view.print_menu("CRM menu ", options, "Go back to main menu")
        inputs = terminal_view.get_inputs(["Please enter a number: "], "")
        choice = inputs[0]
        table_titles = ["id", "name", "email", "subscribed"]
        #reading data from file
        data_table = data_manager.get_table_from_file(
            "model/crm/customers.csv")
        if choice == "1":
            terminal_view.print_table(data_table, table_titles)
        elif choice == "2":
            table_titles.pop(0)
            crm.add(data_table, table_titles)
        elif choice == "3":
            crm.remove(data_table, get_user_id("remove"))
        elif choice == "4":
            crm.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.")
コード例 #2
0
def add_customer():
    view.clear_console()
    view.print_message("Add customer:\n")

    customer = get_customer_data()
    if customer is None:
        return

    crm.update(customer)
    view.print_message("\nCustomer was added correctly!")
コード例 #3
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
    """
    list_of_customers = crm.get_data_to_list()

    # your code
    options = [
        "Add new record", "Remove a record", "Update record",
        "Id of the customer with the longest name",
        "Customers has subscribed to the newsletter", "Print table"
    ]

    title_list = ["ID", "Name", "e-mail", "subscribed"]

    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: ", "e-mail: ", "subscribed: "], "Please enter value: ")
            new_record.insert(0, crm.get_random_id(list_of_customers))
            list_of_customers = crm.add(list_of_customers, new_record)
        elif choice == "2":
            #  id_of_record_to_remove = id_to_number_of_line(list_of_customers)
            id_of_record_to_remove = ask_untill_correct(list_of_customers)
            list_of_customers = crm.remove(
                list_of_customers,
                common.check_id_by_number(list_of_customers,
                                          int(id_of_record_to_remove)))
        elif choice == "3":
            id_of_record_to_update = ask_untill_correct(list_of_customers)
            updated_record = terminal_view.get_inputs(
                ["Name: ", "e-mail: ", "subscribed: "], "Please enter value: ")
            list_of_customers = crm.update(
                list_of_customers,
                common.check_id_by_number(list_of_customers,
                                          int(id_of_record_to_update)),
                updated_record)
        elif choice == "4":
            terminal_view.print_result(
                crm.get_longest_name_id(list_of_customers),
                "Longest person's ID")
        elif choice == "5":
            terminal_view.print_result(
                crm.get_subscribed_emails(list_of_customers),
                "List of subsrcibe user")
        elif choice == "6":
            terminal_view.print_table(list_of_customers, title_list)
        elif choice == "0":
            crm.export_list_to_file(list_of_customers)

        else:
            terminal_view.print_error_message(
                "There is no such choice.")  # your code
コード例 #4
0
def run():
    options = [
        "Print list", "Add record", "Update record", "Remove record",
        'Transaction by employee', 'Transaction by customer'
    ]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice('SALES MENU', options)
        if choice == "1":  # show list of all records
            terminal_view.print_table(sales_list, 'Sales list')
        elif choice == "2":  # add record
            crm.create(
                sales_list,
                terminal_view.get_inputs(list_labels,
                                         'Enter transaction data below:', ''),
                sales_file)
        elif choice == "3":  # update record
            crm.update(
                sales_list,
                terminal_view.get_inputs(temp,
                                         'Enter transaction ID to update: ',
                                         ''),
                terminal_view.get_inputs(list_labels[1:],
                                         'Enter id, name or e-mail to update',
                                         sales_file), sales_file)
        elif choice == "4":  # remove record
            crm.delete(
                sales_list,
                terminal_view.get_inputs(temp,
                                         'Enter transaction ID to remove: ',
                                         ''), sales_file)
        elif choice == '5':
            terminal_view.print_result(
                crm.read(sales_list, terminal_view.get_inputs(temp, 'ID:',
                                                              '')), '')
        elif choice == '6':
            terminal_view.print_result(
                crm.read(sales_list, terminal_view.get_inputs(temp, 'ID:',
                                                              '')), '')
            crm.delete(
                sales_list,
                terminal_view.get_inputs(temp,
                                         'Enter transaction ID to remove: ',
                                         ''), sales_file)
        else:
            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 = crm.get_crm_table_from_file()
    title_list = ["ID", "Name", "E-mail", "Subscribed"]
    options = [
        "View records", "Add record", "Remove record", "Update record",
        "ID releated with the longest name", "The emails with subscription",
        "The users without subscription"
    ]

    choice = None
    while choice != "0":
        choice = terminal_view.get_choice_inner_menu(
            options, "Customer Relationship Management 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 = crm.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 = crm.remove(table, id_to_delete)
        elif choice == "4":
            records = terminal_view.get_inputs(title_list, "Edit item")
            record_id = records[0]
            table = crm.update(table, record_id, records)
        elif choice == "5":
            longest_name_id = crm.get_longest_name_id(table)
            terminal_view.print_result(longest_name_id,
                                       "The longest name ID: ")
        elif choice == "6":
            subscribed_emails = crm.get_subscribed_emails(table)
            terminal_view.print_result(subscribed_emails,
                                       "The subscribed emails: ")
        elif choice == "7":
            offer = crm.proposition_subscription(table)
            terminal_view.print_result(offer,
                                       "The users without subscription: ")
        elif choice != "0":
            terminal_view.print_error_message("There is no such choice.")
コード例 #6
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
    """

    common.clear()
    title = 'Custom Relationship Mmanager menu'
    options = ["Add new record to table",
               "Remove a record with a given id from the table.",
               "Updates specified record in the table.",
               "What is the id of the customer with the longest name?",
               "Which customers has subscribed to the newsletter?"]
    exit_message = "Back to main menu"

    title_list = ["ID", "NAME", "EMAIL", "SUBSCRIBED"]
    table = crm.data_manager.get_table_from_file('model/crm/customers.csv')

    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 = crm.add(table, record)
            crm.data_manager.write_table_to_file('model/crm/customers.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 = crm.remove(table, id_)
            crm.data_manager.write_table_to_file('model/crm/customers.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 = crm.update(table, id_, record)
            crm.data_manager.write_table_to_file('model/crm/customers.csv', updated_table)
            common.exit_prompt()
            common.clear()
        elif choice == "4":
            label = "The id of the customer with the longest name is: "
            result = crm.get_longest_name_id(table)
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice == "5":
            label = "Customers that has been subscribed to the newsletter: "
            result = crm.get_subscribed_emails(table)
            terminal_view.print_result(result, label)
            common.exit_prompt()
            common.clear()
        elif choice != 0:
            terminal_view.print_error_message("There is no such choice.")
        common.exit_prompt()
        common.clear()
コード例 #7
0
 def test_update_record(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected_updated_record = ["kH38Jm#&", 'x', 'x', 'x', 'x']
     updated_data_row = ['x', 'x', 'x', 'x']
     crm.update(table, "kH38Jm#&", updated_data_row)
     self.assertListEqual(table[0], expected_updated_record)
コード例 #8
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 = "Customer Relationship Management (CRM)"
    options = ["Add item",
               "Remove item",
               "Update item",
               "Longest ID of customer",
               "Show subscibers"]
    exit_message = "Back to main menu"

    title_list = [
        ['Name'],
        ['E-mail address'],
        ['Subscription']]

    data_file = "model/crm/customers.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
            crm.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: "], "")
            crm.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
            crm.update(table, user_input[0], record)
            terminal_view.print_table(table, title_list)
        elif choice == "4":
            terminal_view.print_result(
                crm.get_longest_name_id(table), "This is the longest ID")
        elif choice == "5":
            terminal_view.print_result(
                crm.get_subscribed_emails(table), "Subscribed e-mails")
        else:
            terminal_view.print_error_message("You have chosen back to menu.")