import io from aiogram import types from load import dp, messages from utils.database.market import Catalog from keyboard.inline.admin.catalog import item_list from keyboard.default.main_menu import back_to_main_menu @dp.callback_query_handler(lambda c: c.data.split("|")[0] in ["adm_prev", "adm_next"], is_admin=True) async def next_item_adm(callback: types.CallbackQuery): data = callback.data.split("|") count = int(data[1]) items = Catalog.get_catalog() item = items[count] await callback.message.edit_media( media=types.InputMediaPhoto( media=io.BytesIO(item["image"]), caption=messages.product_message.format( name=item["name"], description=item["description"], price=item['price'] ), parse_mode="Markdown", ), reply_markup=item_list(count, len(items) - 1, int(data[2])) ) @dp.callback_query_handler(lambda c: c.data.split("|")[0] == 'delete_post', is_admin=True) async def delete_post_adm(callback: types.CallbackQuery): data = callback.data.split("|") item_id = Catalog.get_catalog()[int(data[1])]["id"] Catalog.delete_post(item_id) items = Catalog.get_catalog() if items: item = items[0] await callback.message.edit_media( media=types.InputMediaPhoto( media=io.BytesIO(item["image"]), caption=messages.product_message.format( name=item["name"], description=item["description"], price=item['price'] ), parse_mode="Markdown", ), reply_markup=item_list(items=len(items) - 1) ) else: await callback.message.delete() await dp.bot.send_message( callback.message.chat.id, messages.catalog + " пуст!", reply_markup=back_to_main_menu ) await callback.answer("Товар удалён!") await callback.answer()