Example #1
0
def run_browse_by_name_process():
    """Executes employee name search on existing entries.

    Presents user with list of employees who have created entries.
    Allows user to view entries created by one of the employees listed.
     """

    list_of_employees = Employee.select()

    if len(list_of_employees) == 0:
        print("There are no time entries in the database.")
        dummy = input("Press Enter to continue.: > ")
        clear_screen()

    else:
        print("The following employees have created time entries:")
        print("")
        for employee in list_of_employees:
            print("\t" + employee.name)

        print("")
        selection = input("Which employee's time " +
                          "entries would you like to view? > ").strip()

        selection = validate_employee_name(selection, list_of_employees)

        matching_entries = (Time_Entry.select()
                                      .join(Employee)
                                      .where(Employee.name == selection))
        clear_screen()

        run_options_loop(matching_entries)
Example #2
0
def run_search_by_name_process():
    """Executes name search on existing entries.

    Asks user for a name to search. Informs user if there is none, one, or
    many matches. Prompts user to continue process.
    """

    name = input("Please enter a name to search. > ").strip()

    matching_names = (Employee.select().where(Employee.name.contains(name)))

    if len(matching_names) == 0:
        print("Sorry there are no employees whose name contains {}"
              .format(name))
        dummy = input("Please press Enter to return to the Main Menu.")
        clear_screen()

    elif len(matching_names) == 1:
        matching_entries = (Time_Entry.select()
                                      .join(Employee)
                                      .where(Employee.name.contains(name)))
        print("Your search returned one match.")
        print("")
        dummy = input("Press Enter to view {}'s entries."
                      .format(matching_entries[0].employee_name.name))
        clear_screen()
        run_options_loop(matching_entries)

    elif len(matching_names) > 1:
        print("There is more than one employee " +
              "whose name contains {}.".format(name))
        print("")
        for employee in matching_names:
            print("\t {}".format(employee.name))
        print("")
        selection = input("Which employee's time " +
                          "entries would you like to view? > ").strip()
        selection = validate_employee_name(selection, matching_names)
        matching_entries = (Time_Entry.select()
                                      .join(Employee)
                                      .where(Employee.name == selection))
        clear_screen()
        run_options_loop(matching_entries)

    else:
        pass