Ejemplo n.º 1
0
 def from_date_string_list(date_string_list):
     due_date_list = list()
     if type(date_string_list) is list and len(date_string_list) > 0:
         for date_string in date_string_list:
             if type(date_string) is str:
                 dd = DueDate()
                 dd.date_string = date_string
                 dd.completed = False
                 due_date_list.append(dd)
     return due_date_list
Ejemplo n.º 2
0
 def __init__(self, text="default"):
     super().__init__(self.__class__.__name__)
     self.vars = CommonVariables()
     self.__external_id = str()
     self.__text = text
     self.__label = self.vars.default_label
     self.__deleted = False
     self.__priority = 1
     self.__project = self.vars.default_project_name
     self.__date_expression = self.vars.default_date_expression
     self.__due_date = DueDate()
Ejemplo n.º 3
0
    def get_due_dates(self, expression: str) -> list:
        assert type(expression) is str
        parser = DateParser(expression, self.current_day)

        self.handler_1.next_handler = self.handler_2
        self.handler_2.next_handler = self.handler_3
        self.handler_3.next_handler = self.handler_4
        self.handler_4.next_handler = self.handler_5
        self.handler_5.next_handler = self.handler_6
        self.handler_6.next_handler = ErrorHandler()
        self.handler_1.handle(parser)

        if len(parser.day_list) == 0:
            return [DueDate()]
        else:
            return [DueDate(day.to_date_string()) for day in parser.day_list]
Ejemplo n.º 4
0
    def get_due_date(self, expression: str) -> DueDate:
        assert type(expression) is str
        parser = DateParser(expression, self.current_day)

        self.handler_1.next_handler = self.handler_2
        self.handler_2.next_handler = self.handler_4
        self.handler_4.next_handler = self.handler_5
        self.handler_5.next_handler = self.handler_7
        self.handler_7.next_handler = ErrorHandler()
        self.handler_1.handle(parser)

        if len(parser.day_list) == 1:
            day = deque(parser.day_list).popleft()
            return DueDate(day.to_date_string())
        else:
            return DueDate()
Ejemplo n.º 5
0
 def deserialize(self, obj_dict):
     for key, value in obj_dict.items():
         if type(value) is list:
             if key == "due_date" and len(value) == 1:
                 self.due_date = DueDate().from_dict(value[0])
         else:
             setattr(self, key, value)
     return self
Ejemplo n.º 6
0
    def reset(self, task_id: str) -> Task:
        """
        Resets the due date to today on the selected task
        :param task_id:
        :return:
        """
        assert type(task_id) is str

        task = self.get_task_by_id(task_id)
        if task is not None:
            due_date = DueDate()
            due_date.completed = False
            due_date.date_string = Today().to_date_string()
            task.due_date = due_date
            self.replace_object(task.index, task)
            return task
        else:
            raise TaskKeyError()
Ejemplo n.º 7
0
class Task(DatabaseObject):
    """
    Contains the properties that are needed to represent a task. The DatabaseObject
    contains only the properties that are used to maintain consistent data.
    """
    def __init__(self, text="default"):
        super().__init__(self.__class__.__name__)
        self.vars = CommonVariables()
        self.__external_id = str()
        self.__text = text
        self.__label = self.vars.default_label
        self.__deleted = False
        self.__priority = 1
        self.__project = self.vars.default_project_name
        self.__date_expression = self.vars.default_date_expression
        self.__due_date = DueDate()

    def get_redis_db_id(self):
        return 0

    @property
    def date_expression(self):
        return self.__date_expression

    @date_expression.setter
    def date_expression(self, expression):
        assert type(expression) is str
        self.__date_expression = expression

    @property
    def due_date(self):
        return self.__due_date

    @due_date.setter
    def due_date(self, due_date):
        self.__due_date = due_date

    def complete(self) -> list:
        self.due_date.completed = True
        return [self.__due_date]

    @property
    def external_id(self):
        return self.__external_id

    @external_id.setter
    def external_id(self, external_id):
        self.__external_id = external_id

    @property
    def project(self):
        return self.__project

    @project.setter
    def project(self, project):
        if len(str(project)) > 0 and project is not None:
            self.__project = project

    @property
    def text(self):
        return self.__text

    @text.setter
    def text(self, text):
        if len(str(text)) > 0 and text is not None:
            self.__text = text

    @property
    def label(self):
        return self.__label

    @label.setter
    def label(self, label):
        if label is not None:
            self.__label = label

    @property
    def deleted(self):
        return self.__deleted

    @deleted.setter
    def deleted(self, deleted):
        assert type(deleted) is bool
        self.__deleted = deleted

    @property
    def priority(self):
        return self.__priority

    @priority.setter
    def priority(self, priority):
        assert type(priority) is int
        self.__priority = priority

    def is_completed(self):
        return self.due_date.completed is True

    def deserialize(self, obj_dict):
        for key, value in obj_dict.items():
            if type(value) is list:
                if key == "due_date" and len(value) == 1:
                    self.due_date = DueDate().from_dict(value[0])
            else:
                setattr(self, key, value)
        return self

    def __eq__(self, other):
        existing = (self.unique_id, self.__text, self.__label, self.__project)
        new = (other.unqiue_id, other.text, self.label, self.project)
        return existing == new

    def __iter__(self):
        yield 'index', self.index
        yield 'external_id', self.external_id
        yield 'text', self.__text
        yield 'label', self.__label
        yield 'deleted', self.__deleted
        yield 'priority', self.__priority
        yield 'project', self.__project
        yield 'date_expression', self.__date_expression
        yield 'due_date', [self.__due_date.to_dict()]
        yield 'unique_id', self.unique_id
        yield 'last_updated', self.last_updated
Ejemplo n.º 8
0
 def is_past(due_date: DueDate, current_day=Today()) -> bool:
     timedelta1 = due_date.to_date_time() - current_day.to_date_time()
     if timedelta1.days < 0:
         return True
     return False
Ejemplo n.º 9
0
    def setUp(self):
        self.vars = CommonVariables()
        self.db = JsonFileDatabase()
        self.db.initialize(Task())
        self.tasks = Tasks(self.db)
        self.task1 = Task("Task1")
        self.task1.label = "waiting"
        self.task1.date_expression = "may 2"
        self.task1.external_id = 1
        self.tasks.append(self.task1)

        self.task2 = Task("Task2")
        self.task2.label = "computer"
        self.task2.date_expression = "may 3"
        self.tasks.append(self.task2)

        self.task3 = Task("Task3")
        self.task3.label = "office"
        self.task3.date_expression = "may 4"
        self.tasks.append(self.task3)

        self.task4 = Task("Task4")
        self.task4.label = "waiting"
        self.task4.date_expression = "may 5"
        self.tasks.append(self.task4)

        self.task5 = Task("Task5")
        self.task5.label = "office"
        self.task5.date_expression = "may 6"
        self.tasks.append(self.task5)

        self.task6 = Task("Task6")
        self.task6.label = "call"
        self.task6.date_expression = "may 7"
        self.tasks.append(self.task6)

        self.task7 = Task("Task7")
        self.task7.label = "computer"
        self.task7.date_expression = "may 8"
        self.tasks.append(self.task7)

        self.task8 = Task("Task8")
        self.task8.label = "call"
        self.task8.date_expression = "may 9"
        self.tasks.append(self.task8)

        self.task9 = Task("Task9")
        self.task9.label = "office"
        self.task9.date_expression = "may 10"
        self.tasks.append(self.task9)

        self.task10 = Task("Task10")
        self.task10.label = "waiting"
        self.task10.date_expression = "may 11"
        self.tasks.append(self.task10)

        self.future_task = Task("Future Task")
        future_datetime = datetime.now() + timedelta(days=1)
        date_string = future_datetime.strftime(self.vars.date_format)
        self.future_task.due_date = DueDate(date_string)
        self.tasks.append(self.future_task)
Ejemplo n.º 10
0
 def test_contains_day(self):
     day = Day(datetime.strptime("2021-04-14", self.vars.date_format))
     result = self.calendar.contains_month(
         [DueDate("2021-04-14"),
          DueDate("2021-04-21")], day)
     self.assertTrue(result)