Skip to main content

A library designed to build pagination using the aiogram library

Project description

aiopagination

About

aiopagination is a library written using the aiogram library to help you create pagination using inline buttons

Info: A sample to use

from aiogram import executor
from aiogram import types

from aiopagination.test.data.loader import dp
from aiopagination.widgets.aiokeyboards import base_cd, pagination_cd

from aiopagination.widgets.aiopagination import Pagination




sample_list = [
    (1, "Apple", 'red'),
    (2, "Cucumber", "green"),
    (3, "Melon", "yellow"),
    (4, "Cherry", "red"),
    (5, "Watermelon", "green"),
    (6, "Banana", "yellow"),
    (7, "Carrot", "orange"),
    (8, "Kiwi", "green"),
    (9, "Malina", "red"),
    (10, "Apelsin", "yellow"),
    (11, "Lemon", "yellow"),
    (12, "Grape", "black"),
    (13, "Carrot", "red"),
    (14, "Potato", "yellow"),
    (15, "Potato", "yellow"),
    (16, "Banana", "yellow"),
    (17, "Carrot", "orange"),
    (18, "Kiwi", "green"),
    (19, "Malina", "red"),
    (20, "Apelsin", "yellow"),
    (21, "Lemon", "yellow"),
    (22, "Grape", "black"),
    (23, "Carrot", "red"),
    (24, "Potato", "yellow")
]







# start
@dp.message_handler(commands=["start"])
async def bot_start(message: types.Message):
    pagination = Pagination(sample_list)
    await pagination.start_message(message=message)




# select item and send to user
@dp.callback_query_handler(base_cd.filter())
async def get_item_id(call: types.CallbackQuery, callback_data: dict):
    await call.answer(cache_time=1)
    item_id = callback_data.get("item_id")
    pag = Pagination(sample_list)
    get_data = await pag.select_item(item_id=int(item_id))

    await call.message.answer(get_data[1], parse_mode="HTML")





# pagination keyboards
@dp.callback_query_handler(pagination_cd.filter())
async def show_pagination(call: types.CallbackQuery, callback_data: dict):
    start = int(callback_data.get("start"))
    end = int(callback_data.get("end"))
    max_pages = int(callback_data.get("max_pages"))
    action = callback_data.get("action")

    pagination = Pagination(items=sample_list)
    if action == "prev":
        await pagination.prev(call=call, start=start, end=end, max_pages=max_pages)
    elif action == "next":
        await pagination.next(call=call, start=start, end=end, max_pages=max_pages)
    else:
        await call.answer(cache_time=1)
        await call.message.edit_reply_markup()
        await call.message.edit_text("Menga matn yuboring")





if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiopagination-1.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

aiopagination-1.0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file aiopagination-1.0.2.tar.gz.

File metadata

  • Download URL: aiopagination-1.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for aiopagination-1.0.2.tar.gz
Algorithm Hash digest
SHA256 6c2b13e5dec20a45c9dfa666171e18579d5ed1c5e70effb0b31adfb2c5582665
MD5 bf23d934a38ba269704fe61143ae764b
BLAKE2b-256 53db3a9a86c3762a02ba4b5c667650e869a6be222d89e4b6da02f201b3ea0d1e

See more details on using hashes here.

File details

Details for the file aiopagination-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aiopagination-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 52f907bc456744cadef552faf1f5eabec727a9df0140bc57b7a7e9c3d87df9ff
MD5 0d67e779dc180d31fd7f15add8e6486c
BLAKE2b-256 9475e68e99eef78232b00d2ab7cff819adb1df2537316a1cd3657399096a715b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page