From 3844f76d18e376777ca4d7c124df6d6b4896a361 Mon Sep 17 00:00:00 2001 From: Joris Date: Mon, 1 Jun 2020 09:11:02 +0200 Subject: Separate tasks panel on status --- src/db/init.py | 3 ++- src/db/tasks.py | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) (limited to 'src/db') diff --git a/src/db/init.py b/src/db/init.py index 77920cf..5d847a3 100644 --- a/src/db/init.py +++ b/src/db/init.py @@ -21,7 +21,8 @@ def init(path): " duration INTEGER," " difficulty INT," " priority INT," - " description TEXT" + " description TEXT," + " status TEXT" " )") cursor.execute( diff --git a/src/db/tasks.py b/src/db/tasks.py index 142abae..dca7710 100644 --- a/src/db/tasks.py +++ b/src/db/tasks.py @@ -3,8 +3,10 @@ import time from typing import List from model.task import Task, ValidTaskForm +from model.status import Status +from model import difficulty, priority, status -def get(cursor: Cursor) -> List[Task]: +def get(cursor: Cursor, s: Status) -> List[Task]: cursor.execute( " SELECT" " id," @@ -15,7 +17,11 @@ def get(cursor: Cursor) -> List[Task]: " difficulty," " priority," " description" - " FROM tasks") + " FROM" + " tasks" + " WHERE" + " status = ?", + (status.format(s),)) res = [] @@ -26,14 +32,14 @@ def get(cursor: Cursor) -> List[Task]: updated_at = task[2], name = task[3], duration = task[4], - difficulty = task[5], - priority = task[6], + difficulty = difficulty.parse(task[5]), + priority = priority.parse(task[6]), description = task[7] )) return res -def insert(cursor: Cursor, form: ValidTaskForm): +def insert(cursor: Cursor, s: Status, form: ValidTaskForm): now = int(time.time()) cursor.execute( " INSERT INTO tasks(" @@ -43,9 +49,10 @@ def insert(cursor: Cursor, form: ValidTaskForm): " duration," " difficulty," " priority," - " description" - " ) VALUES (?, ?, ?, ?, ?, ?, ?)", - (now, now, form.name, form.duration, int(form.difficulty), int(form.priority), form.description)) + " description," + " status" + " ) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", + (now, now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, status.format(s))) return Task( id = cursor.lastrowid, @@ -70,7 +77,7 @@ def update(cursor: Cursor, task: Task, form: ValidTaskForm): " priority = ?," " description = ?" " WHERE id = ?", - (now, form.name, form.duration, int(form.difficulty), int(form.priority), form.description, task.id)) + (now, form.name, form.duration, difficulty.format(form.difficulty), priority.format(form.priority), form.description, task.id)) return Task( id = task.id, -- cgit v1.2.3