Telezab/app/bot/keyboards/active_triggers.py
Vladislav Zverev 0169bf5d6b refactor(alerts): improve active problem fetching and message formatting
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>
2025-06-17 23:44:30 +05:00

33 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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