mirror of
https://github.com/koloideal/DutyLog.git
synced 2026-06-10 10:25:29 +03:00
update
This commit is contained in:
@@ -6,10 +6,18 @@ from dishka import FromDishka
|
||||
from dishka.integrations.aiogram_dialog import inject
|
||||
|
||||
from dutylog.application.bot.user_dialogs.states import MainMenuSG
|
||||
from dutylog.infrastructure.database.repositories.users_repository import UsersRepository
|
||||
from dutylog.infrastructure.database.repositories.residents_repository import ResidentsRepository
|
||||
from dutylog.infrastructure.database.repositories.rooms_repository import RoomsRepository
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import HoursTransactionsRepository
|
||||
from dutylog.infrastructure.database.repositories.users_repository import (
|
||||
UsersRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.residents_repository import (
|
||||
ResidentsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.rooms_repository import (
|
||||
RoomsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.database.repositories.hours_transactions_repository import (
|
||||
HoursTransactionsRepository,
|
||||
)
|
||||
from dutylog.infrastructure.utils.config import Config
|
||||
|
||||
|
||||
@@ -28,27 +36,35 @@ async def get_main_menu_data(
|
||||
first_name=event_from_user.first_name,
|
||||
last_name=event_from_user.last_name,
|
||||
)
|
||||
|
||||
|
||||
is_creator = event_from_user.id == config.bot.creator_id
|
||||
is_admin = user.is_admin
|
||||
|
||||
|
||||
if is_creator:
|
||||
greeting = "👑 <b>Создатель</b>"
|
||||
elif is_admin:
|
||||
greeting = "👨💼 <b>Администратор</b>"
|
||||
else:
|
||||
resident = await residents_repository.get_resident_by_user_id(event_from_user.id)
|
||||
resident = await residents_repository.get_resident_by_user_id(
|
||||
event_from_user.id
|
||||
)
|
||||
if resident:
|
||||
room = await rooms_repository.get_room_by_id(resident.room)
|
||||
room_number = room.number if room else "???"
|
||||
real_name = resident.real_name if resident.real_name else event_from_user.first_name
|
||||
greeting = f"👋 <b>Привет, {real_name}!</b>\n🚪 Комната <code>{room_number}</code>"
|
||||
real_name = (
|
||||
resident.real_name if resident.real_name else event_from_user.first_name
|
||||
)
|
||||
greeting = (
|
||||
f"👋 <b>Привет, {real_name}!</b>\n🚪 Комната <code>{room_number}</code>"
|
||||
)
|
||||
else:
|
||||
greeting = f"👋 <b>Привет, {event_from_user.first_name}!</b>"
|
||||
|
||||
|
||||
if not is_admin and not is_creator:
|
||||
resident = await residents_repository.get_resident_by_user_id(event_from_user.id)
|
||||
|
||||
resident = await residents_repository.get_resident_by_user_id(
|
||||
event_from_user.id
|
||||
)
|
||||
|
||||
if not resident:
|
||||
content = f"""
|
||||
{greeting}
|
||||
@@ -79,7 +95,7 @@ async def get_main_menu_data(
|
||||
Добро пожаловать в систему учета дежурств!
|
||||
"""
|
||||
has_resident = False
|
||||
|
||||
|
||||
return {
|
||||
"content": content,
|
||||
"is_regular_user": not is_admin and not is_creator,
|
||||
@@ -95,7 +111,7 @@ async def get_history_data(
|
||||
**kwargs,
|
||||
):
|
||||
resident = await residents_repository.get_resident_by_user_id(event_from_user.id)
|
||||
|
||||
|
||||
if not resident:
|
||||
history_text = """
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
@@ -105,7 +121,7 @@ async def get_history_data(
|
||||
else:
|
||||
transactions = await transactions_repository.get_resident_history(resident.id)
|
||||
last_10 = transactions[:10]
|
||||
|
||||
|
||||
if not last_10:
|
||||
history_text = """
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
@@ -120,14 +136,14 @@ async def get_history_data(
|
||||
history_lines.append(
|
||||
f"{emoji} <code>{tx.amount}</code> ч • <i>{date_str}</i>"
|
||||
)
|
||||
|
||||
|
||||
history_text = f"""
|
||||
<blockquote>📜 <b>История операций</b></blockquote>
|
||||
|
||||
{"".join(f"{line}\n" for line in history_lines)}
|
||||
<i>Показаны последние 10 операций</i>
|
||||
"""
|
||||
|
||||
|
||||
return {"history_content": history_text}
|
||||
|
||||
|
||||
@@ -177,4 +193,3 @@ main_menu_dialog = Dialog(
|
||||
state=MainMenuSG.faq,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user