mirror of
https://github.com/koloideal/Quizzi.git
synced 2026-06-10 18:35:28 +03:00
update
This commit is contained in:
@@ -32,8 +32,9 @@ async def ensure_user_registered(
|
||||
|
||||
existing_user = await user_dao.get_by_id(message.from_user.id)
|
||||
groups = await group_dao.get_all()
|
||||
has_groups = len(groups) > 0
|
||||
|
||||
start_data = {"user_id": message.from_user.id}
|
||||
start_data = {"user_id": message.from_user.id, "has_groups": has_groups}
|
||||
if pending_test_id:
|
||||
start_data["pending_test_id"] = pending_test_id
|
||||
|
||||
@@ -44,23 +45,25 @@ async def ensure_user_registered(
|
||||
username=message.from_user.username,
|
||||
last_name=message.from_user.last_name,
|
||||
)
|
||||
if len(groups) > 0:
|
||||
await dialog_manager.start(
|
||||
UserRegistrationSG.input_name,
|
||||
mode=StartMode.RESET_STACK,
|
||||
data=start_data
|
||||
)
|
||||
return False
|
||||
return True
|
||||
|
||||
if len(groups) > 0 and (existing_user.name is None or existing_user.group is None):
|
||||
if existing_user.name is None:
|
||||
needs_name = existing_user.name is None
|
||||
needs_group = has_groups and existing_user.group is None
|
||||
|
||||
if needs_name:
|
||||
await dialog_manager.start(
|
||||
UserRegistrationSG.input_name,
|
||||
mode=StartMode.RESET_STACK,
|
||||
data=start_data
|
||||
)
|
||||
else:
|
||||
return False
|
||||
|
||||
if needs_group:
|
||||
await dialog_manager.start(
|
||||
UserRegistrationSG.select_group,
|
||||
mode=StartMode.RESET_STACK,
|
||||
|
||||
@@ -436,7 +436,7 @@ user_menu_dialog = Dialog(
|
||||
getter=get_test_detail,
|
||||
),
|
||||
Window(
|
||||
Const("<b>✏️ Изменение имени</b>\n\nВведите новое имя:"),
|
||||
Const("<b>✏️ Изменение имени</b>\n\nВведите имя и фамилию:"),
|
||||
MessageInput(on_name_input),
|
||||
Button(Const("◀️ Назад"), id="back", on_click=on_back_to_main),
|
||||
state=UserMenuSG.edit_name,
|
||||
|
||||
@@ -9,6 +9,7 @@ from dishka.integrations.aiogram_dialog import inject
|
||||
from quizzi.application.bot.user_dialogs.states import UserDeeplinkSG, UserMenuSG, UserRegistrationSG
|
||||
from quizzi.infrastructure.database.dao.group import GroupDAO
|
||||
from quizzi.infrastructure.database.dao.user import UserDAO
|
||||
from quizzi.infrastructure.utils.timezone import now_msk_naive
|
||||
|
||||
|
||||
@inject
|
||||
@@ -35,11 +36,24 @@ async def on_name_input(
|
||||
start_data = manager.start_data or {}
|
||||
assert isinstance(start_data, dict)
|
||||
user_id = start_data.get("user_id")
|
||||
has_groups = start_data.get("has_groups", True)
|
||||
pending_test_id = start_data.get("pending_test_id")
|
||||
|
||||
if user_id:
|
||||
await user_dao.update(user_id=user_id, name=name)
|
||||
await user_dao.update(user_id=user_id, name=name, name_updated_at=now_msk_naive())
|
||||
|
||||
manager.dialog_data["name"] = name
|
||||
|
||||
if has_groups:
|
||||
await manager.switch_to(UserRegistrationSG.select_group)
|
||||
elif pending_test_id:
|
||||
await manager.start(
|
||||
UserDeeplinkSG.test_preview,
|
||||
mode=StartMode.RESET_STACK,
|
||||
data={"test_id": pending_test_id}
|
||||
)
|
||||
else:
|
||||
await manager.start(UserMenuSG.main, mode=StartMode.RESET_STACK)
|
||||
|
||||
|
||||
@inject
|
||||
@@ -66,7 +80,7 @@ async def on_group_selected(
|
||||
pending_test_id = start_data.get("pending_test_id")
|
||||
|
||||
if user_id:
|
||||
await user_dao.update(user_id=user_id, group=int(item_id))
|
||||
await user_dao.update(user_id=user_id, group=int(item_id), group_updated_at=now_msk_naive())
|
||||
|
||||
if pending_test_id:
|
||||
await manager.start(
|
||||
|
||||
Reference in New Issue
Block a user