X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/blobdiff_plain/81ed71ffac3a2a5e1d289043fa65022741027dd7..41cec29a738f15fd16ef4f1b6f52cbd399ebf721:/matrix_goal_bot/db.py diff --git a/matrix_goal_bot/db.py b/matrix_goal_bot/db.py index d7896e0..eef5ace 100644 --- a/matrix_goal_bot/db.py +++ b/matrix_goal_bot/db.py @@ -28,7 +28,7 @@ class PreferGoal(SQLModel, table=True): class Goal(SQLModel, table=True): id: int | None = Field(default=None, primary_key=True) name: str = Field(default=None, unique=True) - start_date: dt | None = Field(default=today()) + # start_date: dt | None = Field(default=today()) complete_date: dt | None = Field(default=None) vision_id: int | None = Field(default=None, foreign_key="vision.id") notes: str | None = Field(default=None) @@ -65,6 +65,13 @@ def pretty_print(goal, tasks): return results +def _get_with_id(cls, item_id): + return select(cls).where(cls.id == item_id) + +def _get_with_name(cls, name): + return select(cls).where(func.lower(cls.name) == func.lower(name)) + + class Data(): def __init__(self, db_file=None): if not db_file: @@ -87,6 +94,7 @@ class Data(): prefs = session.exec(select(PreferGoal)).all() for pref in prefs: session.delete(pref) + session.commit() pref = PreferGoal() pref.goal_id = goal_id session.add(pref) @@ -98,7 +106,7 @@ class Data(): return pref.goal_id - def clear_list(self, goal_id, clear_all=False): + def clear(self, goal_id, clear_all=False): with Session(self.engine) as session: goal = session.exec(_get_with_id(Goal, goal_id)).first() for item in goal.tasks: @@ -120,7 +128,8 @@ class Data(): def get_current_goals(self): '''List current goals''' with Session(self.engine) as session: - cmd = select(Goal).where(Goal.complete_date == None).where(Goal.start_date <= today()) + # cmd = select(Goal).where(Goal.complete_date == None).where(Goal.start_date <= today()) + cmd = select(Goal).where(Goal.complete_date == None) return session.exec(cmd).all() def get_done_goals(self):