1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
from sqlite3 import Cursor
import time
from typing import List
from PyQt5 import QtCore
from datetime import date
from todo.model.task import Task, ValidTaskForm
from todo.model.status import Status
from todo.model import status
def get(cursor: Cursor, s: Status) -> List[Task]:
cursor.execute(
" SELECT"
" id,"
" created_at,"
" updated_at,"
" name,"
" due_date,"
" description"
" FROM"
" tasks"
" WHERE"
" status = ?",
(status.format(s),))
res = []
for task in cursor.fetchall():
res.append(Task(
id = task[0],
created_at = task[1],
updated_at = task[2],
name = task[3],
due_date = date.fromisoformat(task[4]) if task[4] else None,
description = task[5]
))
return res
def insert(cursor: Cursor, s: Status, form: ValidTaskForm):
now = int(time.time())
cursor.execute(
" INSERT INTO tasks("
" created_at,"
" updated_at,"
" name,"
" due_date,"
" description,"
" status"
" ) VALUES (?, ?, ?, ?, ?, ?)",
(now, now, form.name, form.due_date.isoformat() if form.due_date else "", form.description, status.format(s)))
return Task(
id = cursor.lastrowid,
created_at = now,
updated_at = now,
name = form.name,
due_date = form.due_date,
description = form.description
)
def update(cursor: Cursor, task: Task, form: ValidTaskForm):
now = int(time.time())
cursor.execute(
" UPDATE tasks SET"
" updated_at = ?,"
" name = ?,"
" due_date = ?,"
" description = ?"
" WHERE id = ?",
(now, form.name, form.due_date.isoformat() if form.due_date else "", form.description, task.id))
return Task(
id = task.id,
created_at = task.created_at,
updated_at = now,
name = form.name,
due_date = form.due_date,
description = form.description
)
def delete(cursor: Cursor, ids: List[int]):
if len(ids) >= 1:
cursor.execute(
"DELETE FROM tasks WHERE id IN (%s)" % ",".join("?"*len(ids)),
ids)
def update_status(cursor: Cursor, ids: List[int], s: Status):
if len(ids) >= 1:
cursor.execute(
"UPDATE tasks SET status = ? WHERE id IN (%s)" % ",".join("?"*len(ids)),
[status.format(s)] + ids)
|