X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_free?a=blobdiff_plain;ds=sidebyside;f=plomtask%2Fprocesses.py;h=d007d0f0ff14303e7668146323f0b2384a35cf55;hb=25b71c6f0b10db05907128daf50c6e543e514c35;hp=06ee4ba9b9c2a3011019b03b1b0e21633fce780c;hpb=c5449a0b00f8865b1129ed56bdd16f1cc055bc87;p=plomtask diff --git a/plomtask/processes.py b/plomtask/processes.py index 06ee4ba..d007d0f 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -34,6 +34,7 @@ class Process(BaseModel[int], ConditionsRelations): ('process_step_suppressions', 'process', 'suppressed_steps', 0)] to_search = ['title.newest', 'description.newest'] + can_create_by_id = True def __init__(self, id_: int | None, calendarize: bool = False) -> None: BaseModel.__init__(self, id_) @@ -46,16 +47,20 @@ class Process(BaseModel[int], ConditionsRelations): self.calendarize = calendarize self.n_owners: int | None = None # only set by from_table_row + @property + def as_dict(self) -> dict[str, object]: + """Return self as (json.dumps-coompatible) dict.""" + d = super().as_dict + d['explicit_steps'] = [s.as_dict for s in self.explicit_steps] + d['suppressed_steps'] = [s.as_dict for s in self.suppressed_steps] + return d + @classmethod def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any]) -> Process: """Make from DB row, with dependencies.""" process = super().from_table_row(db_conn, row) - assert isinstance(process.id_, int) - for name in ('title', 'description', 'effort'): - table = f'process_{name}s' - for row_ in db_conn.row_where(table, 'parent', process.id_): - getattr(process, name).history_from_row(row_) + assert process.id_ is not None for name in ('conditions', 'blockers', 'enables', 'disables'): table = f'process_{name}' assert isinstance(process.id_, int) @@ -218,7 +223,7 @@ class ProcessStep(BaseModel[int]): self.parent_step_id = parent_step_id def save(self, db_conn: DatabaseConnection) -> None: - """Remove from DB, and owner's .explicit_steps.""" + """Update into DB/cache, and owner's .explicit_steps.""" super().save(db_conn) owner = Process.by_id(db_conn, self.owner_id) if self not in owner.explicit_steps: