X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Fconditions.py;h=a45260092fdc6c75a94846eb0893b775eb9316dd;hb=ee18435127ad396c24dbee2c7efcdbe6810d5a91;hp=b2ecda14cb7cef0b5bf350d1a253389ea32aabb7;hpb=23c7ff7f9833ff5b0e547c19a4ad85325a5d3400;p=plomtask diff --git a/plomtask/conditions.py b/plomtask/conditions.py index b2ecda1..a452600 100644 --- a/plomtask/conditions.py +++ b/plomtask/conditions.py @@ -4,16 +4,15 @@ from typing import Any from sqlite3 import Row from plomtask.db import DatabaseConnection, BaseModel from plomtask.misc import VersionedAttribute -from plomtask.exceptions import NotFoundException class Condition(BaseModel[int]): - """Non Process-dependency for ProcessSteps and Todos.""" + """Non-Process dependency for ProcessSteps and Todos.""" table_name = 'conditions' to_save = ['is_active'] def __init__(self, id_: int | None, is_active: bool = False) -> None: - self.set_int_id(id_) + super().__init__(id_) self.is_active = is_active self.title = VersionedAttribute(self, 'condition_titles', 'UNNAMED') self.description = VersionedAttribute(self, 'condition_descriptions', @@ -30,34 +29,6 @@ class Condition(BaseModel[int]): getattr(condition, name).history_from_row(row_) return condition - @classmethod - def all(cls, db_conn: DatabaseConnection) -> list[Condition]: - """Collect all Conditions and their VersionedAttributes.""" - conditions = {} - for id_, condition in cls.cache_.items(): - conditions[id_] = condition - already_recorded = conditions.keys() - for id_ in db_conn.column_all('conditions', 'id'): - if id_ not in already_recorded: - condition = cls.by_id(db_conn, id_) - assert isinstance(condition.id_, int) - conditions[condition.id_] = condition - return list(conditions.values()) - - @classmethod - def by_id(cls, db_conn: DatabaseConnection, id_: int | None, - create: bool = False) -> Condition: - """Collect (or create) Condition and its VersionedAttributes.""" - condition = None - if id_: - condition, _ = super()._by_id(db_conn, id_) - if not condition: - if not create: - raise NotFoundException(f'Condition not found of id: {id_}') - condition = cls(id_, False) - condition.save(db_conn) - return condition - def save(self, db_conn: DatabaseConnection) -> None: """Save self and its VersionedAttributes to DB and cache.""" self.save_core(db_conn)