Reworked the logic for retrieving data from Zabbix API to make it more efficient and filter-aware. Message generation for Telegram bot was refactored and decoupled from data retrieval logic to improve structure, readability, and reuse. Signed-off-by: UdoChudo <stream@udochudo.ru>
33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||
|
||
from config import REGIONS_PER_PAGE
|
||
|
||
|
||
def create_region_keyboard(regions, page, page_size=REGIONS_PER_PAGE):
|
||
markup = InlineKeyboardMarkup(row_width=2)
|
||
|
||
start = page * page_size
|
||
end = start + page_size
|
||
page_regions = regions[start:end]
|
||
|
||
for region in page_regions:
|
||
region_id_str = f"{region['id']:02d}" # 2 цифры, с ведущими нулями
|
||
button_text = f"{region['id']:02d}: {region['name']}"
|
||
button = InlineKeyboardButton(text=button_text, callback_data=f"region_{region_id_str}")
|
||
markup.add(button)
|
||
|
||
# Пагинация
|
||
navigation_buttons = []
|
||
if page > 0:
|
||
navigation_buttons.append(InlineKeyboardButton("⬅️", callback_data=f"regions_page_{page - 1}"))
|
||
if end < len(regions):
|
||
navigation_buttons.append(InlineKeyboardButton("➡️", callback_data=f"regions_page_{page + 1}"))
|
||
if navigation_buttons:
|
||
markup.add(*navigation_buttons)
|
||
|
||
# Кнопка отмены в самый низ
|
||
cancel_button = InlineKeyboardButton("Отмена", callback_data="cancel_input")
|
||
markup.add(cancel_button)
|
||
|
||
return markup
|