From 33d4fd2e2eed11f4b05533984c67370e4297f645 Mon Sep 17 00:00:00 2001 From: hteppl Date: Thu, 26 Dec 2024 03:36:28 +0300 Subject: [PATCH 1/3] Monthly payments in admin stats --- handlers/admin/admin_panel.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handlers/admin/admin_panel.py b/handlers/admin/admin_panel.py index 47865ad8..91ae12e1 100644 --- a/handlers/admin/admin_panel.py +++ b/handlers/admin/admin_panel.py @@ -81,6 +81,9 @@ async def user_stats_menu(callback_query: CallbackQuery, session: Any): total_payments_week = await session.fetchval( "SELECT COALESCE(SUM(amount), 0) FROM payments WHERE created_at >= date_trunc('week', CURRENT_DATE)" ) + total_payments_month = await session.fetchval( + "SELECT COALESCE(SUM(amount), 0) FROM payments WHERE created_at >= date_trunc('month', CURRENT_DATE)" + ) total_payments_all_time = await session.fetchval( "SELECT COALESCE(SUM(amount), 0) FROM payments" ) @@ -103,6 +106,7 @@ async def user_stats_menu(callback_query: CallbackQuery, session: Any): f"💰 Финансовая статистика:\n" f" 📅 За день: {total_payments_today} ₽\n" f" 📆 За неделю: {total_payments_week} ₽\n" + f" 📆 За месяц: {total_payments_month} ₽\n" f" 🏦 За все время: {total_payments_all_time} ₽\n" ) From 0ca647fd64dc354af8ed910de960c2b28caff71b Mon Sep 17 00:00:00 2001 From: hteppl Date: Thu, 26 Dec 2024 03:36:54 +0300 Subject: [PATCH 2/3] Remove Telegram URL prefix when finding a user by username --- handlers/admin/admin_user_editor.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/handlers/admin/admin_user_editor.py b/handlers/admin/admin_user_editor.py index fd57f4c8..e2576bfe 100644 --- a/handlers/admin/admin_user_editor.py +++ b/handlers/admin/admin_user_editor.py @@ -55,7 +55,8 @@ async def prompt_username(callback_query: CallbackQuery, state: FSMContext): async def handle_username_input( message: types.Message, state: FSMContext, session: Any ): - username = message.text.strip().lstrip("@") + # Extract the username from a message text by removing leading '@' and the Telegram URL prefix + username = message.text.strip().lstrip('@').replace('https://t.me/', '') user_record = await session.fetchrow( "SELECT tg_id FROM users WHERE username = $1", username ) From 10ce155b8ca457f3e1a1c17569282f0e98be75fb Mon Sep 17 00:00:00 2001 From: hteppl Date: Thu, 26 Dec 2024 03:40:26 +0300 Subject: [PATCH 3/3] Fix key back button --- handlers/admin/admin_user_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/admin/admin_user_editor.py b/handlers/admin/admin_user_editor.py index e2576bfe..e2fc5e3e 100644 --- a/handlers/admin/admin_user_editor.py +++ b/handlers/admin/admin_user_editor.py @@ -339,7 +339,7 @@ async def process_key_edit(callback_query: CallbackQuery, session: Any): callback_data=f"delete_key_admin|{email}", ) ) - builder.row(InlineKeyboardButton(text="🔙 Назад", callback_data="admin")) + builder.row(InlineKeyboardButton(text="🔙 Назад", callback_data="user_editor")) await callback_query.message.answer( response_message, reply_markup=builder.as_markup()