- def set_undoes(self, db_conn: DatabaseConnection, ids: list[int]) -> None:
- """Set self.undoes to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'undoes')
-
- def set_fulfills(self, db_conn: DatabaseConnection,
- ids: list[int]) -> None:
- """Set self.fulfills to Conditions identified by ids."""
- self.set_conditions(db_conn, ids, 'fulfills')
-
- def set_conditions(self, db_conn: DatabaseConnection, ids: list[int],
- target: str = 'conditions') -> None:
- """Set self.[target] to Conditions identified by ids."""
- target_list = getattr(self, target)
- while len(target_list) > 0:
- target_list.pop()
- for id_ in ids:
- target_list += [Condition.by_id(db_conn, id_)]
+ @property
+ def title(self) -> VersionedAttribute:
+ """Shortcut to .process.title."""
+ return self.process.title
+
+ def adopt_from(self, todos: list[Todo]) -> bool:
+ """As far as possible, fill unsatisfied dependencies from todos."""
+ adopted = False
+ for process_id in self.unsatisfied_dependencies:
+ for todo in [t for t in todos if t.process.id_ == process_id
+ and t not in self.children]:
+ self.add_child(todo)
+ adopted = True
+ break
+ return adopted
+
+ def make_missing_children(self, db_conn: DatabaseConnection) -> None:
+ """Fill unsatisfied dependencies with new Todos."""
+ for process_id in self.unsatisfied_dependencies:
+ process = Process.by_id(db_conn, process_id)
+ todo = self.__class__(None, process, False, self.date)
+ todo.save(db_conn)
+ self.add_child(todo)
+
+ def get_step_tree(self, seen_todos: set[int]) -> TodoNode:
+ """Return tree of depended-on Todos."""
+
+ def make_node(todo: Todo) -> TodoNode:
+ children = []
+ seen = todo.id_ in seen_todos
+ assert isinstance(todo.id_, int)
+ seen_todos.add(todo.id_)
+ for child in todo.children:
+ children += [make_node(child)]
+ return TodoNode(todo, seen, children)
+
+ return make_node(self)