diff --git a/src/trudex/application/bot/admin_dialogs/states.py b/src/trudex/application/bot/admin_dialogs/states.py index 9ce9066..b55d1ae 100644 --- a/src/trudex/application/bot/admin_dialogs/states.py +++ b/src/trudex/application/bot/admin_dialogs/states.py @@ -15,6 +15,7 @@ class AdminTestsSG(StatesGroup): tests_list = State() test_detail = State() share_test = State() + edit_menu = State() edit_password = State() edit_attempts = State() edit_group = State() diff --git a/src/trudex/application/bot/admin_dialogs/tests.py b/src/trudex/application/bot/admin_dialogs/tests.py index e136982..6771860 100644 --- a/src/trudex/application/bot/admin_dialogs/tests.py +++ b/src/trudex/application/bot/admin_dialogs/tests.py @@ -66,19 +66,19 @@ async def get_test_detail(test_dao: FromDishka[TestDAO], test_repo: FromDishka[T status = "🟢 Активен" if test.is_active else "🔴 Деактивирован" password_str = f"🔒 {test.password}" if test.password else "🔓 Без пароля" attempts_str = f"🔄 {test.attempts}" if test.attempts else "♾️ Без ограничений" - expires_str = test.expires_at.strftime("%d.%m.%Y %H:%M") if test.expires_at else "♾️ Без срока" + expires_str = f"📅 {test.expires_at.strftime('%d.%m.%Y %H:%M')}" if test.expires_at else "📅 Без срока" group_str = f"🎓 Группа {test.for_group}" if test.for_group else "👥 Для всех" test_info = ( f"📝 Информация о тесте\n\n" - f"Название: {test.title}\n" - f"Описание: {test.description or '—'}\n\n" + f"Название:\n
{test.title}\n" + f"Описание:\n
{test.description or '—'}\n\n" f"Статус: {status}\n" f"Вопросов: {questions_count}\n" - f"{password_str}\n" - f"Попыток: {attempts_str}\n" - f"{expires_str}\n" - f"{group_str}\n\n" + f"Пароль: {password_str}\n" + f"Попытки: {attempts_str}\n" + f"Срок: {expires_str}\n" + f"Группа: {group_str}\n\n" f"Создан: {test.created_at.strftime('%d.%m.%Y %H:%M') if test.created_at else '—'}" ) @@ -161,6 +161,18 @@ async def qr_media_selector(data: dict, widget, manager: DialogManager): } +async def on_edit_menu(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(AdminTestsSG.edit_menu) + + +async def on_back_to_detail(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(AdminTestsSG.test_detail) + + +async def on_back_to_edit_menu(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(AdminTestsSG.edit_menu) + + async def on_edit_password(_callback: CallbackQuery, _button: Button, manager: DialogManager): await manager.switch_to(AdminTestsSG.edit_password) @@ -351,21 +363,29 @@ tests_dialog = Dialog( on_click=on_toggle_active ), Button(Const("🔗 Поделиться"), id="share", on_click=on_share_test), - Button(Const("🔑 Изменить пароль"), id="edit_password", on_click=on_edit_password), - Button(Const("🔄 Изменить попытки"), id="edit_attempts", on_click=on_edit_attempts), - Button(Const("👥 Изменить группу"), id="edit_group", on_click=on_edit_group), - Button(Const("📅 Изменить срок"), id="edit_expires", on_click=on_edit_expires), + Button(Const("✏️ Изменить"), id="edit_menu", on_click=on_edit_menu), Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), ), state=AdminTestsSG.test_detail, getter=get_test_detail, ), + Window( + Const("✏️ Изменить тест\n\nВыберите, что хотите изменить:"), + Column( + Button(Const("🔑 Пароль"), id="edit_password", on_click=on_edit_password), + Button(Const("🔄 Попытки"), id="edit_attempts", on_click=on_edit_attempts), + Button(Const("👥 Группа"), id="edit_group", on_click=on_edit_group), + Button(Const("📅 Срок действия"), id="edit_expires", on_click=on_edit_expires), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_detail), + ), + state=AdminTestsSG.edit_menu, + ), Window( Const("🔑 Изменение пароля\n\n💬 Введите новый пароль или удалите текущий:\n(максимум 255 символов)"), MessageInput(on_password_input), Column( Button(Const("🗑 Удалить пароль"), id="remove_password", on_click=on_remove_password), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=AdminTestsSG.edit_password, ), @@ -374,7 +394,7 @@ tests_dialog = Dialog( MessageInput(on_attempts_input_edit), Column( Button(Const("🗑 Без ограничений"), id="remove_attempts", on_click=on_remove_attempts), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=AdminTestsSG.edit_attempts, ), @@ -394,7 +414,7 @@ tests_dialog = Dialog( ), Column( Button(Const("🗑 Для всех групп"), id="remove_group", on_click=on_remove_group), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=AdminTestsSG.edit_group, getter=get_groups_for_edit, @@ -404,7 +424,7 @@ tests_dialog = Dialog( Calendar(id="calendar", on_click=on_date_selected_for_test), Column( Button(Const("🗑 Удалить срок"), id="remove_expires", on_click=on_remove_expires), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=AdminTestsSG.edit_expires, ), diff --git a/src/trudex/application/bot/creator_dialogs/states.py b/src/trudex/application/bot/creator_dialogs/states.py index 071c43d..2d5fbe0 100644 --- a/src/trudex/application/bot/creator_dialogs/states.py +++ b/src/trudex/application/bot/creator_dialogs/states.py @@ -16,6 +16,7 @@ class CreatorTestsSG(StatesGroup): tests_list = State() test_detail = State() share_test = State() + edit_menu = State() edit_password = State() edit_attempts = State() edit_group = State() diff --git a/src/trudex/application/bot/creator_dialogs/tests.py b/src/trudex/application/bot/creator_dialogs/tests.py index 4e37bc3..e8c9f9b 100644 --- a/src/trudex/application/bot/creator_dialogs/tests.py +++ b/src/trudex/application/bot/creator_dialogs/tests.py @@ -69,19 +69,19 @@ async def get_test_detail(test_dao: FromDishka[TestDAO], test_repo: FromDishka[T status = "🟢 Активен" if test.is_active else "🔴 Деактивирован" password_str = f"🔒 {test.password}" if test.password else "🔓 Без пароля" attempts_str = f"🔄 {test.attempts}" if test.attempts else "♾️ Без ограничений" - expires_str = test.expires_at.strftime("%d.%m.%Y %H:%M") if test.expires_at else "♾️ Без срока" + expires_str = f"📅 {test.expires_at.strftime('%d.%m.%Y %H:%M')}" if test.expires_at else "📅 Без срока" group_str = f"🎓 Группа {test.for_group}" if test.for_group else "👥 Для всех" test_info = ( f"📝 Информация о тесте\n\n" - f"Название: {test.title}\n" - f"Описание: {test.description or '—'}\n\n" + f"Название:\n
{test.title}\n" + f"Описание:\n
{test.description or '—'}\n\n" f"Статус: {status}\n" f"Вопросов: {questions_count}\n" - f"{password_str}\n" - f"Попыток: {attempts_str}\n" - f"{expires_str}\n" - f"{group_str}\n\n" + f"Пароль: {password_str}\n" + f"Попытки: {attempts_str}\n" + f"Срок: {expires_str}\n" + f"Группа: {group_str}\n\n" f"Создан: {test.created_at.strftime('%d.%m.%Y %H:%M') if test.created_at else '—'}" ) @@ -147,6 +147,18 @@ async def on_share_test(_callback: CallbackQuery, _button: Button, manager: Dial ) +async def on_edit_menu(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(CreatorTestsSG.edit_menu) + + +async def on_back_to_detail(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(CreatorTestsSG.test_detail) + + +async def on_back_to_edit_menu(_callback: CallbackQuery, _button: Button, manager: DialogManager): + await manager.switch_to(CreatorTestsSG.edit_menu) + + async def on_edit_password(_callback: CallbackQuery, _button: Button, manager: DialogManager): await manager.switch_to(CreatorTestsSG.edit_password) @@ -337,21 +349,29 @@ tests_dialog = Dialog( on_click=on_toggle_active ), Button(Const("🔗 Поделиться"), id="share", on_click=on_share_test), - Button(Const("🔑 Изменить пароль"), id="edit_password", on_click=on_edit_password), - Button(Const("🔄 Изменить попытки"), id="edit_attempts", on_click=on_edit_attempts), - Button(Const("👥 Изменить группу"), id="edit_group", on_click=on_edit_group), - Button(Const("📅 Изменить срок"), id="edit_expires", on_click=on_edit_expires), + Button(Const("✏️ Изменить"), id="edit_menu", on_click=on_edit_menu), Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), ), state=CreatorTestsSG.test_detail, getter=get_test_detail, ), Window( - Const("� Измеенение пароля\n\n� СВведите новый пароль или удалите текущий:\n(максимум 255 символов)"), + Const("✏️ Изменить тест\n\nВыберите, что хотите изменить:"), + Column( + Button(Const("🔑 Пароль"), id="edit_password", on_click=on_edit_password), + Button(Const("🔄 Попытки"), id="edit_attempts", on_click=on_edit_attempts), + Button(Const("👥 Группа"), id="edit_group", on_click=on_edit_group), + Button(Const("📅 Срок действия"), id="edit_expires", on_click=on_edit_expires), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_detail), + ), + state=CreatorTestsSG.edit_menu, + ), + Window( + Const("🔑 Изменение пароля\n\n💬 Введите новый пароль или удалите текущий:\n(максимум 255 символов)"), MessageInput(on_password_input), Column( Button(Const("🗑 Удалить пароль"), id="remove_password", on_click=on_remove_password), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=CreatorTestsSG.edit_password, ), @@ -360,7 +380,7 @@ tests_dialog = Dialog( MessageInput(on_attempts_input_edit), Column( Button(Const("🗑 Без ограничений"), id="remove_attempts", on_click=on_remove_attempts), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=CreatorTestsSG.edit_attempts, ), @@ -380,7 +400,7 @@ tests_dialog = Dialog( ), Column( Button(Const("🗑 Для всех групп"), id="remove_group", on_click=on_remove_group), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=CreatorTestsSG.edit_group, getter=get_groups_for_edit, @@ -390,7 +410,7 @@ tests_dialog = Dialog( Calendar(id="calendar", on_click=on_date_selected_for_test), Column( Button(Const("🗑 Удалить срок"), id="remove_expires", on_click=on_remove_expires), - Button(Const("◀️ Назад"), id="back", on_click=on_back_to_list), + Button(Const("◀️ Назад"), id="back", on_click=on_back_to_edit_menu), ), state=CreatorTestsSG.edit_expires, )