PaperParser/app/models/session.py

22 lines
690 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.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]
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) \
2024-02-03 22:29:56 +10:00
.filter((Task.status == "RUNNING") | (Task.status == "CREATED") | (Task.status == "STOPING")) \
2024-01-31 19:37:01 +10:00
.all()
return len(tasks) > 0