Enhance promo export functionality with English localization
- Added support for exporting promo activations and all promo codes with captions and CSV headers in English. - Updated the promo export handlers to ensure consistent English messaging for user notifications and CSV content. - Introduced new localization entries for English in the locales files to support the changes.
This commit is contained in:
@@ -248,6 +248,7 @@ async def promo_export_activations_handler(callback: types.CallbackQuery, i18n_d
|
|||||||
if not i18n or not callback.message or not current_lang:
|
if not i18n or not callback.message or not current_lang:
|
||||||
return await callback.answer("Error processing request.", show_alert=True)
|
return await callback.answer("Error processing request.", show_alert=True)
|
||||||
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs)
|
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs)
|
||||||
|
export_lang = "en"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
promo_id = int(callback.data.split(":")[1])
|
promo_id = int(callback.data.split(":")[1])
|
||||||
@@ -267,7 +268,11 @@ async def promo_export_activations_handler(callback: types.CallbackQuery, i18n_d
|
|||||||
|
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
file = types.BufferedInputFile(output.getvalue().encode('utf-8'), filename=f"promo_{promo.code}_activations.csv")
|
file = types.BufferedInputFile(output.getvalue().encode('utf-8'), filename=f"promo_{promo.code}_activations.csv")
|
||||||
await callback.message.answer_document(file, caption=_("admin_promo_export_caption", code=promo.code))
|
# Force English caption for exports
|
||||||
|
await callback.message.answer_document(
|
||||||
|
file,
|
||||||
|
caption=i18n.gettext(export_lang, "admin_promo_export_caption", code=promo.code)
|
||||||
|
)
|
||||||
|
|
||||||
except (ValueError, IndexError):
|
except (ValueError, IndexError):
|
||||||
await callback.answer(_("admin_promo_not_found"), show_alert=True)
|
await callback.answer(_("admin_promo_not_found"), show_alert=True)
|
||||||
@@ -281,9 +286,10 @@ async def promo_export_all_handler(callback: types.CallbackQuery, i18n_data: dic
|
|||||||
if not i18n or not callback.message or not current_lang:
|
if not i18n or not callback.message or not current_lang:
|
||||||
return await callback.answer("Error processing request.", show_alert=True)
|
return await callback.answer("Error processing request.", show_alert=True)
|
||||||
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs)
|
_ = lambda key, **kwargs: i18n.gettext(current_lang, key, **kwargs)
|
||||||
|
export_lang = "en"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await callback.answer("📄 Создаю CSV файл...", show_alert=True)
|
await callback.answer(i18n.gettext(export_lang, "admin_promo_export_all_generating"), show_alert=True)
|
||||||
|
|
||||||
# Получаем все промокоды
|
# Получаем все промокоды
|
||||||
all_promos = await promo_code_dal.get_all_promo_codes_with_details(session, limit=10000, offset=0)
|
all_promos = await promo_code_dal.get_all_promo_codes_with_details(session, limit=10000, offset=0)
|
||||||
@@ -291,15 +297,22 @@ async def promo_export_all_handler(callback: types.CallbackQuery, i18n_data: dic
|
|||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
writer = csv.writer(output)
|
writer = csv.writer(output)
|
||||||
|
|
||||||
# Заголовки CSV
|
# CSV headers (forced to English)
|
||||||
writer.writerow([
|
writer.writerow([
|
||||||
"Код", "Бонусные дни", "Максимальные активации", "Текущие активации",
|
i18n.gettext(export_lang, "admin_promo_csv_code"),
|
||||||
"Статус", "Активен", "Действителен до", "Создан", "Создал (Admin ID)"
|
i18n.gettext(export_lang, "admin_promo_csv_bonus_days"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_max_activations"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_current_activations"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_status"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_is_active"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_valid_until"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_created_at"),
|
||||||
|
i18n.gettext(export_lang, "admin_promo_csv_created_by_admin_id"),
|
||||||
])
|
])
|
||||||
|
|
||||||
for promo in all_promos:
|
for promo in all_promos:
|
||||||
# Определяем статус
|
# Определяем статус
|
||||||
status_emoji, status_text = get_promo_status_emoji_and_text(promo, i18n, current_lang)
|
status_emoji, status_text = get_promo_status_emoji_and_text(promo, i18n, export_lang)
|
||||||
|
|
||||||
# Формируем данные для CSV
|
# Формируем данные для CSV
|
||||||
row = [
|
row = [
|
||||||
@@ -308,8 +321,8 @@ async def promo_export_all_handler(callback: types.CallbackQuery, i18n_data: dic
|
|||||||
promo.max_activations,
|
promo.max_activations,
|
||||||
promo.current_activations,
|
promo.current_activations,
|
||||||
status_text,
|
status_text,
|
||||||
"Да" if promo.is_active else "Нет",
|
i18n.gettext(export_lang, "csv_yes") if promo.is_active else i18n.gettext(export_lang, "csv_no"),
|
||||||
promo.valid_until.strftime("%Y-%m-%d %H:%M:%S") if promo.valid_until else "Без ограничений",
|
promo.valid_until.strftime("%Y-%m-%d %H:%M:%S") if promo.valid_until else i18n.gettext(export_lang, "admin_promo_valid_indefinitely"),
|
||||||
promo.created_at.strftime("%Y-%m-%d %H:%M:%S") if promo.created_at else "N/A",
|
promo.created_at.strftime("%Y-%m-%d %H:%M:%S") if promo.created_at else "N/A",
|
||||||
promo.created_by_admin_id or "N/A"
|
promo.created_by_admin_id or "N/A"
|
||||||
]
|
]
|
||||||
@@ -324,11 +337,11 @@ async def promo_export_all_handler(callback: types.CallbackQuery, i18n_data: dic
|
|||||||
filename=filename
|
filename=filename
|
||||||
)
|
)
|
||||||
|
|
||||||
caption = f"📄 Экспорт всех промокодов\n📊 Всего: {len(all_promos)} промокодов"
|
caption = i18n.gettext(export_lang, "admin_promo_export_all_caption", count=len(all_promos))
|
||||||
await callback.message.answer_document(file, caption=caption)
|
await callback.message.answer_document(file, caption=caption)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await callback.answer(f"❌ Ошибка экспорта: {str(e)}", show_alert=True)
|
await callback.answer(f"❌ Export error: {str(e)}", show_alert=True)
|
||||||
|
|
||||||
|
|
||||||
@router.callback_query(F.data.startswith("promo_delete:"))
|
@router.callback_query(F.data.startswith("promo_delete:"))
|
||||||
|
|||||||
@@ -149,6 +149,19 @@
|
|||||||
"admin_promo_not_found": "Promo not found.",
|
"admin_promo_not_found": "Promo not found.",
|
||||||
"admin_promo_export_csv_button": "📄 Export to CSV",
|
"admin_promo_export_csv_button": "📄 Export to CSV",
|
||||||
"admin_promo_export_caption": "📄 Activations for promo code {code}",
|
"admin_promo_export_caption": "📄 Activations for promo code {code}",
|
||||||
|
"admin_promo_export_all_generating": "📄 Generating CSV...",
|
||||||
|
"admin_promo_export_all_caption": "📄 Export of all promo codes\n📊 Total: {count} promo codes",
|
||||||
|
"admin_promo_csv_code": "Code",
|
||||||
|
"admin_promo_csv_bonus_days": "Bonus Days",
|
||||||
|
"admin_promo_csv_max_activations": "Max Activations",
|
||||||
|
"admin_promo_csv_current_activations": "Current Activations",
|
||||||
|
"admin_promo_csv_status": "Status",
|
||||||
|
"admin_promo_csv_is_active": "Active",
|
||||||
|
"admin_promo_csv_valid_until": "Valid Until",
|
||||||
|
"admin_promo_csv_created_at": "Created",
|
||||||
|
"admin_promo_csv_created_by_admin_id": "Created By (Admin ID)",
|
||||||
|
"csv_yes": "Yes",
|
||||||
|
"csv_no": "No",
|
||||||
"admin_promo_edit_select_field": "Select a field to edit:",
|
"admin_promo_edit_select_field": "Select a field to edit:",
|
||||||
"admin_promo_prompt_bonus_days": "Enter the new number of bonus days:",
|
"admin_promo_prompt_bonus_days": "Enter the new number of bonus days:",
|
||||||
"admin_promo_prompt_max_activations": "Enter the new maximum number of activations:",
|
"admin_promo_prompt_max_activations": "Enter the new maximum number of activations:",
|
||||||
|
|||||||
@@ -155,6 +155,19 @@
|
|||||||
"admin_promo_not_found": "Промокод не найден.",
|
"admin_promo_not_found": "Промокод не найден.",
|
||||||
"admin_promo_export_csv_button": "📄 Экспорт в CSV",
|
"admin_promo_export_csv_button": "📄 Экспорт в CSV",
|
||||||
"admin_promo_export_caption": "📄 Активации промокода {code}",
|
"admin_promo_export_caption": "📄 Активации промокода {code}",
|
||||||
|
"admin_promo_export_all_generating": "📄 Создаю CSV файл...",
|
||||||
|
"admin_promo_export_all_caption": "📄 Экспорт всех промокодов\n📊 Всего: {count} промокодов",
|
||||||
|
"admin_promo_csv_code": "Код",
|
||||||
|
"admin_promo_csv_bonus_days": "Бонусные дни",
|
||||||
|
"admin_promo_csv_max_activations": "Максимальные активации",
|
||||||
|
"admin_promo_csv_current_activations": "Текущие активации",
|
||||||
|
"admin_promo_csv_status": "Статус",
|
||||||
|
"admin_promo_csv_is_active": "Активен",
|
||||||
|
"admin_promo_csv_valid_until": "Действителен до",
|
||||||
|
"admin_promo_csv_created_at": "Создан",
|
||||||
|
"admin_promo_csv_created_by_admin_id": "Создал (Admin ID)",
|
||||||
|
"csv_yes": "Да",
|
||||||
|
"csv_no": "Нет",
|
||||||
"admin_promo_edit_select_field": "Выберите поле для редактирования:",
|
"admin_promo_edit_select_field": "Выберите поле для редактирования:",
|
||||||
"admin_promo_prompt_bonus_days": "Введите новое количество бонусных дней:",
|
"admin_promo_prompt_bonus_days": "Введите новое количество бонусных дней:",
|
||||||
"admin_promo_prompt_max_activations": "Введите новое максимальное количество активаций:",
|
"admin_promo_prompt_max_activations": "Введите новое максимальное количество активаций:",
|
||||||
|
|||||||
Reference in New Issue
Block a user