chore: minor fixes and formatting
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
import contextlib
|
||||
import logging
|
||||
import os
|
||||
from re import Match
|
||||
from aiogram import Router, F
|
||||
from aiogram.types import CallbackQuery, FSInputFile
|
||||
from aiogram.exceptions import TelegramBadRequest
|
||||
|
||||
from aiogram import F, Router
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import CallbackQuery, FSInputFile
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from config import VERIFIED_ACCOUNTS
|
||||
@@ -23,9 +24,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@router.callback_query(
|
||||
F.data.regexp(r"products:(?P<category_id>.*):(?P<page_id>\d+)").as_(
|
||||
"pagination_match"
|
||||
)
|
||||
F.data.regexp(r"products:(?P<category_id>.*):(?P<page_id>\d+)").as_("pagination_match")
|
||||
)
|
||||
async def products_pagination(
|
||||
cb: CallbackQuery,
|
||||
@@ -39,11 +38,11 @@ async def products_pagination(
|
||||
pagination_data = pagination_match.groupdict()
|
||||
category_id = int(pagination_data.get("category_id"))
|
||||
page_id = int(pagination_data.get("page_id", 0))
|
||||
is_admin = cb.from_user.id in VERIFIED_ACCOUNTS
|
||||
|
||||
view = await catalogue_service.build_category_view(
|
||||
session, category_id, page=page_id
|
||||
session, category_id, page=page_id, include_hidden=is_admin
|
||||
)
|
||||
is_admin = cb.from_user.id in VERIFIED_ACCOUNTS
|
||||
|
||||
kb = render_catalogue(view, is_admin=is_admin)
|
||||
|
||||
@@ -61,10 +60,15 @@ async def product_card(
|
||||
await state.clear()
|
||||
|
||||
product_id = int(cb.data.split(":")[1])
|
||||
product = await products_repo.get_product_by_id(session, product_id)
|
||||
is_admin = cb.from_user.id in VERIFIED_ACCOUNTS
|
||||
product = await products_repo.get_product_by_id(session, product_id, include_hidden=is_admin)
|
||||
|
||||
if cb.from_user.id in VERIFIED_ACCOUNTS:
|
||||
kb = admins.edit_product(product_id=product.id, category_id=product.category_id)
|
||||
if not product:
|
||||
await cb.answer("Товар недоступен.", show_alert=True)
|
||||
return
|
||||
|
||||
if is_admin:
|
||||
kb = admins.edit_product(product)
|
||||
else:
|
||||
order_item = await order_service.get_cart_product_amount(
|
||||
session, customer=cb.from_user.id, product_id=product_id
|
||||
@@ -76,9 +80,7 @@ async def product_card(
|
||||
cart_amount=order_item,
|
||||
)
|
||||
|
||||
if not product.file_id and not (
|
||||
product.img_path and os.path.isfile(product.img_path)
|
||||
):
|
||||
if not product.file_id and not (product.img_path and os.path.isfile(product.img_path)):
|
||||
await cb.message.edit_text(
|
||||
get_product_description(product),
|
||||
reply_markup=kb,
|
||||
@@ -95,10 +97,8 @@ async def product_card(
|
||||
)
|
||||
return
|
||||
|
||||
try:
|
||||
with contextlib.suppress(Exception):
|
||||
await cb.message.edit_text("<b>⏳ Загружаем карточку товара...</b>")
|
||||
except TelegramBadRequest:
|
||||
...
|
||||
|
||||
msg = await cb.message.answer_photo(
|
||||
FSInputFile(product.img_path),
|
||||
@@ -110,9 +110,7 @@ async def product_card(
|
||||
logger.warning("didnt get a photo back wahhh :(")
|
||||
return # TODO: Add logging
|
||||
|
||||
await products_repo.add_product_file_id(
|
||||
session, product_id, file_id=msg.photo[-1].file_id
|
||||
)
|
||||
await products_repo.add_product_file_id(session, product_id, file_id=msg.photo[-1].file_id)
|
||||
|
||||
|
||||
@router.callback_query(F.data.startswith("cart_action:"))
|
||||
@@ -127,7 +125,13 @@ async def cart_action(
|
||||
|
||||
action = cb.data.split(":")[1]
|
||||
product_id = int(cb.data.split(":")[2])
|
||||
product = await products_repo.get_product_by_id(session, product_id)
|
||||
is_admin = cb.from_user.id in VERIFIED_ACCOUNTS
|
||||
product = await products_repo.get_product_by_id(session, product_id, include_hidden=is_admin)
|
||||
|
||||
if not product:
|
||||
await cb.answer("Товар недоступен.", show_alert=True)
|
||||
return
|
||||
|
||||
show_cart = True
|
||||
|
||||
if action == "add":
|
||||
|
||||
Reference in New Issue
Block a user