Ejemplo n.º 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
    """
    list_options = [
        "1. Add new record to table",
        "2. Remove a record with a given id from the table",
        "3. Update specified record in the table",
        "4. What is the id of the customer with the longest name?",
        "5. Which customers has subscribed to the newsletter?"
    ]

    program_works = True
    while program_works:
        table = crm.get_table()
        title_list = [
            "ID",
            "NAME",
            "EMAIL",
            "SUBSCRIBED? y/n",
        ]
        terminal_view.print_table(table, title_list)
        answer = terminal_view.get_choice(list_options)

        if answer == "1":
            record = terminal_view.get_inputs(
                ["ID: ", "Name: ", "E-mail: ", "Subscription? Yes/ No"],
                "Please provide information: \n")
            common.add(table, record)
            crm.save_table(table)
        elif answer == "2":
            id_ = terminal_view.get_input("Please enter id number: ")
            common.remove(table, id_)
            crm.save_table(table)
        elif answer == "3":
            common.update(table, id_, record)
        elif answer == "4":
            crm.get_longest_name_id(table)
        elif answer == "5":
            crm.get_subscribed_emails(table)
        elif answer == "0":
            program_works = False
        else:
            terminal_view.print_error_message(
                "There is no such choice. Choose from 1 to 5")
    return
Ejemplo n.º 2
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
Ejemplo n.º 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
    """

    title_list = ["* id", "* name", "* email", "* subscribed"]

    options = [
        "Add new record to table",
        "Remove a record with a given id from the table",
        "Update specified record in the table",
        "ID of the customer with the longest name",
        "Customers that have subscribed to the newsletter", "Print table"
    ]
    os.system('clear')
    file = "model/crm/customers.csv"
    choice = None
    while choice != "0":
        terminal_view.print_menu("What do you want to do:", options,
                                 "Back to main menu")
        choice = terminal_view.get_choice(options)
        if choice == "1":
            common.all_add(title_list, file)
        elif choice == "2":
            common.all_remove(title_list, file)
        elif choice == "3":
            common.all_updates(title_list, file)
        elif choice == "4":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = file
            table = common.get_table_from_file(file_name)
            id_with_longest_name = crm.get_longest_name_id(table)
            os.system("clear")
            print("ID of the customer with the longest name: ",
                  id_with_longest_name)
            common.waiting()
            os.system("clear")
        elif choice == "5":
            file_name = common.get_input("Choose a file: ")
            if file_name == "":
                file_name = file
            table = common.get_table_from_file(file_name)
            subscribed_mails = crm.get_subscribed_emails(table)
            os.system("clear")
            print("Customers that have subscribed to the newsletter: ",
                  subscribed_mails)
            common.waiting()
            os.system("clear")
        elif choice == "6":
            common.all_print_table(title_list, file)

        else:
            if choice != "0":
                terminal_view.print_error_message("There is no such choice.")
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
    """
    options = [
        "Add data", "Remove data", "Update data",
        "The customer ID with the Longest name", "Newsletter subscription",
        "Customer\'s name with the given ID"
    ]
    common_options = [
        "Name: ", "E-mail: ", "Newsletter subscribtion ('1'-yes or '0'-no): "
    ]
    link_for_csv = "model/crm/customers.csv"
    title_list = ["ID", "Name", "E-mail", "Newsletter subscribtion"]
    choice = None
    dont_clear = False
    while choice != '0':
        if not dont_clear:
            os.system("clear")
            table = data_manager.get_table_from_file(link_for_csv)
            terminal_view.print_table(table, title_list)
        choice = terminal_view.get_choice_submenu(options)
        dont_clear = False
        if choice == '1':
            common.add(link_for_csv, common_options)
        elif choice == '2':
            common.remove(link_for_csv)
        elif choice == '3':
            common.update(link_for_csv, common_options)
        elif choice == '4':
            terminal_view.print_result(
                crm.get_longest_name_id(table),
                'ID of the customer with the Longest name: ')
            dont_clear = True
        elif choice == '5':
            table_subscription = crm.get_subscribed_emails(table)
            terminal_view.print_result(
                table_subscription,
                'Customers who has subscribed to the newsletter: ')
            dont_clear = True
        elif choice == '6':
            ID = terminal_view.get_input("ID: ", "Please enter ID: ")
            terminal_view.print_result(
                crm.get_name_by_id_from_table(table, ID),
                "Customer\'s name by given ID: ")
            dont_clear = True
        else:
            terminal_view.print_error_message(
                "There is no such choice, please try again")
Ejemplo n.º 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.")
Ejemplo n.º 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
    """
    menu_controller = [
        "Print controller list", "Add to controller list",
        "Remove form controller list", "Update record in controller list",
        "Show subscribers", "Show longest name ID"
    ]
    title = ["ID", "Name", "E-mail", "Subscribed"]
    title_del = ["Input ID: "]
    choice = None
    while choice != "0":
        choice = terminal_view.get_choice(menu_controller)

        if choice == "1":
            terminal_view.print_table(crm.get_data(), title)

        if choice == "2":
            crm.new_record(
                common.get_user_inp_record(
                    terminal_view.get_inputs(title[1:], "")),
                "model/crm/customers.csv")
        if choice == "3":
            crm.delete_record(
                crm.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                "model/crm/customers.csv")
        if choice == "4":
            crm.update_record(
                crm.get_data(),
                common.get_user_inp_record(
                    terminal_view.get_inputs(title_del, "")),
                terminal_view.get_inputs(title[1:], ""),
                "model/crm/customers.csv")
        if choice == "5":
            terminal_view.print_result(
                crm.get_subscribed_emails(crm.get_data()), "Subscribers")
        if choice == "6":
            terminal_view.print_result(crm.get_longest_name_id(crm.get_data()),
                                       "Longest name ID")
