87 lines
3.8 KiB
Python
87 lines
3.8 KiB
Python
from datetime import datetime, timezone
|
|
|
|
from app.extensions import db
|
|
|
|
|
|
class TaskList(db.Model):
|
|
__tablename__ = 'task_lists'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
owner_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
|
|
name = db.Column(db.String(255), nullable=False)
|
|
color = db.Column(db.String(7), default='#10b981')
|
|
description = db.Column(db.Text, nullable=True)
|
|
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
tasks = db.relationship('Task', backref='task_list', lazy='dynamic',
|
|
cascade='all, delete-orphan')
|
|
shares = db.relationship('TaskListShare', backref='task_list', lazy='dynamic',
|
|
cascade='all, delete-orphan')
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'owner_id': self.owner_id,
|
|
'name': self.name,
|
|
'color': self.color,
|
|
'description': self.description,
|
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
|
}
|
|
|
|
|
|
class Task(db.Model):
|
|
__tablename__ = 'tasks'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
task_list_id = db.Column(db.Integer, db.ForeignKey('task_lists.id'), nullable=False, index=True)
|
|
uid = db.Column(db.String(255), unique=True, nullable=False)
|
|
ical_data = db.Column(db.Text, nullable=False, default='') # Full VTODO block
|
|
summary = db.Column(db.String(500), nullable=True)
|
|
description = db.Column(db.Text, nullable=True)
|
|
status = db.Column(db.String(32), nullable=True) # NEEDS-ACTION | IN-PROCESS | COMPLETED | CANCELLED
|
|
priority = db.Column(db.Integer, nullable=True) # 0 (keine) - 9
|
|
percent_complete = db.Column(db.Integer, nullable=True) # 0..100
|
|
due = db.Column(db.DateTime, nullable=True, index=True)
|
|
dtstart = db.Column(db.DateTime, nullable=True)
|
|
completed_at = db.Column(db.DateTime, nullable=True)
|
|
categories = db.Column(db.Text, nullable=True) # kommagetrennt
|
|
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
|
|
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
|
|
onupdate=lambda: datetime.now(timezone.utc))
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'task_list_id': self.task_list_id,
|
|
'uid': self.uid,
|
|
'summary': self.summary,
|
|
'description': self.description,
|
|
'status': self.status or 'NEEDS-ACTION',
|
|
'priority': self.priority,
|
|
'percent_complete': self.percent_complete,
|
|
'due': self.due.isoformat() if self.due else None,
|
|
'dtstart': self.dtstart.isoformat() if self.dtstart else None,
|
|
'completed_at': self.completed_at.isoformat() if self.completed_at else None,
|
|
'categories': self.categories.split(',') if self.categories else [],
|
|
'created_at': self.created_at.isoformat() if self.created_at else None,
|
|
'updated_at': self.updated_at.isoformat() if self.updated_at else None,
|
|
}
|
|
|
|
|
|
class TaskListShare(db.Model):
|
|
__tablename__ = 'task_list_shares'
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
task_list_id = db.Column(db.Integer, db.ForeignKey('task_lists.id'), nullable=False, index=True)
|
|
shared_with_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False, index=True)
|
|
permission = db.Column(db.String(20), nullable=False, default='read')
|
|
color = db.Column(db.String(7), nullable=True)
|
|
|
|
shared_with = db.relationship('User', backref='shared_task_lists')
|
|
|
|
__table_args__ = (
|
|
db.UniqueConstraint('task_list_id', 'shared_with_id', name='uq_task_list_share'),
|
|
)
|