This commit is contained in:
2026-03-04 01:21:06 +03:00
parent c7ad35d343
commit 9b004c3a86
7 changed files with 598 additions and 49 deletions
@@ -27,6 +27,7 @@ async def get_residents_list_data(
residents_repository: FromDishka[ResidentsRepository],
rooms_repository: FromDishka[RoomsRepository],
floors_repository: FromDishka[FloorsRepository],
users_repository: FromDishka[UsersRepository],
**kwargs,
):
all_residents = await residents_repository.get_all_residents()
@@ -41,17 +42,25 @@ async def get_residents_list_data(
else:
floor_number = 999999
room_number = 999999
residents_with_rooms.append((resident, floor_number, room_number))
is_admin = False
if resident.user_entity:
user = await users_repository.get_user_by_id(resident.user_entity)
if user and user.is_admin:
is_admin = True
residents_with_rooms.append((resident, floor_number, room_number, is_admin))
residents_with_rooms.sort(key=lambda x: (x[1], x[2]))
residents_data = []
for resident, floor_number, room_number in residents_with_rooms:
for resident, floor_number, room_number, is_admin in residents_with_rooms:
status = "🟢" if resident.is_busy else "⚪️"
name = resident.real_name if resident.real_name else "Без имени"
admin_badge = " 👑" if is_admin else ""
residents_data.append(
(f"{name} | Комната {room_number} | {status}", resident.id)
(f"{name} | Комната {room_number} | {status}{admin_badge}", resident.id)
)
content = f"""
@@ -79,12 +88,12 @@ async def get_resident_info_data(
resident_id = dialog_manager.dialog_data.get("selected_resident_id")
if not resident_id:
return {"info_content": "Ошибка: резидент не выбран", "is_busy": False, "from_search": False, "from_filter": False}
return {"info_content": "Ошибка: резидент не выбран", "is_busy": False, "is_admin": False, "from_search": False, "from_filter": False}
resident = await residents_repository.get_resident_by_id(resident_id)
if not resident:
return {"info_content": "Ошибка: резидент не найден", "is_busy": False, "from_search": False, "from_filter": False}
return {"info_content": "Ошибка: резидент не найден", "is_busy": False, "is_admin": False, "from_search": False, "from_filter": False}
room = await rooms_repository.get_room_by_id(resident.room)
room_number = room.number if room else "???"
@@ -92,6 +101,7 @@ async def get_resident_info_data(
name = resident.real_name if resident.real_name else "Без имени"
status = "🟢 Занят" if resident.is_busy else "⚪️ Свободен"
is_admin = False
user_info = "Не привязан"
if resident.user_entity:
user = await users_repository.get_user_by_id(resident.user_entity)
@@ -101,19 +111,28 @@ async def get_resident_info_data(
else:
username = f"ID: {user.id}"
user_info = f"{user.first_name} ({username})"
is_admin = user.is_admin
admin_badge = " 👑" if is_admin else ""
hours_info = ""
if not is_admin:
hours_info = f"""
🟢 <b>Отработанные часы:</b> <code>{resident.inactive_hours}</code> ч
🔴 <b>Неотработанные часы:</b> <code>{resident.active_hours}</code> ч
"""
else:
hours_info = "\n<blockquote>👑 <b>Это администратор</b></blockquote>"
info_content = f"""
<blockquote>👤 <b>Информация о резиденте</b></blockquote>
<blockquote>👤 <b>Информация о резиденте{admin_badge}</b></blockquote>
<b>ID:</b> <code>{resident.id}</code>
<b>Имя:</b> {name}
<b>Комната:</b> <code>{room_number}</code>
<b>Статус:</b> {status}
<b>Пользователь:</b> {user_info}
🟢 <b>Отработанные часы:</b> <code>{resident.inactive_hours}</code> ч
🔴 <b>Неотработанные часы:</b> <code>{resident.active_hours}</code> ч
"""
{hours_info}"""
from_search = dialog_manager.dialog_data.get("from_search", False)
from_filter = dialog_manager.dialog_data.get("from_filter", False)
@@ -121,6 +140,7 @@ async def get_resident_info_data(
return {
"info_content": info_content,
"is_busy": resident.is_busy,
"is_admin": is_admin,
"from_search": from_search,
"from_filter": from_filter,
}
@@ -478,17 +498,25 @@ async def get_search_results_data(
else:
floor_number = 999999
room_number = 999999
residents_with_rooms.append((resident, floor_number, room_number))
is_admin = False
if resident.user_entity:
user = await users_repository.get_user_by_id(resident.user_entity)
if user and user.is_admin:
is_admin = True
residents_with_rooms.append((resident, floor_number, room_number, is_admin))
residents_with_rooms.sort(key=lambda x: (x[1], x[2]))
residents_data = []
for resident, floor_number, room_number in residents_with_rooms:
for resident, floor_number, room_number, is_admin in residents_with_rooms:
status = "🟢" if resident.is_busy else "⚪️"
name = resident.real_name if resident.real_name else "Без имени"
admin_badge = " 👑" if is_admin else ""
residents_data.append(
(f"{name} | Комната {room_number} | {status}", resident.id)
(f"{name} | Комната {room_number} | {status}{admin_badge}", resident.id)
)
content = f"""
@@ -565,28 +593,32 @@ resident_info_window = Window(
Const("Добавить часы"),
id="add_hours_btn",
on_click=lambda c, b, m: m.switch_to(AdminMenuSG.add_hours_select),
when=~F["is_admin"],
),
Button(
Const("Отнять часы"),
id="remove_hours_btn",
on_click=lambda c, b, m: m.switch_to(AdminMenuSG.remove_hours_select),
when=~F["is_admin"],
),
),
Button(
Const("🔄 Перепривязать к комнате"),
id="rebind_resident_btn",
on_click=on_rebind_resident,
when=~F["is_admin"],
),
Button(
Const("🚪 Разлогинить"),
id="logout_resident_btn",
on_click=lambda c, b, m: m.switch_to(AdminMenuSG.resident_logout_confirm),
when="is_busy",
when=F["is_busy"] & ~F["is_admin"],
),
Button(
Const("🗑 Удалить резидента"),
id="delete_resident_btn",
on_click=lambda c, b, m: m.switch_to(AdminMenuSG.resident_delete_confirm),
when=~F["is_admin"],
),
SwitchTo(
Const("◀️ Назад к результатам поиска"),