X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/blobdiff_plain/d9963fa251c1068be30ed1307fe8d8531e618f20..20c4ba82eda7e71635190228655360ee9a37f6c3:/goals/db.py diff --git a/goals/db.py b/goals/db.py index fa88dc5..2921bf0 100644 --- a/goals/db.py +++ b/goals/db.py @@ -46,6 +46,18 @@ class Task(SQLModel, table=True): def __str__(self): return f'{self.name} ({self.id})' + +def pretty_print(goal, tasks): + results = [] + results.append(f' ## {goal}') + for task in tasks: + if(task.complete_date): + results.append(f' - [x] {task}') + else: + results.append(f' - [ ] {task}') + return results + + class Data(): def __init__(self, db_file = DB_FILE): self.file = db_file @@ -85,10 +97,20 @@ class Data(): pass def complete_goal(self, id): - pass + with Session(self.engine) as session: + cmd = select(Goal).where(Goal.id == id) + goal = session.exec(cmd).first() + goal.complete_date = dt.today() + session.commit() def complete_task(self, id): - pass + with Session(self.engine) as session: + cmd = select(Task).where(Task.id == id) + task = session.exec(cmd).first() + task.complete_date = dt.today() + goal_id = task.goal_id + session.commit() + return goal_id def add_with_name(self, cls, name): id = -1