Ejemplo n.º 7
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_headers = ['ID','Name', 'Email', 'Subscribed']
    choice = None
    filename = 'model/crm/customers.csv'
    columns_headers = ['Name', 'Email', 'Subscribed']
    ask_information = "Please provide your personal information"
   
    common.print_art(0)
    while choice != "0":
        choice = terminal_view.get_submenu_choice(['Add', 'Remove', 'Update',\
            'Longest customer name - id',\
                'Newsletter subscribers'])
        table = common.get_table_from_file(filename)
        
        if choice[0] == "1":
            common.clear_terminal()
            common.adding(table, table_headers, filename, columns_headers, ask_information)
        elif choice[0] == "2":
            common.clear_terminal()
            common.removing(table, table_headers,  id, filename)
        elif choice == "3":
            common.clear_terminal()
            common.updating(table, table_headers, id, filename, columns_headers, ask_information)
        elif choice == "4":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            longest_name = crm.get_longest_name_id(table)
            terminal_view.print_result('Id of customer with the longest name: ', longest_name)
        elif choice == "5":
            common.clear_terminal()
            terminal_view.print_table(table, table_headers)
            subscribers = crm.get_subscribed_emails(table)
            terminal_view.print_result('Subscribers: ', subscribers)
        elif int(choice) >= 6:
            common.clear_terminal()
            terminal_view.print_error_message("There is no such choice.")
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_options = [
			'Customer Relations Management',
			'Show all customers',
			'Add',
			'Remove',
			'Update',
			'Get ID of the customer with the longest name',
			'Get customers subscribed to newsletter',
			'Exit to main menu'
		]
	data_file = "model/crm/customers.csv"
	crud_module = crm
	while True:
		table = data_manager.get_table_from_file(data_file)
		max_id = len(table)
		list_labels = [
			['Name', 'name'],
			['Email', 'email'],
			['Subscription', 'subscription']
		]
		user_choice = terminal_view.get_choice(list_options)
		if user_choice in ['1', '2', '3', '4']:
			make_crud(crud_module, list_labels, list_options, max_id, table, user_choice)
		elif user_choice == '5':
			result = crm.get_longest_name_id(table)
			terminal_view.print_result(result, "ID of the customer with the longest name")
		elif user_choice == '6':
			result = crm.get_subscribed_emails(table)
			terminal_view.print_result(result, "Customers subscribed to the newsletter")
		elif user_choice == '0':
			break
		else:
			terminal_view.print_error_message("There is no such choice.")
 def test_get_longest_name_id(self):
     table = data_manager.get_table_from_file(self.data_file)
     result = crm.get_longest_name_id(table)
     self.assertEqual(result, "kH94Ju#&")
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
 def test_get_longest_name_id(self):
     table = data_manager.get_table_from_file(self.data_file)
     expected = "kH38Jm#&"
     result = crm.get_longest_name_id(table)
     self.assertEqual(result, expected)
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.")