chore: minor fixes and formatting
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import logging
|
||||
from aiogram import Router, F
|
||||
from aiogram.types import Message, CallbackQuery
|
||||
|
||||
from aiogram import F, Router
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from dto.catalogue import CategoryActionContext
|
||||
from dto.control import EditProductContext
|
||||
from misc.filters import IsVerified
|
||||
from misc.kb import admins
|
||||
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
|
||||
@@ -19,7 +21,7 @@ logger = logging.getLogger(__name__)
|
||||
router = Router()
|
||||
|
||||
|
||||
@router.callback_query(IsVerified(), F.data.startswith("edit_product:"))
|
||||
@router.callback_query(IsVerified(), F.data.regexp(r"^edit_product:\d+:(name|description|price)$"))
|
||||
async def edit_product(cb: CallbackQuery, state: FSMContext):
|
||||
await state.clear()
|
||||
|
||||
@@ -31,18 +33,14 @@ async def edit_product(cb: CallbackQuery, state: FSMContext):
|
||||
await cb.message.delete()
|
||||
msg = await cb.message.answer(
|
||||
f"<b>✍️ Введите {product_editing_mapping.get(mode)}</b>",
|
||||
reply_markup=back_to_product_kb(
|
||||
product_id, cb_factory=lambda p: f"product:{p}"
|
||||
),
|
||||
reply_markup=back_to_product_kb(product_id, cb_factory=lambda p: f"product:{p}"),
|
||||
)
|
||||
|
||||
else:
|
||||
msg = cb.message
|
||||
await cb.message.edit_text(
|
||||
f"<b>✍️ Введите {product_editing_mapping.get(mode)}</b>",
|
||||
reply_markup=back_to_product_kb(
|
||||
product_id, cb_factory=lambda p: f"product:{p}"
|
||||
),
|
||||
reply_markup=back_to_product_kb(product_id, cb_factory=lambda p: f"product:{p}"),
|
||||
)
|
||||
|
||||
ctx = EditProductContext(int(product_id), mode, msg)
|
||||
@@ -68,13 +66,9 @@ async def edit_product_query(
|
||||
try:
|
||||
await ctx.msg.edit_text("⏳")
|
||||
if ctx.mode == "name":
|
||||
await products_repo.update_product_name_by_id(
|
||||
session, ctx.product_id, msg.text
|
||||
)
|
||||
await products_repo.update_product_name_by_id(session, ctx.product_id, msg.text)
|
||||
elif ctx.mode == "description":
|
||||
await products_repo.update_product_description_by_id(
|
||||
session, ctx.product_id, msg.text
|
||||
)
|
||||
await products_repo.update_product_description_by_id(session, ctx.product_id, msg.text)
|
||||
elif ctx.mode == "price":
|
||||
if msg.text.isdigit():
|
||||
await products_repo.update_product_price_by_id(
|
||||
@@ -99,6 +93,33 @@ async def edit_product_query(
|
||||
await ctx.msg.edit_text(text="‼️ Что-то пошло не так.", reply_markup=kb)
|
||||
|
||||
|
||||
@router.callback_query(IsVerified(), F.data.startswith("edit_product:"), F.data.endswith(":hide"))
|
||||
async def toggle_product_visibility(
|
||||
cb: CallbackQuery,
|
||||
state: FSMContext,
|
||||
session: AsyncSession,
|
||||
products_repo: ProductRepository,
|
||||
):
|
||||
await state.clear()
|
||||
|
||||
product_id = int(cb.data.split(":")[1])
|
||||
product = await products_repo.toggle_product_hidden_by_id(session, product_id)
|
||||
if not product:
|
||||
await cb.answer("Товар не найден.", show_alert=True)
|
||||
return
|
||||
|
||||
await cb.answer("Товар скрыт." if product.is_hidden else "Товар снова виден.")
|
||||
|
||||
if cb.message.photo:
|
||||
await cb.message.edit_caption(
|
||||
caption=cb.message.caption,
|
||||
reply_markup=admins.edit_product(product),
|
||||
)
|
||||
return
|
||||
|
||||
await cb.message.edit_reply_markup(reply_markup=admins.edit_product(product))
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("edit:"))
|
||||
async def edit_entry(cb: CallbackQuery, state: FSMContext):
|
||||
await state.clear()
|
||||
@@ -143,6 +164,4 @@ async def edit_category(
|
||||
session=session, category_id=parse_cat_id(ctx.parent_id), value=msg.text
|
||||
)
|
||||
|
||||
await ctx.msg.edit_text(
|
||||
"✅ Успешно.", reply_markup=get_back_to_catalogue(cat.parent_id)
|
||||
)
|
||||
await ctx.msg.edit_text("✅ Успешно.", reply_markup=get_back_to_catalogue(cat.parent_id))
|
||||
|
||||
Reference in New Issue
Block a user