24 lines
811 B
Python
24 lines
811 B
Python
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")
|
|
|
|
tasks: Mapped[List[Task]] = relationship("Task", cascade="all, delete-orphan", back_populates="session")
|
|
|
|
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
|
|
|