+ @staticmethod
+ def _x_ablers_for_at(db_conn: DatabaseConnection, name: str,
+ cond: Condition, date: str) -> list[Todo]:
+ """Collect all Todos of day that [name] condition."""
+ assert isinstance(cond.id_, int)
+ x_ablers = []
+ table = f'todo_{name}'
+ for id_ in db_conn.column_where(table, 'todo', 'condition', cond.id_):
+ todo = Todo.by_id(db_conn, id_)
+ if todo.date == date:
+ x_ablers += [todo]
+ return x_ablers
+
+ @classmethod
+ def enablers_for_at(cls, db_conn: DatabaseConnection,
+ condition: Condition, date: str) -> list[Todo]:
+ """Collect all Todos of day that enable condition."""
+ return cls._x_ablers_for_at(db_conn, 'enables', condition, date)
+
+ @classmethod
+ def disablers_for_at(cls, db_conn: DatabaseConnection,
+ condition: Condition, date: str) -> list[Todo]:
+ """Collect all Todos of day that disable condition."""
+ return cls._x_ablers_for_at(db_conn, 'disables', condition, date)
+
+ @property
+ def is_doable(self) -> bool:
+ """Decide whether .is_done settable based on children, Conditions."""
+ for child in self.children:
+ if not child.is_done:
+ return False
+ for condition in self.conditions:
+ if not condition.is_active:
+ return False
+ return True
+
+ @property
+ def process_id(self) -> int | str | None:
+ """Return ID of tasked Process."""
+ return self.process.id_
+
+ @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')
+ if self._is_done != value:
+ self._is_done = value
+ if value is True:
+ for condition in self.enables:
+ condition.is_active = True
+ for condition in self.disables:
+ condition.is_active = False
+
+ def set_disables(self, db_conn: DatabaseConnection,
+ ids: list[int]) -> None:
+ """Set self.disables to Conditions identified by ids."""
+ self.set_conditions(db_conn, ids, 'disables')
+
+ def set_enables(self, db_conn: DatabaseConnection,
+ ids: list[int]) -> None:
+ """Set self.enables to Conditions identified by ids."""
+ self.set_conditions(db_conn, ids, 'enables')
+
+ 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_)]
+