-
Notifications
You must be signed in to change notification settings - Fork 1
/
task_type.py
90 lines (74 loc) · 2.12 KB
/
task_type.py
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
from database import DB
class TaskType:
def __init__(self, title):
self.title = title
def create(self):
with DB() as db:
values = (None, self.title)
db.execute(
'''
INSERT INTO task_types
VALUES (?, ?)
''', values
)
return self
@staticmethod
def get_all_types():
with DB() as db:
return db.execute(
'''
SELECT * FROM task_types
'''
).fetchall()
@staticmethod
def get_task_type_by_title(title):
if not title:
return None
with DB() as db:
return db.execute(
'''
SELECT * FROM task_types
WHERE title = ?
''', (title,)
).fetchone()
@staticmethod
def get_task_type_title_by_id(task_type_id):
if not task_type_id:
return None
with DB() as db:
return db.execute(
'''
SELECT title FROM task_types
WHERE id = ?
''', (str(task_type_id),)
).fetchone()[0]
@staticmethod
def update_task_type_title_for_id(task_type_id, new_title):
if not task_type_id:
return None
with DB() as db:
row = db.execute(
'''
SELECT * FROM task_types
WHERE id = ?
''', (str(task_type_id),)
).fetchone()
if row:
db.execute(
'''
UPDATE task_types
SET title = ?
WHERE id = ?
''', (new_title, str(task_type_id),)
)
else:
return False
def delete(self):
with DB() as db:
db.execute(
'''
DELETE FROM task_types
WHERE title = ?
''', (self.title,)
)
return self