예제 #1
0
def run_exact_date_search_process():
    """Executes exact date search on existing entries.

    Asks user for an exact date. Returns a list of matching entries. If there
    are no matches then user is informed of that fact.
    """

    list_of_entries = Time_Entry.select()

    print("Time entries were created on the following dates:")
    print("")
    for entry in list_of_entries:
        print("\t", end="")
        prettyprint_date(entry.date)
    print("")

    print("Enter the Date you would like to view.")
    exact_date = input("Please use DD/MM/YYYY: > ").strip()
    exact_date = validate_date_eds(exact_date, list_of_entries)
    exact_date = datetime.datetime.strptime(exact_date, '%d/%m/%Y')
    matching_entries = (Time_Entry.select()
                                  .where(Time_Entry.date == exact_date))
    clear_screen()

    if len(matching_entries) == 0:
        print("No matching entries found.")
        dummy = input("Press enter to continue. ")
    else:
        run_options_loop(matching_entries)
예제 #2
0
def run_add_entry_process():
    """Creates new time entry and saves to database.

    Obtains field information from user, creates new time entry object, and
    then saves the entry's information into the database.
    """

    add = Add_Menu()
    add.show()
    employee = get_employee()
    clear_screen()
    add.show()
    date = get_date()
    clear_screen()
    add.show()
    title = get_title()
    clear_screen()
    add.show()
    time_spent = get_time_spent()
    clear_screen()
    add.show()
    notes = get_notes()
    Time_Entry.create(employee_name=employee,
                      date=date,
                      title=title,
                      time_spent=time_spent,
                      notes=notes)
    clear_screen()
    input("The entry has been added! Press Enter to return to main menu.")
    clear_screen()
예제 #3
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)
예제 #4
0
 def test_remaining_entries(self):
     employee_name = "Brian Peterson"
     query = (Time_Entry.select().join(Employee).where(
         Employee.name == employee_name))
     expected_result = len(query)
     result = remaining_entries(employee_name)
     self.assertEqual(expected_result, result)
예제 #5
0
def remaining_entries(employee_name):
    """Returns the number of entries that an employee has made."""

    number_of_entries = (Time_Entry.select()
                                   .join(Employee)
                                   .where(Employee.name == employee_name)
                                   .count())
    return number_of_entries
예제 #6
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
예제 #7
0
def run_time_spent_process():
    """Executes time spent search on existing entries.

    Asks user for a time amount. Returns a list of matching entries. If there
    are no matches then user is informed of that fact.
    """

    time_spent = get_time_spent()

    matching_entries = (Time_Entry.select()
                                  .where(Time_Entry.time_spent == time_spent))

    clear_screen()

    if len(matching_entries) == 0:
        print("No matching entries found.")
        dummy = input("Press enter to continue. ")
    else:
        run_options_loop(matching_entries)
예제 #8
0
def run_range_of_dates_search_process():
    """Executes range of dates search on existing entries.

    Asks user for range of dates. Returns a list of matching entries. If there
    are no matches then user is informed of that fact.
    """

    start_date, end_date = get_date_range()

    within_range = ((Time_Entry.date >= start_date)
                    & (Time_Entry.date <= end_date))

    matching_entries = (Time_Entry.select().where(within_range))

    clear_screen()

    if len(matching_entries) == 0:
        print("No matching entries found.")
        dummy = input("Press enter to continue. ")
    else:
        run_options_loop(matching_entries)
예제 #9
0
def run_keyword_search_process():
    """Executes exact string search on existing entries.

    Asks user for an exact string to match against. Returns a list of matching
    entries. If there are no matches then user is informed of that fact.
    """

    print("This will search for matches in the title and notes fields.")
    search_term = input("Enter a search term: ").strip()

    contains_search_term = ((Time_Entry.title.contains(search_term))
                            | (Time_Entry.notes.contains(search_term)))

    matching_entries = Time_Entry.select().where(contains_search_term)

    clear_screen()

    if len(matching_entries) == 0:
        print("No matching entries found.")
        dummy = input("Press enter to continue. ")
    else:
        run_options_loop(matching_entries)
예제 #10
0
from peewee import *

from models.employee import Employee
from models.time_entry import Time_Entry

db = SqliteDatabase('time_entries.db')


def initialize():
    db.connect()
    db.create_tables([Employee, Time_Entry], safe=True)


if __name__ == '__main__':
    initialize()
    ee1 = Employee.create(name="Brian Peterson")
    Time_Entry.create(name=ee1.name,
                      title="test title",
                      time_spent=50,
                      notes="These are the notes")