Files
tasklist-plugin/data.py
Interitio 48eda11e1d feat: Migration v0 to v1.
Move 'tasklist' table to 'taskslist' for compatibility.
Add migration sql script.
Add 'taskslist_info' view.
Add 'completed_in' to tasks.
2025-10-02 20:32:00 +10:00

79 lines
1.6 KiB
Python

import datetime as dt
from data import Registry, RowModel, Table
from data.columns import String, Timestamp, Integer, Bool
class Task(RowModel):
"""
Schema
------
"""
_tablename_ = 'taskslist'
_cache_ = {}
taskid = Integer(primary=True)
profileid = Integer()
content = String()
created_at = Timestamp()
deleted_at = Timestamp()
duration = Integer()
started_at = Timestamp()
completed_at = Timestamp()
completed_in = Integer()
_timestamp = Timestamp()
class TaskProfile(RowModel):
"""
Schema
------
"""
_tablename_ = 'task_profiles'
_cache_ = {}
profileid = Integer(primary=True)
show_tips = Bool()
show_encouragement = Bool()
class TaskInfo(RowModel):
_tablename_ = 'taskslist_info'
taskid = Integer(primary=True)
profileid = Integer()
content = String()
created_at = Timestamp()
duration = Integer()
started_at = Timestamp()
completed_at = Timestamp()
completed_in = Integer()
last_started = Timestamp()
order_idx = Integer()
is_running = Bool()
is_planned = Bool()
is_complete = Bool()
show_tips = Bool()
show_encouragement = Bool()
tasklabel = Integer()
@property
def total_duration(self):
dur = self.duration
if self.is_running and self.last_started:
dur += (dt.datetime.now(tz=dt.UTC) - self.last_started).total_seconds()
return int(dur)
class TaskData(Registry):
tasklist = Task.table
task_profiles = TaskProfile.table
tasklist_info = TaskInfo.table
nowlist = Table('nowlist')
taskplan = Table('taskplan')