コード例 #1
0
def search_by_range_of_dates():
    """This method takes self as argument. It get the tasks as a
    list from the text file and guides the user to search tasks within
    a specific range of dates. It returns a list with eventually found
    tasks."""
    # End the method if not task is available
    tasks = dbInteraction.TaskEntry.select().order_by(dbInteraction.
                                                      TaskEntry.
                                                      due_date.desc())
    if len(tasks) == 0:
        return []
    # Ask for a search date
    print("\nIn which period of time has the task been assinged for? ")
    while True:
        date_input = input("Please use MM/DD/YYYY-MM/DD/YYYY format. ")
        try:
            date_start, date_end = date_input[:10], date_input[11:21]
            utc_date_start = utility.convert_datetime_to_utc(date_start)
            utc_date_end = utility.convert_datetime_to_utc(date_end)
            break
        except ValueError:
            print("'{}' doesn't seem to be valid dates.".format(
                date_input))
    # Database query
    found_tasks = tasks.where(dbInteraction.TaskEntry.
                              due_date > utc_date_start,
                              dbInteraction.TaskEntry.
                              due_date < utc_date_end)
    return found_tasks
コード例 #2
0
 def add_task_to_DB(self, first_name, family_name, title, date,
                    time_spent, notes):
     """Test the addition of a task to the Database."""
     dbInteraction.add_task_to_db(first_name,
                                  family_name,
                                  title,
                                  utility.convert_datetime_to_utc(date),
                                  time_spent,
                                  notes)
コード例 #3
0
 def test_delete_task_from_DB(self):
     dbInteraction.add_task_to_db(self.first_name,
                                  self.family_name,
                                  self.title,
                                  utility.convert_datetime_to_utc(
                                      self.date),
                                  self.time_spent,
                                  self.notes)
     test_task = dbInteraction.TaskEntry.select().\
         where(dbInteraction.TaskEntry.first_name == self.first_name).get()
     test_task.delete_instance()
コード例 #4
0
 def test_convert_datetime_to_utc(self):
     """Takes a datetime format information and localizes it with
         pytz to 'Europe/Paris' and returns utc."""
     date_input = '03/03/2000'
     # Test
     self.assertEqual(str(utility.convert_datetime_to_utc('03/03/2000')),
                      '2000-03-02 23:00:00+00:00')
     # check to convert a native datetime to an aware pytz format
     with self.assertRaises(ValueError):
         utility.convert_datetime_to_utc('03/03/20004')
     with self.assertRaises(ValueError):
         utility.convert_datetime_to_utc('03*03/2000')
     with self.assertRaises(OverflowError):
         utility.convert_datetime_to_utc('01/01/0001')
コード例 #5
0
def edit_task(task):
    """This method takes self and a task as argument. The user is guided
    step by step to edit the task.
    Records can be deleted and edited, letting the user change the date,
    task name, time spent, and/or notes. Once done, the task is update in the
    database."""
    # Ask for the name of the user
    print('\n' + '=' * 60)
    while True:
        # Ask for the name of the task
        print("Your task to edit: '{}'. ".format(task.task_title))
        task_title = input("Please key in your new task name. ")
        print("\nWhat is the task's new due date? ")
        # Ask for the date of the task
        while True:
            date_input = input("Please use MM/DD/YYYY format. ")
            try:
                utc_date = utility.convert_datetime_to_utc(date_input)
                break
            except Exception:  # ValueError:
                print("{} doesn't seem to be a valid date.".format(date_input))
        # Ask for time spent on the task
        text = "\nHow much time does it take to finish the task "
        print(text + "'{}'? ".format(task_title))
        while True:
            time_input = input("Please add a time in Minutes. ")
            try:
                time_spent = int(time_input)
                if time_spent < 0:
                    print("That's not positive number. Please try again.")
                    continue
                break
            except ValueError:
                print(
                    "'{}' doesn't seem to be a valid time in Minutes.".format(
                        time_input))
        # Ask for notes to the task
        notes = input("Please key any notes to this task. ")
        break
    # Remove old task from database
    dbInteraction.delete_task_from_db(task)
    # Add (write) the new task into the database
    dbInteraction.add_task_to_db(task.first_name, task.family_name, task_title,
                                 utc_date, time_spent, notes)
    print('Task was successfully edited.')
コード例 #6
0
    def test_view_task(self):
        dbInteraction.add_task_to_db(self.first_name,
                                     self.family_name,
                                     self.title,
                                     utility.convert_datetime_to_utc(
                                         self.date),
                                     self.time_spent,
                                     self.notes)
        test_task = dbInteraction.TaskEntry.select().\
            where(dbInteraction.TaskEntry.first_name == self.first_name).get()
        result = """============================================================
Task title: thisss
============================================================
Employee's first name: 90df8sd09fs8d0f9sds
Employee's last name: skywalker
Task's due date: 03/03/2000
Time spent on task: 39038490470 Hours 34 Minutes (=> 2342309428234 Minutes)
Notes: testnotes
============================================================"""
        self.assertEqual(dbInteraction.view_task(test_task), result)
        test_task.delete_instance()
コード例 #7
0
 def test_add_task_to_DB(self):
     """Test the addition of a task to the Database."""
     dbInteraction.add_task_to_db(self.first_name,
                                  self.family_name,
                                  self.title,
                                  utility.convert_datetime_to_utc(
                                      self.date),
                                  self.time_spent,
                                  self.notes)
     all_tasks = dbInteraction.TaskEntry.select()
     test_task = all_tasks.where(dbInteraction.
                                 TaskEntry.
                                 first_name == self.first_name).get()
     self.assertEqual(test_task.first_name, self.first_name)
     self.assertEqual(test_task.family_name, self.family_name)
     self.assertEqual(test_task.task_title, self.title)
     self.assertEqual(utility.convert_utcdate_to_datestring(
         test_task.due_date), self.date)
     self.assertEqual(test_task.time_spent, self.time_spent)
     self.assertEqual(test_task.notes, self.notes)
     test_task.delete_instance()
コード例 #8
0
def add_task_ui():
    """This method take self as argument and ask the user to input
    all necessary information to add a task. The new task is added to
    the database."""
    while True:
        # Ask for the name of the user
        first_name = input("Please key in your first name. ")
        family_name = input("Please key in your last name. ")
        task_title = input("Please key in the name of the task. ")
        print("\nWhen is this task due? ")
        while True:
            date_input = input("Please use MM/DD/YYYY format. ")
            try:
                utc_date = utility.convert_datetime_to_utc(date_input)
                break
            except Exception:
                print(
                    "'{}' doesn't seem to be a valid date.".format(date_input))
        # Ask for time spent on the task
        print(
            "\nHow much time did you spend on task '{}'? ".format(task_title))
        while True:
            time_input = input("Please add a time in Minutes. ")
            try:
                time_spent = int(time_input)
                if time_spent < 0:
                    print("That's not positive number. Please try again.")
                    continue
                break
            except ValueError:
                print(
                    "'{}' doesn't seem to be a valid time in Minutes.".format(
                        time_input))
        # Ask for notes to the task
        notes = input("Please key any notes to this task. ")
        break
    # Add (write) the new task into the database
    dbInteraction.add_task_to_db(first_name, family_name, task_title, utc_date,
                                 time_spent, notes)
    print('Task was successfully added.')