X-Git-Url: https://apps.delaporte.us/gitweb/matrix-goal-bot.git/blobdiff_plain/f5b4674001d94e6aadbfbcd074fd730917e6c89d..20c4ba82eda7e71635190228655360ee9a37f6c3:/goals/db.py diff --git a/goals/db.py b/goals/db.py index 6c3c332..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 @@ -90,10 +102,15 @@ class Data(): goal = session.exec(cmd).first() goal.complete_date = dt.today() session.commit() - return self.get_goal(id) 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