From: Christian Heller Date: Fri, 21 Jun 2024 21:29:18 +0000 (+0200) Subject: Fuse Day.by_id_or_create and Day.by_id, as valid_date call in the first one fits... X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%22https:/validator.w3.org/balance?a=commitdiff_plain;h=0274be2e09f4b9c9cffa9e6737a8b128e0fab76d;p=plomtask Fuse Day.by_id_or_create and Day.by_id, as valid_date call in the first one fits better into the second. --- diff --git a/plomtask/days.py b/plomtask/days.py index 7e6a5cc..2320130 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -34,17 +34,17 @@ class Day(BaseModel[str]): day.todos = Todo.by_date(db_conn, day.id_) return day - @classmethod - def by_id_or_create(cls, db_conn: DatabaseConnection, id_: str | None - ) -> Day: - """Extend BaseModel.by_id to ensure date name translation.""" - assert isinstance(id_, str) - return super().by_id_or_create(db_conn, valid_date(id_)) - @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_)