chore: clean up texts

This commit is contained in:
2026-08-13 11:30:04 +07:00
parent 104cf71969
commit 1b78f2ba36
7 changed files with 111 additions and 5 deletions

View File

@@ -13,6 +13,7 @@ from misc.kb.admins import back_to_product_kb
from misc.kb.client import get_back_to_catalogue
from misc.mapper import parse_cat_id
from misc.states import AdminControlStorage
from misc.texts import get_product_description
from misc.texts import product_editing_mapping
from repositories.categories import CategoriesRepository
from repositories.products import ProductRepository
@@ -120,6 +121,95 @@ async def toggle_product_visibility(
await cb.message.edit_reply_markup(reply_markup=admins.edit_product(product))
@router.callback_query(IsVerified(), F.data.startswith("edit_product:"), F.data.endswith(":photo"))
async def request_product_photo(cb: CallbackQuery, state: FSMContext):
await state.clear()
product_id = int(cb.data.split(":")[1])
if cb.message.photo:
await cb.message.delete()
msg = await cb.message.answer(
"<b>📷 Отправьте фотографию товара.</b>",
reply_markup=back_to_product_kb(product_id, cb_factory=lambda p: f"product:{p}"),
)
else:
msg = cb.message
await cb.message.edit_text(
"<b>📷 Отправьте фотографию товара.</b>",
reply_markup=back_to_product_kb(product_id, cb_factory=lambda p: f"product:{p}"),
)
await state.set_state(AdminControlStorage.edit_product_photo)
await state.set_data({"ctx": EditProductContext(product_id, "photo", msg)})
@router.message(AdminControlStorage.edit_product_photo)
async def upload_product_photo(
msg: Message,
state: FSMContext,
session: AsyncSession,
products_repo: ProductRepository,
):
data = await state.get_data()
ctx: EditProductContext = data.get("ctx", EditProductContext)
kb = back_to_product_kb(ctx.product_id, cb_factory=lambda p: f"product:{p}")
if not msg.photo:
await msg.delete()
await ctx.msg.edit_text("❌ Отправьте именно фотографию.", reply_markup=kb)
await state.set_state(AdminControlStorage.edit_product_photo)
await state.set_data({"ctx": ctx})
return
await state.clear()
await msg.delete()
try:
await ctx.msg.edit_text("⏳")
await products_repo.add_product_file_id(
session, ctx.product_id, file_id=msg.photo[-1].file_id
)
await ctx.msg.edit_text("✅ Фотография обновлена.", reply_markup=kb)
except Exception as e:
logger.exception(e)
await ctx.msg.edit_text("‼️ Что-то пошло не так.", reply_markup=kb)
@router.callback_query(
IsVerified(), F.data.startswith("edit_product:"), F.data.endswith(":delete_photo")
)
async def delete_product_photo(
cb: CallbackQuery,
state: FSMContext,
session: AsyncSession,
products_repo: ProductRepository,
):
await state.clear()
product_id = int(cb.data.split(":")[1])
product = await products_repo.clear_product_photo(session, product_id)
if not product:
await cb.answer("Товар не найден.", show_alert=True)
return
await cb.answer("Фото удалено.")
text = get_product_description(product)
reply_markup = admins.edit_product(product)
if cb.message.photo:
await cb.message.delete()
await cb.message.answer(text, reply_markup=reply_markup)
return
if cb.message.caption:
await cb.message.edit_text(text, reply_markup=reply_markup)
return
await cb.message.edit_reply_markup(reply_markup=reply_markup)
@router.callback_query(F.data.startswith("edit:"))
async def edit_entry(cb: CallbackQuery, state: FSMContext):
await state.clear()