X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/static/gitweb.css?a=blobdiff_plain;f=plomtask%2Fprocesses.py;h=bb1de3a4a3356415473bc652d650e202886eb01b;hb=refs%2Fheads%2Fmaster;hp=d007d0f0ff14303e7668146323f0b2384a35cf55;hpb=25b71c6f0b10db05907128daf50c6e543e514c35;p=plomtask diff --git a/plomtask/processes.py b/plomtask/processes.py index d007d0f..9870ab3 100644 --- a/plomtask/processes.py +++ b/plomtask/processes.py @@ -25,36 +25,34 @@ class Process(BaseModel[int], ConditionsRelations): """Template for, and metadata for, Todos, and their arrangements.""" # pylint: disable=too-many-instance-attributes table_name = 'processes' - to_save = ['calendarize'] - to_save_versioned = ['title', 'description', 'effort'] + to_save_simples = ['calendarize'] to_save_relations = [('process_conditions', 'process', 'conditions', 0), ('process_blockers', 'process', 'blockers', 0), ('process_enables', 'process', 'enables', 0), ('process_disables', 'process', 'disables', 0), ('process_step_suppressions', 'process', 'suppressed_steps', 0)] + add_to_dict = ['explicit_steps'] + versioned_defaults = {'title': 'UNNAMED', 'description': '', 'effort': 1.0} to_search = ['title.newest', 'description.newest'] can_create_by_id = True + sorters = {'steps': lambda p: len(p.explicit_steps), + 'owners': lambda p: p.n_owners, + 'effort': lambda p: p.effort.newest, + 'title': lambda p: p.title.newest} def __init__(self, id_: int | None, calendarize: bool = False) -> None: BaseModel.__init__(self, id_) ConditionsRelations.__init__(self) - self.title = VersionedAttribute(self, 'process_titles', 'UNNAMED') - self.description = VersionedAttribute(self, 'process_descriptions', '') - self.effort = VersionedAttribute(self, 'process_efforts', 1.0) + for name in ['title', 'description', 'effort']: + attr = VersionedAttribute(self, f'process_{name}s', + self.versioned_defaults[name]) + setattr(self, name, attr) self.explicit_steps: list[ProcessStep] = [] self.suppressed_steps: list[ProcessStep] = [] 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: @@ -213,7 +211,7 @@ class Process(BaseModel[int], ConditionsRelations): class ProcessStep(BaseModel[int]): """Sub-unit of Processes.""" table_name = 'process_steps' - to_save = ['owner_id', 'step_process_id', 'parent_step_id'] + to_save_simples = ['owner_id', 'step_process_id', 'parent_step_id'] def __init__(self, id_: int | None, owner_id: int, step_process_id: int, parent_step_id: int | None) -> None: