chore: minor fixes and formatting
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from .creation import router as creation_router
|
||||
from .inline_mode import router as inline_router
|
||||
from .menu import router as menu_router
|
||||
from .product_mgmt import router as product_router
|
||||
from .creation import router as creation_router
|
||||
|
||||
routers = [inline_router, menu_router, product_router, creation_router]
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
from aiogram import F, Router
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from dto.catalogue import CategoryActionContext
|
||||
from misc.filters import IsVerified
|
||||
from misc.kb.client import created_category, get_back_to_catalogue
|
||||
from misc.kb.common import return_menu
|
||||
from misc.mapper import parse_cat_id
|
||||
from misc.states import AdminControlStorage
|
||||
from misc.kb.common import return_menu
|
||||
from repositories.categories import CategoriesRepository
|
||||
from services.catalogue import CatalogueService
|
||||
|
||||
@@ -67,6 +67,6 @@ async def create_new_category(
|
||||
await ctx.msg.edit_text(
|
||||
f"✅ Категория {msg.text} создана успешно.",
|
||||
reply_markup=created_category(
|
||||
category.id, f"🛒 {category.name}", category.parent_id
|
||||
category.id, f"🛒 {category.name}", category.parent_id or "root"
|
||||
),
|
||||
)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Router, F
|
||||
from aiogram import F, Router
|
||||
from aiogram.types import (
|
||||
ChosenInlineResult,
|
||||
InlineQuery,
|
||||
@@ -26,9 +26,7 @@ async def send_invoice(iq: InlineQuery, amount: int):
|
||||
InlineQueryResultArticle(
|
||||
id=dict_to_b64({"a": amount}),
|
||||
title=f"💸 Счёт на {amount}₽",
|
||||
input_message_content=InputTextMessageContent(
|
||||
message_text="⏳ Создаю счёт..."
|
||||
),
|
||||
input_message_content=InputTextMessageContent(message_text="⏳ Создаю счёт..."),
|
||||
reply_markup=placeholder_kb,
|
||||
description="Нажмите, чтобы создать счёт.",
|
||||
),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import logging
|
||||
|
||||
from aiogram import Router, F
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Message, CallbackQuery
|
||||
from aiogram import F, Router
|
||||
from aiogram.filters import Command
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, Message
|
||||
|
||||
from misc.filters import IsVerified
|
||||
from misc.kb.admins import main_menu
|
||||
|
||||
@@ -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