diff --git a/src/trudex/application/bot/admin_dialogs/tests.py b/src/trudex/application/bot/admin_dialogs/tests.py index f490495..fb2faf3 100644 --- a/src/trudex/application/bot/admin_dialogs/tests.py +++ b/src/trudex/application/bot/admin_dialogs/tests.py @@ -22,7 +22,7 @@ from trudex.infrastructure.database.repo.test_attempt import TestAttemptReposito from trudex.infrastructure.utils.config import Config from trudex.infrastructure.utils.qr_generator import generate_qr_bytes from trudex.infrastructure.utils.test_id_to_hash import encode_id -from trudex.infrastructure.utils.timezone import MSK_TZ, to_msk +from trudex.infrastructure.utils.timezone import to_msk @inject @@ -379,7 +379,7 @@ async def on_date_selected_for_test(_callback, _widget, manager: DialogManager, await _callback.answer("❌ Тест не найден") return - expires_at = datetime.combine(selected_date, time.min, tzinfo=MSK_TZ) + expires_at = datetime.combine(selected_date, time.min) await test_dao.update(test_id, expires_at=expires_at) await _callback.answer("✅ Срок действия обновлен") await manager.switch_to(AdminTestsSG.test_detail) diff --git a/src/trudex/application/bot/creator_dialogs/create_test.py b/src/trudex/application/bot/creator_dialogs/create_test.py index 5c89ef8..513a21c 100644 --- a/src/trudex/application/bot/creator_dialogs/create_test.py +++ b/src/trudex/application/bot/creator_dialogs/create_test.py @@ -16,7 +16,7 @@ from trudex.infrastructure.database.dao.option import OptionDAO from trudex.infrastructure.database.dao.question import QuestionDAO from trudex.infrastructure.database.dao.test import TestDAO from trudex.infrastructure.database.repo.test import TestRepository -from trudex.infrastructure.utils.timezone import MSK_TZ, to_msk +from trudex.infrastructure.utils.timezone import to_msk async def on_title_input(message: Message, _widget: MessageInput, manager: DialogManager): @@ -111,7 +111,7 @@ async def on_skip_attempts(_callback: CallbackQuery, _button: Button, manager: D async def on_date_selected(_callback, _widget, manager: DialogManager, selected_date: date): - manager.dialog_data["expires_at"] = datetime.combine(selected_date, time.min, tzinfo=MSK_TZ) + manager.dialog_data["expires_at"] = datetime.combine(selected_date, time.min) await manager.switch_to(CreateTestSG.input_for_group) @@ -537,7 +537,7 @@ create_test_dialog = Dialog( getter=get_question_type_data, ), Window( - Const("✏️ Правильный ответ\n\n💬 Введите правильный ответ (для проверки будет использоваться точное совпадение):\n(максимум 255 символов)"), + Const("✏️ Правильный ответ\n\n💬 Введите правильный ответ (регистр и пробелы игнорируются):\n(максимум 255 символов)"), MessageInput(on_correct_answer_input), Button(Const("◀️ Назад"), id="back", on_click=on_cancel_question), state=CreateTestSG.input_correct_answer, diff --git a/src/trudex/application/bot/creator_dialogs/tests.py b/src/trudex/application/bot/creator_dialogs/tests.py index 71465d1..524a95a 100644 --- a/src/trudex/application/bot/creator_dialogs/tests.py +++ b/src/trudex/application/bot/creator_dialogs/tests.py @@ -25,7 +25,7 @@ from trudex.infrastructure.database.repo.test_attempt import TestAttemptReposito from trudex.infrastructure.utils.config import Config from trudex.infrastructure.utils.qr_generator import generate_qr_bytes from trudex.infrastructure.utils.test_id_to_hash import encode_id -from trudex.infrastructure.utils.timezone import MSK_TZ, to_msk +from trudex.infrastructure.utils.timezone import to_msk @inject @@ -383,7 +383,7 @@ async def on_date_selected_for_test(_callback, _widget, manager: DialogManager, await _callback.answer("❌ Тест не найден") return - expires_at = datetime.combine(selected_date, time.min, tzinfo=MSK_TZ) + expires_at = datetime.combine(selected_date, time.min) await test_dao.update(test_id, expires_at=expires_at) await _callback.answer("✅ Срок действия обновлен") await manager.switch_to(CreatorTestsSG.test_detail) diff --git a/src/trudex/application/bot/handlers.py b/src/trudex/application/bot/handlers.py index 57fad4d..75b0570 100644 --- a/src/trudex/application/bot/handlers.py +++ b/src/trudex/application/bot/handlers.py @@ -17,7 +17,7 @@ from trudex.infrastructure.database.dao.test import TestDAO from trudex.infrastructure.database.dao.user import UserDAO from trudex.infrastructure.utils.config import Config from trudex.infrastructure.utils.test_id_to_hash import decode_id -from trudex.infrastructure.utils.timezone import now_msk +from trudex.infrastructure.utils.timezone import now_msk_naive router = Router() @@ -92,7 +92,7 @@ async def validate_deeplink_test( if not test.is_active: return False, "❌ Тест деактивирован" - if test.expires_at and test.expires_at < now_msk(): + if test.expires_at and test.expires_at < now_msk_naive(): return False, "❌ Срок действия теста истек" user = await user_dao.get_by_id(user_id) diff --git a/src/trudex/application/bot/user_dialogs/main_menu.py b/src/trudex/application/bot/user_dialogs/main_menu.py index b695639..122e8de 100644 --- a/src/trudex/application/bot/user_dialogs/main_menu.py +++ b/src/trudex/application/bot/user_dialogs/main_menu.py @@ -20,7 +20,7 @@ from trudex.infrastructure.database.repo.test_attempt import TestAttemptReposito from trudex.infrastructure.utils.config import Config from trudex.infrastructure.utils.qr_generator import generate_qr_bytes from trudex.infrastructure.utils.test_id_to_hash import encode_id -from trudex.infrastructure.utils.timezone import now_msk, to_msk +from trudex.infrastructure.utils.timezone import now_msk, now_msk_naive, to_msk from datetime import datetime @@ -150,7 +150,7 @@ async def on_name_input( result = await user_dao.update( user_id=message.from_user.id, name=name, - name_updated_at=now_msk(), + name_updated_at=now_msk_naive(), ) if result: await message.answer("✅ Имя обновлено") @@ -177,7 +177,7 @@ async def on_group_selected( result = await user_dao.update( user_id=_callback.from_user.id, group=int(item_id), - group_updated_at=now_msk(), + group_updated_at=now_msk_naive(), ) if result: await _callback.answer("✅ Группа обновлена") diff --git a/src/trudex/application/bot/user_dialogs/take_test.py b/src/trudex/application/bot/user_dialogs/take_test.py index 6c40969..8a8a16d 100644 --- a/src/trudex/application/bot/user_dialogs/take_test.py +++ b/src/trudex/application/bot/user_dialogs/take_test.py @@ -12,7 +12,7 @@ from trudex.infrastructure.database.dao.user_answer import UserAnswerDAO from trudex.infrastructure.database.models import QuestionType from trudex.infrastructure.database.repo.test import TestRepository from trudex.infrastructure.database.repo.test_attempt import TestAttemptRepository -from trudex.infrastructure.utils.timezone import now_msk +from trudex.infrastructure.utils.timezone import now_msk_naive async def get_state_for_question_type(question_type: str): @@ -50,7 +50,7 @@ async def on_start_test( await _callback.answer("❌ Тест деактивирован") return - if test.expires_at and test.expires_at < now_msk(): + if test.expires_at and test.expires_at < now_msk_naive(): await _callback.answer("❌ Срок действия теста истек") return diff --git a/src/trudex/infrastructure/api/__init__.py b/src/trudex/infrastructure/api/__init__.py deleted file mode 100644 index 8b13789..0000000 --- a/src/trudex/infrastructure/api/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/trudex/infrastructure/database/repo/test_attempt.py b/src/trudex/infrastructure/database/repo/test_attempt.py index b4fcbd4..1ec61fa 100644 --- a/src/trudex/infrastructure/database/repo/test_attempt.py +++ b/src/trudex/infrastructure/database/repo/test_attempt.py @@ -12,7 +12,7 @@ from trudex.infrastructure.database.dto.user_answer import UserAnswerDTO from trudex.infrastructure.database.models import \ TestAttempt as TestAttemptModel from trudex.infrastructure.database.models import UserAnswer as UserAnswerModel -from trudex.infrastructure.utils.timezone import now_msk +from trudex.infrastructure.utils.timezone import now_msk_naive @final @@ -132,7 +132,7 @@ class TestAttemptRepository: async def finish_attempt(self, attempt_id: int, score: int, is_passed: bool) -> TestAttempt | None: return await self.attempt_dao.update( attempt_id=attempt_id, - finished_at=now_msk(), + finished_at=now_msk_naive(), score=score, is_passed=is_passed ) diff --git a/src/trudex/infrastructure/scheduling/tasks.py b/src/trudex/infrastructure/scheduling/tasks.py index 0a99ccf..5667ccb 100644 --- a/src/trudex/infrastructure/scheduling/tasks.py +++ b/src/trudex/infrastructure/scheduling/tasks.py @@ -1,7 +1,7 @@ from dishka import AsyncContainer from trudex.infrastructure.database.dao.test import TestDAO -from trudex.infrastructure.utils.timezone import now_msk +from trudex.infrastructure.utils.timezone import now_msk_naive async def deactivate_expired_tests(container: AsyncContainer): @@ -11,5 +11,5 @@ async def deactivate_expired_tests(container: AsyncContainer): tests = await test_dao.get_all() for test in tests: - if test.expires_at and test.expires_at < now_msk() and test.is_active: + if test.expires_at and test.expires_at < now_msk_naive() and test.is_active: await test_dao.update(test.id, is_active=False) diff --git a/src/trudex/infrastructure/utils/timezone.py b/src/trudex/infrastructure/utils/timezone.py index dea7c88..6236e2b 100644 --- a/src/trudex/infrastructure/utils/timezone.py +++ b/src/trudex/infrastructure/utils/timezone.py @@ -8,6 +8,11 @@ def now_msk() -> datetime: return datetime.now(MSK_TZ) +def now_msk_naive() -> datetime: + """Возвращает текущее время в МСК без timezone info (для сохранения в БД).""" + return datetime.now(MSK_TZ).replace(tzinfo=None) + + def to_msk(dt: datetime | None) -> datetime | None: if dt is None: return None