added crud operations for Course
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import logging
|
||||
from telebot import types
|
||||
from database.models import Courses
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def register(bot):
|
||||
@bot.message_handler(func=lambda message: message.text == "Show Courses")
|
||||
def get_students(message):
|
||||
try:
|
||||
data = Courses.getAllCourses()
|
||||
if data:
|
||||
markup = types.InlineKeyboardMarkup(row_width=2)
|
||||
for row in data:
|
||||
btn = types.InlineKeyboardButton(
|
||||
f"{row[1][:26] + "..."} | id#{row[0]}", callback_data=f"course_{row[0]}")
|
||||
markup.add(btn)
|
||||
|
||||
# add button for creating a new course
|
||||
markup.add(types.InlineKeyboardButton(
|
||||
"➕ Create New Course", callback_data="create_course"))
|
||||
|
||||
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 Courses) handler: {e}")
|
||||
bot.reply_to(message, "Sorry, an error occurred.")
|
||||
@@ -1,4 +1,4 @@
|
||||
from . import start, students, teachers, common
|
||||
from . import start, students, teachers, courses, common
|
||||
from bot.callbacks.init import register_all_callbacks
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ def register_all_handlers(bot):
|
||||
start.register(bot)
|
||||
students.register(bot)
|
||||
teachers.register(bot)
|
||||
courses.register(bot)
|
||||
common.register(bot) # Must be last (catch-all)
|
||||
|
||||
# Callback handlers
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from telebot import types
|
||||
from bot.utils.auth import is_authenticated
|
||||
|
||||
# TODO: Add Pagincation to Showing rows of entities (To all entities)
|
||||
|
||||
|
||||
def register(bot):
|
||||
@bot.message_handler(commands=["start"])
|
||||
@@ -16,11 +18,6 @@ def register(bot):
|
||||
bot.reply_to(message, "Use buttons to fetch from database.",
|
||||
reply_markup=markup)
|
||||
|
||||
@bot.message_handler(func=lambda message: message.text in ["Show Courses", "Show Tag", "Show Categories"])
|
||||
def handle_test_options(message):
|
||||
option = message.text
|
||||
bot.send_message(message.chat.id, f"You selected: {option}")
|
||||
|
||||
|
||||
def startMarkup():
|
||||
markup = types.ReplyKeyboardMarkup(
|
||||
|
||||
Reference in New Issue
Block a user