X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;f=plomtask%2Ftodos.py;h=cf4c33048ba779fb2145e21a4f325f55b6bfe024;hb=010ef4bfea17be7436a937f28e7b54d3da17a1e1;hp=336ec0350830ce5dfbdf5e85a92b3945608835d9;hpb=54e6c8bccace28583cf9926aa00917a796628a00;p=plomtask diff --git a/plomtask/todos.py b/plomtask/todos.py index 336ec03..cf4c330 100644 --- a/plomtask/todos.py +++ b/plomtask/todos.py @@ -170,7 +170,7 @@ class Todo(BaseModel, ConditionsRelations): return node def add_child(self, child: Todo) -> None: - """Add child to self.children, guard against recursion""" + """Add child to self.children, avoid recursion, update parenthoods.""" def walk_steps(node: Todo) -> None: if node.id_ == self.id_: raise BadFormatException('bad child choice causes recursion') @@ -186,6 +186,13 @@ class Todo(BaseModel, ConditionsRelations): self.children += [child] child.parents += [self] + def remove_child(self, child: Todo) -> None: + """Remove child from self.children, update counter relations.""" + if child not in self.children: + raise HandledException('Cannot remove un-parented child.') + self.children.remove(child) + child.parents.remove(self) + def save(self, db_conn: DatabaseConnection) -> None: """Write self and children to DB and its cache.""" if self.process.id_ is None: