+ @property
+ def is_doable(self) -> bool:
+ """Decide whether .is_done can be set to True based on children's."""
+ for child in self.children:
+ if not child.is_done:
+ return False
+ return True
+
+ @property
+ def is_done(self) -> bool:
+ """Wrapper around self._is_done so we can control its setter."""
+ return self._is_done
+
+ @is_done.setter
+ def is_done(self, value: bool) -> None:
+ if value != self.is_done and not self.is_doable:
+ raise BadFormatException('cannot change doneness of undoable Todo')
+ self._is_done = value
+
+ def add_child(self, child: Todo) -> None:
+ """Add child to self.children, guard against recursion"""
+ def walk_steps(node: Todo) -> None:
+ if node.id_ == self.id_:
+ raise BadFormatException('bad child choice causes recursion')
+ for child in node.children:
+ walk_steps(child)
+ if self.id_ is None:
+ raise HandledException('Can only add children to saved Todos.')
+ if child.id_ is None:
+ raise HandledException('Can only add saved children to Todos.')
+ if child in self.children:
+ raise BadFormatException('cannot adopt same child twice')
+ walk_steps(child)
+ self.children += [child]
+ child.parents += [self]
+