todo/todo/Task.py

43 lines
1.1 KiB
Python

from __future__ import annotations
from typing import Union
from datetime import datetime
from .Note import Note
from .TodoObject import TodoObject
class Task(TodoObject):
def __init__(self, name : str, date = Union[datetime, None], complete: bool = False, level: int = 0, parent = None):
self.date = date
self.complete = complete
super().__init__(level, name, parent)
def get_subtasks(self) -> list[Task]:
tasks = []
for child in self.children:
if isinstance(child, Task):
tasks.append(child)
return tasks
def get_notes(self):
notes = []
for child in self.children:
if isinstance(child, Note):
notes.append(child)
def __str__(self):
output = ""
if self.complete:
output += "- [x]"
else:
output += "- [ ]"
if self.date is not None:
self.date: datetime
output += f" {self.text} |{self.date.strftime('%b %d %Y')}"
else:
output += f" {self.text}"
return output
def __add__(self, other):
return other + self.__str__()