X-Git-Url: https://plomlompom.com/repos/feed.xml?a=blobdiff_plain;f=plomtask%2Fdays.py;h=a924bbfeadd2bd895d2f21ac4b7487305fbe771f;hb=HEAD;hp=68cf989643924a42b1ef8b48cc04a63434efe6b9;hpb=21df71ef1fde304b158da5989692c01f463515b5;p=plomtask diff --git a/plomtask/days.py b/plomtask/days.py index 68cf989..2320130 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -12,6 +12,7 @@ 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: @@ -24,15 +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 - assert isinstance(d['_library'], dict) - d['todos'] = [t.as_dict_into_reference(d['_library']) - for t in self.todos] - return d - @classmethod def from_table_row(cls, db_conn: DatabaseConnection, row: Row | list[Any] ) -> Day: @@ -44,8 +36,15 @@ class Day(BaseModel[str]): @classmethod 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_) + """Extend BaseModel.by_id + + Checks Todo.days_to_update if we need to a retrieved Day's .todos, + and also ensures we're looking for proper dates and not strings like + "yesterday" by enforcing the valid_date translation. + """ + assert isinstance(id_, str) + possibly_translated_date = valid_date(id_) + day = super().by_id(db_conn, possibly_translated_date) if day.id_ in Todo.days_to_update: Todo.days_to_update.remove(day.id_) day.todos = Todo.by_date(db_conn, day.id_)