added crud opertions for tag entity
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from . import start, students, teachers, courses, common
|
||||
from . import start, students, teachers, courses, tags, common
|
||||
from bot.callbacks.init import register_all_callbacks
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ def register_all_handlers(bot):
|
||||
students.register(bot)
|
||||
teachers.register(bot)
|
||||
courses.register(bot)
|
||||
tags.register(bot)
|
||||
common.register(bot) # Must be last (catch-all)
|
||||
|
||||
# Callback handlers
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import logging
|
||||
from telebot import types
|
||||
from database.models import Tags
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def register(bot):
|
||||
@bot.message_handler(func=lambda message: message.text == "Show Tags")
|
||||
def get_tags(message):
|
||||
try:
|
||||
data = Tags.getAllTags()
|
||||
if data:
|
||||
markup = types.InlineKeyboardMarkup(row_width=2)
|
||||
|
||||
for row in data:
|
||||
btn = types.InlineKeyboardButton(
|
||||
f"{row[1]} | id#{row[0]}", callback_data=f"tag_{row[0]}")
|
||||
markup.add(btn)
|
||||
|
||||
# add button for creating a new tag
|
||||
markup.add(types.InlineKeyboardButton(
|
||||
"➕ Create New Tag", callback_data="create_tag"))
|
||||
|
||||
bot.send_message(
|
||||
message.chat.id, "Here is the data:", reply_markup=markup)
|
||||
else:
|
||||
bot.reply_to(message, "No data found.")
|
||||
except Exception as e:
|
||||
logger.error(f"Error in 'Show Tags' handler: {e}")
|
||||
bot.reply_to(message, "Sorry, an error occurred.")
|
||||
Reference in New Issue
Block a user