X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomtask%2Ftodos.py;h=a7af99faa3a298e27548e7a7234699c1cf8038fc;hb=77e9d9dfa5681bc32e8aec8558d0fa449805e3ac;hp=7cbe989b538018e480d24752d2d0cc44450f7396;hpb=b0758d1c63db38867ef12ee89317524a7436129d;p=plomtask diff --git a/plomtask/todos.py b/plomtask/todos.py index 7cbe989..a7af99f 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -23,18 +23,24 @@ class Todo(BaseModel[int], ConditionsRelations): """Individual actionable.""" # pylint: disable=too-many-instance-attributes table_name = 'todos' - to_save = ['process_id', 'is_done', 'date', 'comment', 'effort'] + to_save = ['process_id', 'is_done', 'date', 'comment', 'effort', + 'calendarize'] to_save_relations = [('todo_conditions', 'todo', 'conditions'), + ('todo_blockers', 'todo', 'blockers'), ('todo_enables', 'todo', 'enables'), ('todo_disables', 'todo', 'disables'), ('todo_children', 'parent', 'children'), ('todo_children', 'child', 'parents')] # pylint: disable=too-many-arguments - def __init__(self, id_: int | None, process: Process, - is_done: bool, date: str, comment: str = '', - effort: None | float = None) -> None: - super().__init__(id_) + def __init__(self, id_: int | None, + process: Process, + is_done: bool, + date: str, comment: str = '', + effort: None | float = None, + calendarize: bool = False) -> None: + BaseModel.__init__(self, id_) + ConditionsRelations.__init__(self) if process.id_ is None: raise NotFoundException('Process of Todo without ID (not saved?)') self.process = process @@ -44,11 +50,11 @@ class Todo(BaseModel[int], ConditionsRelations): self.effort = effort self.children: list[Todo] = [] self.parents: list[Todo] = [] - self.conditions: list[Condition] = [] - self.enables: list[Condition] = [] - self.disables: list[Condition] = [] + self.calendarize = calendarize if not self.id_: + self.calendarize = self.process.calendarize self.conditions = self.process.conditions[:] + self.blockers = self.process.blockers[:] self.enables = self.process.enables[:] self.disables = self.process.disables[:] @@ -71,7 +77,7 @@ class Todo(BaseModel[int], ConditionsRelations): 'child', todo.id_): # pylint: disable=no-member todo.parents += [cls.by_id(db_conn, t_id)] - for name in ('conditions', 'enables', 'disables'): + for name in ('conditions', 'blockers', 'enables', 'disables'): table = f'todo_{name}' assert isinstance(todo.id_, int) for cond_id in db_conn.column_where(table, 'condition', @@ -97,6 +103,18 @@ class Todo(BaseModel[int], ConditionsRelations): for condition in self.conditions: if not condition.is_active: return False + for condition in self.blockers: + if condition.is_active: + return False + return True + + @property + def is_deletable(self) -> bool: + """Decide whether self be deletable (not if preserve-worthy values).""" + if self.comment: + return False + if self.effort and self.effort >= 0: + return False return True @property @@ -195,8 +213,17 @@ class Todo(BaseModel[int], ConditionsRelations): self.children.remove(child) child.parents.remove(self) + def save(self, db_conn: DatabaseConnection) -> None: + """On save calls, also check if auto-deletion by effort < 0.""" + if self.effort and self.effort < 0 and self.is_deletable: + self.remove(db_conn) + return + super().save(db_conn) + def remove(self, db_conn: DatabaseConnection) -> None: """Remove from DB, including relations.""" + if not self.is_deletable: + raise HandledException('Cannot remove non-deletable Todo.') children_to_remove = self.children[:] parents_to_remove = self.parents[:] for child in children_to_remove: