PaperParser/app/models/session.py

24 lines
811 B
Python
Raw Normal View History

2024-01-31 19:37:01 +10:00
from typing import List
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.task import Task
from app.models.user import User
from app.extensions import db
class Session(db.Model):
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(unique=True)
authorized: Mapped[bool]
users: Mapped[List[User]] = relationship("User", cascade="all, delete-orphan", back_populates="session")
2024-01-31 19:37:01 +10:00
tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session")
2024-01-31 19:37:01 +10:00
def has_depending_tasks(self):
tasks = Task.query \
.filter_by(session_id=self.id) \
.filter((Task.status == "RUNNING") | (Task.status == "RUNNING")) \
.all()
return len(tasks) > 0