mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 18:35:28 +03:00
update
This commit is contained in:
@@ -12,7 +12,7 @@ from quizzi.infrastructure.database.models import QuestionType
|
|||||||
from quizzi.infrastructure.database.repo.test import TestRepository
|
from quizzi.infrastructure.database.repo.test import TestRepository
|
||||||
from quizzi.infrastructure.database.repo.test_attempt import TestAttemptRepository
|
from quizzi.infrastructure.database.repo.test_attempt import TestAttemptRepository
|
||||||
from quizzi.infrastructure.utils.rate_limiter import PasswordRateLimiter
|
from quizzi.infrastructure.utils.rate_limiter import PasswordRateLimiter
|
||||||
from quizzi.infrastructure.utils.timezone import now_msk_naive
|
from quizzi.infrastructure.utils.timezone import now_msk_naive, to_msk
|
||||||
|
|
||||||
|
|
||||||
@inject
|
@inject
|
||||||
@@ -20,12 +20,15 @@ async def get_deeplink_test_data(
|
|||||||
dialog_manager: DialogManager,
|
dialog_manager: DialogManager,
|
||||||
test_dao: FromDishka[TestDAO],
|
test_dao: FromDishka[TestDAO],
|
||||||
test_repo: FromDishka[TestRepository],
|
test_repo: FromDishka[TestRepository],
|
||||||
|
attempt_repo: FromDishka[TestAttemptRepository],
|
||||||
**_kwargs,
|
**_kwargs,
|
||||||
):
|
):
|
||||||
|
assert dialog_manager.event.from_user is not None
|
||||||
start_data = dialog_manager.start_data or {}
|
start_data = dialog_manager.start_data or {}
|
||||||
assert isinstance(start_data, dict)
|
assert isinstance(start_data, dict)
|
||||||
test_id = start_data.get("test_id")
|
test_id = start_data.get("test_id")
|
||||||
error = start_data.get("error")
|
error = start_data.get("error")
|
||||||
|
user_id = dialog_manager.event.from_user.id
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
return {"test_info": error, "can_start": False}
|
return {"test_info": error, "can_start": False}
|
||||||
@@ -40,17 +43,26 @@ async def get_deeplink_test_data(
|
|||||||
|
|
||||||
questions_count = await test_repo.count_questions_in_test(test_id)
|
questions_count = await test_repo.count_questions_in_test(test_id)
|
||||||
|
|
||||||
|
attempts = await attempt_repo.get_user_test_attempts(user_id, test_id)
|
||||||
|
finished_attempts = [a for a in attempts if a.finished_at]
|
||||||
|
|
||||||
password_str = "🔒 Требуется пароль" if test.password else "🔓 Без пароля"
|
password_str = "🔒 Требуется пароль" if test.password else "🔓 Без пароля"
|
||||||
attempts_str = f"🔄 Попыток: {test.attempts}" if test.attempts else "🔄 Попыток: ♾️"
|
attempts_str = f"🔄 Попыток: {len(finished_attempts)}/{test.attempts}" if test.attempts else f"🔄 Попыток: {len(finished_attempts)}/♾️"
|
||||||
time_limit_str = f"⏱️ Время: {test.time_limit // 60} мин" if test.time_limit else "⏱️ Без лимита"
|
time_limit_str = f"⏱️ Время: {test.time_limit // 60} мин" if test.time_limit else "⏱️ Без лимита"
|
||||||
|
|
||||||
|
expires_at_msk = to_msk(test.expires_at)
|
||||||
|
expires_str = f"📅 До {expires_at_msk.strftime('%d.%m.%Y %H:%M')}" if expires_at_msk else "📅 Без срока"
|
||||||
|
group_str = f"🎓 Для группы {test.for_group}" if test.for_group else "👥 Для всех"
|
||||||
|
|
||||||
test_info = (
|
test_info = (
|
||||||
f"<b>📝 {test.title}</b>\n\n"
|
f"<b>📝 {test.title}</b>\n\n"
|
||||||
f"<blockquote>{test.description or '—'}</blockquote>\n\n"
|
f"<blockquote>{test.description or '—'}</blockquote>\n\n"
|
||||||
f"<b>Вопросов:</b> {questions_count}\n"
|
f"<b>Вопросов:</b> {questions_count}\n"
|
||||||
f"{password_str}\n"
|
f"{password_str}\n"
|
||||||
f"{attempts_str}\n"
|
f"{attempts_str}\n"
|
||||||
f"{time_limit_str}"
|
f"{time_limit_str}\n"
|
||||||
|
f"{expires_str}\n"
|
||||||
|
f"{group_str}"
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"test_info": test_info, "can_start": True, "has_password": bool(test.password)}
|
return {"test_info": test_info, "can_start": True, "has_password": bool(test.password)}
|
||||||
|
|||||||
Reference in New Issue
Block a user