X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Fdays.py;h=92e44b2330b27caf7da9a3fce9ffca8aff3e7bc5;hb=5a393ec6a77d8f1040763ffa3e9e908f38a0e517;hp=a924bbfeadd2bd895d2f21ac4b7487305fbe771f;hpb=db62e6559fdd577dae38d4b6f5cbd5ef6a14cc57;p=plomtask diff --git a/plomtask/days.py b/plomtask/days.py index a924bbf..92e44b2 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -12,6 +12,8 @@ class Day(BaseModel[str]): """Individual days defined by their dates.""" table_name = 'days' to_save = ['comment'] + add_to_dict = ['todos'] + can_create_by_id = True def __init__(self, date: str, comment: str = '') -> None: id_ = valid_date(date) @@ -23,13 +25,6 @@ class Day(BaseModel[str]): def __lt__(self, other: Day) -> bool: return self.date < other.date - @property - def as_dict(self) -> dict[str, object]: - """Return self as (json.dumps-coompatible) dict.""" - d = super().as_dict - d['todos'] = [t.as_dict for t in self.todos] - return d - @classmethod def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any] ) -> Day: @@ -40,13 +35,9 @@ class Day(BaseModel[str]): return day @classmethod - def by_id(cls, - db_conn: DatabaseConnection, id_: str | None, - create: bool = False, - ) -> Day: + def by_id(cls, db_conn: DatabaseConnection, id_: str) -> Day: """Extend BaseModel.by_id checking for new/lost .todos.""" - day = super().by_id(db_conn, id_, create) - assert day.id_ is not None + day = super().by_id(db_conn, id_) if day.id_ in Todo.days_to_update: Todo.days_to_update.remove(day.id_) day.todos = Todo.by_date(db_conn, day.id_)