async def admin_menu_template_delete_handler(call: types.CallbackQuery, state: FSMContext, *args, **kwargs): template_id = (await state.get_data("template_id")).get("template_id") template_name = (await state.get_data("template_name")).get("template_name") Template.drop_template(template_id) if state: await state.finish() await call.answer(text=f"Шаблон {template_name} удалён!") await select_menu_today_handler(call)
async def add_new_template_handler(message: types.Message, state: FSMContext, *args, **kwargs): template_name = message.text Template.create_template(template_name) template_id = Template.get_template_id(template_name) await state.set_data({ "template_name": template_name, "template_id": template_id }) await ChangeTemplate.start.set() await admin_menu_template_change_handler(message, state)
async def wrapper(message, state=None, *args, **kwargs): from handlers.user_handlers import main_menu_handler if Template.get_menu_status() == "Меню активно": await func(message, state, args, kwargs) if state else await func(message, args, kwargs) elif Template.get_menu_status() == "Меню не активно": if isinstance(message, types.CallbackQuery): await message.answer("Меню уже недоступно! Приходите завтра!") await main_menu_handler(message.message) else: await main_menu_handler(message) await message.answer("Меню уже недоступно! Приходите завтра!") else: await main_menu_handler(message) await message.answer("Меню на сегодня ещё не составлено! Приходите позже!")
async def select_menu_today_handler(call: types.CallbackQuery, *args, **kwargs): # все меню сегодня Null, а выбранное True, redirect на admin_menu_status template_id = call.data.split(":")[1] ok = Template.set_active_menu(template_id) while not ok: pass await admin_menu_status_handler(call, active_menu=True)
async def select_menu_today_handler(call: types.CallbackQuery, *args, **kwargs): await call.message.edit_text("Выбор меню на сегодня") templates = Template.get_templates() for num, template in enumerate(templates, start=1): await call.message.answer( text=f"{num}. {hbold(template.template_name)}\n", reply_markup=get_inline_keyboard_markup( text=f"Выбрать {template.template_name}", callback_data=f"select_menu_today_active:{template.id}"))
async def admin_menu_status_handler(call: types.CallbackQuery, *args, **kwargs): menu_status = Template.get_menu_status() if kwargs.get("active_menu"): await call.message.answer( text=f"Статус меню: {hbold(menu_status)}", reply_markup=get_keyboard_admin_menu_status(menu_status)) else: await call.message.edit_text( text=f"Статус меню: {hbold(menu_status)}", reply_markup=get_keyboard_admin_menu_status(menu_status))
def get_template_keyboard(): """:return: Keyboard with loop of template buttons""" button_list = [[ InlineKeyboardButton(text="Добавить новый шаблон", callback_data="add_new_template") ]] button_list_pref = [[ InlineKeyboardButton( text=x.template_name, callback_data=f"select_template:{x.template_name}:{x.id}") ] for x in Template.get_templates()] button_list += button_list_pref button_list.append([ InlineKeyboardButton(text="Назад", callback_data="admin_menu_status") ]) category_keyboard = InlineKeyboardMarkup(inline_keyboard=button_list) return category_keyboard
async def menu_today_false_handler(call: types.CallbackQuery, *args, **kwargs): Template.set_false() await call.answer("Меню не активно!") await admin_menu_status_handler(call)