from aiogram import F, Router
from contextlib import suppress
from aiogram.exceptions import TelegramBadRequest
from aiogram.fsm.context import FSMContext
from aiogram.types import CallbackQuery, FSInputFile
from aiogram.types.input_media_photo import InputMediaPhoto
from src.services import DataBase1
from src.states.user import BasketTask
from src.keyboards import menu_inline_order
from src import keyboards
router: Router = Router()
db1 = DataBase1('tg_order.db')
list_full_basket = [[]]
list_basket_delete = None
@router.callback_query(BasketTask.page, keyboards.Basket.filter(F.action.in_(['prev_basket', 'next_basket'])))
async def pagination_handler(call: CallbackQuery, callback_data: keyboards.Basket, state: FSMContext):
page_num_basket = int(callback_data.page)
page_basket = page_num_basket - 1 if page_num_basket > 0 else 0
media_photo = FSInputFile('gh.png')
if callback_data.action == 'next_basket':
await call.answer()
page_basket = page_num_basket + 1 if page_num_basket < (len(list_full_basket) - 1) else page_num_basket
with suppress(TelegramBadRequest):
await state.update_data(page=page_basket)
data = await state.get_data()
print(data)
await call.message.edit_media(InputMediaPhoto(
media=media_photo if page_basket == 0 else list_full_basket[page_basket][0],
caption=f'{list_full_basket[page_basket][1]}'),
reply_markup=keyboards.paginator_basket(page_basket) if page_basket > 0 else keyboards.paginator_basket_start()
)
@router.callback_query(F.data == 'basket')
async def check_history(call: CallbackQuery, state: FSMContext):
try:
data1 = await state.get_data()
page_basket = data1['page']
data = await db1.select_task_label(call.from_user.id)
label = data[page_basket - 1][0]
await db1.delete_task(call.from_user.id, label)
except KeyError:
pass
await state.clear()
await call.message.delete()
await call.answer()
photo_p = 'gh.png'
all_show_basket = await db1.show_all_basket(call.from_user.id)
final_show_basket = all_show_basket
if len(final_show_basket) == 0:
await call.message.answer('В корзине пока нет товаров(\n'
'Заказывайте скорее!', reply_markup=menu_inline_order)
else:
await state.set_state(BasketTask.page)
global list_full_basket
text = ''.join(f'{all_sh[3]}@'
f'Имя пользователя: {all_sh[2]}'
' '
f'Трек номер: {all_sh[9]}'
' '
f'Ссылка на товар: {all_sh[5]}'
' '
f'Цена: {all_sh[6]} рублей '
' '
f'Размер: {all_sh[7]} EU'
' '
f'Доставка: {all_sh[8]}'
' '
f'Номер телефона: {all_sh[9]}@' for all_sh in final_show_basket)
start_text = ''.join(f'{start_price[4]}@'
f'В вашей корзине: {len(final_show_basket)} товаров'
' '
f'На обшую сумму: {start_price[6]} рублей' for start_price in all_show_basket)
print(start_text)
show_list = start_text.split('@')
up_show_list_basket = [show_list[u:u + 2] for u in range(0, len(show_list), 2)]
up_list_basket = text.split('@')
res_list_basket = [up_list_basket[b:b + 2] for b in range(0, len(up_list_basket), 2)]
final_list_basket = res_list_basket[: -1]
list_full_basket = up_show_list_basket + final_list_basket
await call.message.answer_photo(photo=FSInputFile(path=photo_p),
caption=f'{list_full_basket[0][1]}',
reply_markup=keyboards.paginator_basket_start())
class BasketTask(StatesGroup):
page = State()
final = State()
Вот код самого сервис файла
Что касаемо нашего спора, хочу решить свой вопрос, я сюда не спорить пришел