todo/todo/Category.py

29 lines
796 B
Python

from __future__ import annotations
from .Task import Task
from .TodoObject import TodoObject
class Category(TodoObject):
def __init__(self, name : str, level: int, parent = None):
super().__init__(level, name, parent)
def get_subcategories(self) -> list[Category]:
categories = []
for child in self.children:
if isinstance(child, Category):
categories.append(child)
return categories
def get_tasks(self) -> list[Task]:
tasks = []
for child in self.children:
if isinstance(child, Task):
tasks.append(child)
return tasks
def __str__(self):
return "#"*(self.level+1) + f" {self.text}"
def __add__(self, other):
return other + self.__str__()