- def by_id(cls, db_conn: DatabaseConnection, id_: int | None) -> Todo:
- """Get Todo of .id_=id_ and children (from DB cache if possible)."""
- if id_:
- todo, from_cache = super()._by_id(db_conn, id_)
- else:
- todo, from_cache = None, False
- if todo is None:
- raise NotFoundException(f'Todo of ID not found: {id_}')
- if not from_cache:
- for row in db_conn.exec('SELECT child FROM todo_children '
- 'WHERE parent = ?', (id_,)):
- todo.children += [cls.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT parent FROM todo_children '
- 'WHERE child = ?', (id_,)):
- todo.parents += [cls.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_conditions '
- 'WHERE todo = ?', (id_,)):
- todo.conditions += [Condition.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_fulfills '
- 'WHERE todo = ?', (id_,)):
- todo.fulfills += [Condition.by_id(db_conn, row[0])]
- for row in db_conn.exec('SELECT condition FROM todo_undoes '
- 'WHERE todo = ?', (id_,)):
- todo.undoes += [Condition.by_id(db_conn, row[0])]
- assert isinstance(todo, Todo)
- return todo
+ def by_process_id(cls, db_conn: DatabaseConnection,
+ process_id: int | None) -> list[Todo]:
+ """Collect all Todos of Process of process_id."""
+ return [t for t in cls.all(db_conn) if t.process.id_ == process_id]