process = Process.by_id(self.conn, process_id)
todo = Todo(None, process, False, day.date)
todo.save(self.conn)
- for step in todo.process.explicit_steps:
- for t in [t for t in existing_todos
- if t.process.id_ == step.step_process_id]:
- todo.add_child(t)
- break
+ todo.adopt_from(existing_todos)
todo.save(self.conn)
def do_POST_todo(self) -> None:
self.enables: list[Condition] = []
self.disables: list[Condition] = []
if not self.id_:
- self.conditions = process.conditions[:]
- self.enables = process.enables[:]
- self.disables = process.disables[:]
+ self.conditions = self.process.conditions[:]
+ self.enables = self.process.enables[:]
+ self.disables = self.process.disables[:]
@classmethod
def from_table_row(cls, db_conn: DatabaseConnection,
"""Return ID of tasked Process."""
return self.process.id_
+ @property
+ def unsatisfied_dependencies(self) -> list[int]:
+ """Return Process IDs of .process.explicit_steps not in .children."""
+ child_process_ids = {c.process.id_ for c in self.children}
+ unsatisfied: list[int] = []
+ for process_id in [s.step_process_id
+ for s in self.process.explicit_steps]:
+ if process_id not in child_process_ids:
+ unsatisfied += [process_id]
+ return unsatisfied
+
@property
def is_done(self) -> bool:
"""Wrapper around self._is_done so we can control its setter."""
for condition in self.disables:
condition.is_active = False
+ def adopt_from(self, todos: list[Todo]) -> None:
+ """As far as possible, fill unsatisfied dependencies from todos."""
+ for process_id in self.unsatisfied_dependencies:
+ for todo in [t for t in todos if t.process.id_ == process_id]:
+ self.add_child(todo)
+ break
+
def get_step_tree(self, seen_todos: set[int],
seen_conditions: set[int]) -> TodoStepsNode:
"""Return tree of depended-on Todos and Conditions."""