You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
796 B
23 lines
796 B
"""Утилиты по цепочке теста (попытки/версии).""" |
|
from __future__ import annotations |
|
|
|
from sqlalchemy.orm import Session |
|
|
|
from ..models import TestAttempt, TestVersion |
|
|
|
|
|
def has_any_attempt_for_test(session: Session, test_id) -> bool: |
|
"""Возвращает True, если для теста есть хотя бы одна попытка.""" |
|
import uuid as _uuid |
|
if not isinstance(test_id, _uuid.UUID): |
|
try: |
|
test_id = _uuid.UUID(str(test_id)) |
|
except (ValueError, AttributeError): |
|
return False |
|
|
|
return session.query( |
|
session.query(TestAttempt) |
|
.join(TestVersion, TestAttempt.test_version_id == TestVersion.id) |
|
.filter(TestVersion.test_id == test_id) |
|
.exists() |
|
).scalar()
|
|
|