This repository has been archived by the owner on Jan 20, 2024. It is now read-only.
/
task.py
40 lines (39 loc) · 1.49 KB
/
task.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
from project_amber.db import db
class Task(db.Model):
"""
Task model. Contains a task ID, the owner, the subject, and the lastmod /
creation time.
"""
id = db.Column(db.Integer, primary_key=True)
owner = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False)
text = db.Column(db.String(65536))
gen = db.Column(db.Integer, nullable=False)
parent_id = db.Column(db.Integer, db.ForeignKey("task.id"))
status = db.Column(db.Integer, nullable=False)
creation_time = db.Column(db.Integer, nullable=False)
last_mod_time = db.Column(db.Integer, nullable=False)
deadline = db.Column(db.Integer)
reminder = db.Column(db.Integer)
def is_child(self) -> bool:
"""
Helper method. Simply checks whether the task is of gen 0 or not.
"""
if self.gen > 0:
return True
return False
def toDict(self) -> dict:
"""
Helper method that converts public task data (ID, text, PID, status,
modtime, deadline and reminders) to a dict that can be safely used in
JSON serialization. Returns the resulting dict.
"""
result = {
"id": self.id,
"text": self.text,
"status": self.status,
"last_mod": self.last_mod_time
}
if self.parent_id: result["parent_id"] = self.parent_id
if self.deadline: result["deadline"] = self.deadline
if self.reminder: result["reminder"] = self.reminder
return result