diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py
index 8a932cb..8641898 100644
--- a/bot_modules/mod_table_operate.py
+++ b/bot_modules/mod_table_operate.py
@@ -131,7 +131,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
return None
child_mod = self.GetModule(self.m_ChildModName)
cur_buttons = [
- keyboard.InlineButton(child_mod.GetButton(ButtonNames.LIST), child_mod.GetSelectPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW),
+ keyboard.InlineButtonWithAccess(child_mod.GetButton(ButtonNames.LIST), child_mod.GetSelectPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(cur_buttons, a_UserGroups)
@@ -141,22 +141,23 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)],\
a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]
- def ShowMessageTemplate(self, a_Message, keyboard_template_func = None):
+ def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery, a_Item):
msg = a_Message.StaticCopy()
# TODO: добавить поддержку языка в a_MessageName
- keyboard_func = None
+ Inline_keyboard_func = None
item_access = None
if a_Item:
- if len(a_Item) < self.m_Table.GetFieldsCount():
+ if len(a_Item) < self.m_Table.GetFieldsCount() - 1: # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func
return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND))
- msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item))
- msg.UpdatePhotoID(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)])
+ elif len(a_Item) == self.m_Table.GetFieldsCount():
+ msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item))
+ msg.UpdatePhotoID(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)])
item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]
- if keyboard_template_func:
- keyboard_func = keyboard_template_func(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)])
+ if Inline_keyboard_template_func:
+ Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)])
- return simple_message.WorkFuncResult(msg, item_access = item_access, keyboard_func = keyboard_func)
+ return simple_message.WorkFuncResult(msg, item_access = item_access, Inline_keyboard_func = Inline_keyboard_func)
return ShowMessage
# TODO: delete?
diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py
index b3ed5f8..ca69097 100644
--- a/bot_modules/tasks.py
+++ b/bot_modules/tasks.py
@@ -3,36 +3,27 @@
# Задачи
-from bot_sys import bot_bd, bd_table, keyboard, user_access
-from bot_modules import start, access, groups, projects, needs, comments
-from template import bd_item_view, simple_message, bd_item_delete, bd_item_edit, bd_item, bd_item_add, bd_item_select
-
-from aiogram import types
+from bot_sys import bot_bd, keyboard, user_access, user_messages, bd_table
+from bot_modules import mod_table_operate
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
-from aiogram.dispatcher import Dispatcher
-import sqlite3
-class FSMCreateTask(StatesGroup):
+class FSMCreateTasks(StatesGroup):
name = State()
desc = State()
photo = State()
-class FSMEditTaskPhotoItem(StatesGroup):
- item_id = State()
+class FSMEditTasksPhotoItem(StatesGroup):
item_field = State()
-class FSMEditTaskNameItem(StatesGroup):
- item_id = State()
+class FSMEditTasksNameItem(StatesGroup):
item_field = State()
-class FSMEditTaskDescItem(StatesGroup):
- item_id = State()
+class FSMEditTasksDescItem(StatesGroup):
item_field = State()
-class FSMEditTaskAccessItem(StatesGroup):
- item_id = State()
+class FSMEditTasksAccessItem(StatesGroup):
item_field = State()
# ---------------------------------------------------------
# БД
@@ -57,327 +48,101 @@ table = bd_table.Table(table_name, [
bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT),
])
-init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
- {key_name} INTEGER PRIMARY KEY,
- {name_field} TEXT,
- {desc_field} TEXT,
- {photo_field} TEXT,
- {access_field} TEXT,
- {create_datetime_field} TEXT,
- {parent_id_field} INTEGER
- )''',
-f"INSERT OR IGNORE INTO module_access (modName, modAccess, itemDefaultAccess) VALUES ('{module_name}', '{user_access.user_access_group_new}=va', '{user_access.user_access_group_new}=va');"
-]
+init_access = f'{user_access.user_access_group_new}=va'
-select_tasks_prefix = ''
+fsm = mod_table_operate.FSMs(FSMCreateTasks, FSMEditTasksNameItem, FSMEditTasksDescItem, FSMEditTasksPhotoItem, FSMEditTasksAccessItem)
# ---------------------------------------------------------
-# Сообщения
-
-tasks_button_name = "✎ Задачи"
-base_task_message = '''
-✎ Задачи
-
-'''
-
-list_task_button_name = "📃 Список задач"
-select_task_message = '''
+# Сообщения и кнопки
+
+button_names = {
+ mod_table_operate.ButtonNames.START: "✎ Задачи",
+ mod_table_operate.ButtonNames.LIST: "📃 Список задач",
+ mod_table_operate.ButtonNames.ADD: "☑ Добавить задачу",
+ mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать задачу",
+ mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у задачи",
+ mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у задачи",
+ mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у задачи",
+ mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к задаче",
+ mod_table_operate.ButtonNames.DEL: "❌ Удалить задачу",
+}
+
+messages = {
+ mod_table_operate.Messages.START: f'''
+{button_names[mod_table_operate.ButtonNames.START]}
+
+''',
+ mod_table_operate.Messages.SELECT: '''
Пожалуйста, выберите задачу:
-'''
-
-error_find_proj_message = '''
+''',
+ mod_table_operate.Messages.ERROR_FIND: '''
❌ Ошибка, задача не найдена
-'''
-
-task_open_message = f'''
+''',
+ mod_table_operate.Messages.OPEN: f'''
Задача: #{name_field}
#{desc_field}
Время создания: #{create_datetime_field}
-'''
-
-# Создание задачи
-
-add_task_button_name = "☑ Добавить задачу"
-task_create_name_message = '''
+''',
+ mod_table_operate.Messages.CREATE_NAME: '''
Создание задачи. Шаг №1
Введите название задачи:
-'''
-
-task_create_desc_message = '''
+''',
+ mod_table_operate.Messages.CREATE_DESC: '''
Создание задачи. Шаг №2
Введите описание задачи:
-'''
-
-task_create_photo_message = '''
+''',
+ mod_table_operate.Messages.CREATE_PHOTO: '''
Создание задачи. Шаг №3
Загрузите обложку для задачи (Фото):
Она будет отображаться в её описании.
-'''
-
-task_success_create_message = '''✅ Задача успешно добавлена!'''
-
-# Редактирование задачи.
-
-edit_task_button_name = "🛠 Редактировать задачу"
-task_start_edit_message= '''
+''',
+ mod_table_operate.Messages.SUCCESS_CREATE: '''✅ Задача успешно добавлена!''',
+ mod_table_operate.Messages.START_EDIT: '''
Пожалуйста, выберите действие:
-'''
-
-task_select_to_edit_message = '''
+''',
+ mod_table_operate.Messages.SELECT_TO_EDIT: '''
Выберите задачу, которую вы хотите отредактировать.
-'''
-
-edit_task_photo_button_name = "☐ Изменить изображение у задачи"
-task_edit_photo_message = '''
+''',
+ mod_table_operate.Messages.EDIT_PHOTO: '''
Загрузите новую обложку для задачи (Фото):
Она будет отображаться в её описании.
-'''
-
-edit_task_name_button_name = "≂ Изменить название у задачи"
-task_edit_name_message = f'''
+''',
+ mod_table_operate.Messages.EDIT_NAME: f'''
Текущее название задачи:
#{name_field}
Введите новое название задачи:
-'''
-
-edit_task_desc_button_name = "𝌴 Изменить описание у задачи"
-task_edit_desc_message = f'''
+''',
+ mod_table_operate.Messages.EDIT_DESC: f'''
Текущее описание задачи:
#{desc_field}
Введите новое описание задачи:
-'''
-
-edit_task_access_button_name = "✋ Изменить доступ к задаче"
-task_edit_access_message = f'''
+''',
+ mod_table_operate.Messages.EDIT_ACCESS: f'''
Текущий доступ к задаче:
#{access_field}
{user_access.user_access_readme}
Введите новую строку доступа:
-'''
-
-task_success_edit_message = '''✅ Задача успешно отредактирована!'''
-
-# Удаление задачи
-
-del_task_button_name = "❌ Удалить задачу"
-task_select_to_delete_message = '''
+''',
+ mod_table_operate.Messages.SUCCESS_EDIT: '''✅ Задача успешно отредактирован!''',
+ mod_table_operate.Messages.SELECT_TO_DELETE: '''
Выберите задачу, которую вы хотите удалить.
-Все потребности в этой задачае так же будут удалены!
-'''
-
-task_success_delete_message = '''✅ Задача успешно удалена!'''
-
-# ---------------------------------------------------------
-# Работа с кнопками
-
-def GetEditTaskKeyboardButtons(a_Message, a_UserGroups):
- cur_buttons = GetModuleButtons() + [
- keyboard.ButtonWithAccess(edit_task_photo_button_name, user_access.AccessMode.EDIT, GetAccess()),
- keyboard.ButtonWithAccess(edit_task_name_button_name, user_access.AccessMode.EDIT, GetAccess()),
- keyboard.ButtonWithAccess(edit_task_desc_button_name, user_access.AccessMode.EDIT, GetAccess()),
- keyboard.ButtonWithAccess(edit_task_access_button_name, user_access.AccessMode.ACCEES_EDIT, GetAccess()),
- ]
- mods = [start]
- return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
-
-def GetStartTaskKeyboardButtons(a_Message, a_UserGroups):
- cur_buttons = [
- keyboard.ButtonWithAccess(list_task_button_name, user_access.AccessMode.VIEW, GetAccess()),
- keyboard.ButtonWithAccess(add_task_button_name, user_access.AccessMode.ADD, GetAccess()),
- keyboard.ButtonWithAccess(del_task_button_name, user_access.AccessMode.DELETE, GetAccess()),
- keyboard.ButtonWithAccess(edit_task_button_name, user_access.AccessMode.EDIT, GetAccess())
- ]
- mods = [start, projects, needs, comments]
- return keyboard.MakeKeyboard(keyboard.GetButtons(mods) + cur_buttons, a_UserGroups)
-
-def GetViewItemInlineKeyboardTemplate(a_ItemID):
- def GetViewItemInlineKeyboard(a_Message, a_UserGroups):
- cur_buttons = [
- keyboard.InlineButton(needs.list_need_button_name, needs.select_needs_prefix, a_ItemID, GetAccess(), user_access.AccessMode.VIEW),
- ]
- return keyboard.MakeInlineKeyboard(cur_buttons, a_UserGroups)
- return GetViewItemInlineKeyboard
-
-# ---------------------------------------------------------
-# Обработка сообщений
-
-# стартовое сообщение
-async def TasksOpen(a_Message : types.message, state = None):
- return simple_message.WorkFuncResult(base_task_message)
-
-def GetButtonNameAndKeyValueAndAccess(a_Item):
- # taskName taskID taskAccess
- return a_Item[1], a_Item[0], a_Item[4]
-
-def ShowMessageTemplate(a_StringMessage, keyboard_template_func = None):
- async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
- if (len(a_Item) < 6):
- return simple_message.WorkFuncResult(error_find_proj_message)
-
- msg = a_StringMessage.\
- replace(f'#{name_field}', a_Item[1]).\
- replace(f'#{desc_field}', a_Item[2]).\
- replace(f'#{create_datetime_field}', a_Item[5]).\
- replace(f'#{access_field}', a_Item[4])
- keyboard_func = None
- if keyboard_template_func:
- keyboard_func = keyboard_template_func(a_Item[0])
- return simple_message.WorkFuncResult(msg, photo_id = a_Item[3], item_access = a_Item[4], keyboard_func = keyboard_func)
- return ShowMessage
-
-def SimpleMessageTemplateLegacy(a_StringMessage):
- async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
- return simple_message.WorkFuncResult(a_StringMessage)
- return ShowMessage
-
-# Удаление задачи
-
-async def TaskPreDelete(a_CallbackQuery : types.CallbackQuery, a_Item):
- if (len(a_Item) < 6):
- return simple_message.WorkFuncResult(error_find_proj_message)
- access = a_Item[4]
- return simple_message.WorkFuncResult('', None, item_access = access)
-
-async def TaskPostDelete(a_CallbackQuery : types.CallbackQuery, a_ItemID):
- log.Success(f'Задача №{a_ItemID} была удалена пользователем {a_CallbackQuery.from_user.id}.')
- #TODO: удалить вложенные
- return simple_message.WorkFuncResult(task_success_delete_message)
-
-# ---------------------------------------------------------
-# Работа с базой данных задач
-
-def AddBDItemFunc(a_ItemData, a_UserID):
- res, error = bot_bd.SQLRequestToBD(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})',
- commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], access.GetItemDefaultAccessForModule(module_name) + f";{a_UserID}=+", a_ItemData[parent_id_field]))
-
- if error:
- log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
- else:
- log.Success(f'Пользоватлель {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
-
- return res, error
-
-# ---------------------------------------------------------
-# API
-
-# Инициализация БД
-def GetInitBDCommands():
- return init_bd_cmds
-
-def GetAccess():
- return access.GetAccessForModule(module_name)
-
-# Доступные кнопки
-def GetModuleButtons():
- return [keyboard.ButtonWithAccess(tasks_button_name, user_access.AccessMode.VIEW, GetAccess())]
-
-# Обработка кнопок
-def RegisterHandlers(dp : Dispatcher):
- defaul_keyboard_func = GetStartTaskKeyboardButtons
- def RegisterSelectParent(a_ButtonName, access_mode):
- a_PrefixBase = a_ButtonName
- return bd_item_select.FirstSelectBDItemRegisterHandlers(dp, \
- a_PrefixBase, \
- a_ButtonName, \
- projects.table_name, \
- projects.key_name, \
- projects.GetButtonNameAndKeyValueAndAccess, \
- projects.select_project_message, \
- projects.GetAccess, access_mode = access_mode\
- )
-
- # Стартовое сообщение
- dp.register_message_handler(simple_message.SimpleMessageTemplateLegacy(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name)
-
- # Список задач
- a_Prefix = RegisterSelectParent(list_task_button_name, user_access.AccessMode.VIEW)
- bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \
- a_Prefix, parent_id_field, \
- table_name, key_name, \
- ShowMessageTemplate(task_open_message, GetViewItemInlineKeyboardTemplate), \
- GetButtonNameAndKeyValueAndAccess, \
- select_task_message, \
- GetAccess, \
- defaul_keyboard_func, \
- access_mode = user_access.AccessMode.VIEW\
- )
- global select_tasks_prefix
- select_tasks_prefix = a_Prefix
-
- # Удаление задачи
- a_Prefix = RegisterSelectParent(del_task_button_name, user_access.AccessMode.DELETE)
- bd_item_delete.DeleteBDItemRegisterHandlers(dp, \
- a_Prefix, \
- bd_item.GetCheckForPrefixFunc(a_Prefix), \
- table_name, \
- key_name, \
- parent_id_field, \
- TaskPreDelete, \
- TaskPostDelete, \
- GetButtonNameAndKeyValueAndAccess, \
- select_task_message, \
- GetAccess, \
- defaul_keyboard_func\
- )
-
- # Добавление задачи
- a_Prefix = RegisterSelectParent(add_task_button_name, user_access.AccessMode.ADD)
- bd_item_add.AddBDItem3RegisterHandlers(dp, \
- bd_item.GetCheckForPrefixFunc(a_Prefix), \
- FSMCreateTask, \
- FSMCreateTask.name,\
- FSMCreateTask.desc, \
- FSMCreateTask.photo,\
- AddBDItemFunc, \
- SimpleMessageTemplateLegacy(task_create_name_message), \
- SimpleMessageTemplateLegacy(task_create_desc_message), \
- SimpleMessageTemplateLegacy(task_create_photo_message), \
- SimpleMessageTemplateLegacy(task_success_create_message), \
- a_Prefix,\
- projects.table_name, \
- projects.key_name, \
- name_field, \
- desc_field, \
- photo_field, \
- GetButtonNameAndKeyValueAndAccess, \
- GetAccess, \
- GetStartTaskKeyboardButtons\
- )
-
- def RegisterEdit(a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT):
- a_Prefix = RegisterSelectParent(a_ButtonName, a_AccessMode)
- bd_item_edit.EditBDItemRegisterHandlers(dp, \
- a_Prefix, \
- a_FSM, \
- bd_item.GetCheckForPrefixFunc(a_Prefix), \
- task_select_to_edit_message, \
- ShowMessageTemplate(a_EditMessage), \
- ShowMessageTemplate(task_success_edit_message), \
- table_name, \
- key_name, \
- parent_id_field, \
- a_FieldName, \
- GetButtonNameAndKeyValueAndAccess, \
- GetAccess, \
- edit_keyboard_func, \
- access_mode = a_AccessMode, \
- field_type = a_FieldType\
- )
+Все потребности в этой задаче так же будут удалены!
+''',
+ mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Задача успешно удалёна!''',
+}
- # Редактирование задачи
- edit_keyboard_func = GetEditTaskKeyboardButtons
- dp.register_message_handler(simple_message.InfoMessageTemplateLegacy(task_start_edit_message, edit_keyboard_func, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_task_button_name)
+class ModuleTasks(mod_table_operate.TableOperateModule):
+ def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log):
+ super().__init__(table, messages, button_names, fsm, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log)
- RegisterEdit(edit_task_photo_button_name, FSMEditTaskPhotoItem, task_edit_photo_message, photo_field, bd_item.FieldType.photo)
- RegisterEdit(edit_task_name_button_name, FSMEditTaskNameItem, task_edit_name_message, name_field, bd_item.FieldType.text)
- RegisterEdit(edit_task_desc_button_name, FSMEditTaskDescItem, task_edit_desc_message, desc_field, bd_item.FieldType.text)
- RegisterEdit(edit_task_access_button_name, FSMEditTaskAccessItem, task_edit_access_message, access_field, bd_item.FieldType.text)
+ def GetName(self):
+ return module_name
diff --git a/main.py b/main.py
index afd4ba1..a585a19 100644
--- a/main.py
+++ b/main.py
@@ -6,7 +6,7 @@ log_start_message = 'Бот успешно запущен!'
import os
from bot_sys import config, log, bot_bd, user_access, aiogram_bot, bot_messages, bd_table
-from bot_modules import mod_agregator, start, profile, backup, groups, access, projects #, projects, , access, , tasks, needs, comments, messages, , languages
+from bot_modules import mod_agregator, start, profile, backup, groups, access, projects, tasks #, projects, , access, , , needs, comments, messages, , languages
g_Log = log
g_Bot = aiogram_bot.AiogramBot(config.GetTelegramBotApiToken(), bot_bd.GetBDFileName(), config.GetRootIDs(), g_Log)
@@ -38,10 +38,14 @@ g_ModuleAgregator.AddModule(mod_profile)
mod_backup = backup.ModuleBackup(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_backup)
-start_mod_name_list = [mod_start_name]#, mod_tasks_name, mod_needs_name, mod_comments_name]
-mod_project = projects.ModuleProjects(None, None, start_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
+start_mod_name_list = [mod_start_name, mod_tasks_name]#, , mod_needs_name, mod_comments_name]
+mod_project = projects.ModuleProjects(None, mod_tasks_name, start_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
g_ModuleAgregator.AddModule(mod_project)
+start_mod_name_list = [mod_start_name, mod_projects_name]#, mod_needs_name, mod_comments_name]
+mod_tasks = tasks.ModuleTasks(mod_projects_name, None, start_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log)
+g_ModuleAgregator.AddModule(mod_tasks)
+
start_mod_name_list = [#, '', , '', , 'languages']
mod_profile.GetName(),
mod_backup.GetName(),
diff --git a/template/bd_item_select.py b/template/bd_item_select.py
index 2931af2..8514c9e 100644
--- a/template/bd_item_select.py
+++ b/template/bd_item_select.py
@@ -23,14 +23,13 @@ def GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName : str, a_ParentIDFi
access = ''
if bname:
b = keyboard.InlineButtonWithAccess(bname, a_NextPrefix, key_value, access, access_mode)
- print('MakeInlineKeyboardButtons', b, bname, a_NextPrefix, key_value, access, access_mode)
items_button_list += [b]
return keyboard.MakeInlineKeyboardButtons(items_button_list, a_UserGroups)
return GetBDItemsListKeyboardButtons
def SelectDBItemTemplate(a_Bot, a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW):
- keyboard_func = GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
- return simple_message.InfoMessageTemplate(a_Bot, a_StartMessage, None, keyboard_func, a_AccessFunc, access_mode)
+ inline_keyboard_func = GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
+ return simple_message.InfoMessageTemplate(a_Bot, a_StartMessage, None, inline_keyboard_func, a_AccessFunc, access_mode)
def FirstSelectBDItemRegisterHandlers(a_Bot, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
diff --git a/template/simple_message.py b/template/simple_message.py
index 957cf6b..7da195b 100644
--- a/template/simple_message.py
+++ b/template/simple_message.py
@@ -29,10 +29,11 @@ async def AccessDeniedMessage(a_Bot, a_GetButtonsFunc, a_UserID, a_Message, user
return await SendMessage(a_Bot, bot_messages.MakeBotMessage(access_utils.access_denied_message), a_GetButtonsFunc, None, a_UserID, a_Message, user_groups)
class WorkFuncResult():
- def __init__(self, a_BotMessage, keyboard_func = None, item_access = None):
+ def __init__(self, a_BotMessage, keyboard_func = None, Inline_keyboard_func = None, item_access = None):
self.m_BotMessage = a_BotMessage
self.item_access = item_access
self.keyboard_func = keyboard_func
+ self.Inline_keyboard_func = Inline_keyboard_func
def InfoMessageTemplate(a_Bot, a_HelpMessage, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
async def GetMessage(a_Message : types.message, state = None):
@@ -52,7 +53,11 @@ def SimpleMessageTemplate(a_Bot, a_WorkFunc, a_GetButtonsFunc, a_GetInlineButton
if res is None:
return
- keyboard_func = a_GetInlineButtonsFunc
+ Inline_keyboard_func = a_GetInlineButtonsFunc
+ if res.Inline_keyboard_func:
+ Inline_keyboard_func = res.Inline_keyboard_func
+
+ keyboard_func = a_GetButtonsFunc
if res.keyboard_func:
keyboard_func = res.keyboard_func
@@ -61,7 +66,7 @@ def SimpleMessageTemplate(a_Bot, a_WorkFunc, a_GetButtonsFunc, a_GetInlineButton
return
if not res.item_access is None and not user_access.CheckAccess(a_Bot.GetRootIDs(), res.item_access, user_groups, access_mode):
- return await AccessDeniedMessage(a_Bot, a_GetButtonsFunc, user_id, a_Message, user_groups)
+ return await AccessDeniedMessage(a_Bot, keyboard_func, user_id, a_Message, user_groups)
msg = msg.GetMessageForLang(lang).StaticCopy()
@@ -69,7 +74,7 @@ def SimpleMessageTemplate(a_Bot, a_WorkFunc, a_GetButtonsFunc, a_GetInlineButton
user_id,
msg.GetDesc(),
msg.GetPhotoID(),
- ProxyGetButtonsTemplate(a_GetButtonsFunc)(a_Message, user_groups),
- ProxyGetButtonsTemplate(keyboard_func)(a_Message, user_groups)
+ ProxyGetButtonsTemplate(keyboard_func)(a_Message, user_groups),
+ ProxyGetButtonsTemplate(Inline_keyboard_func)(a_Message, user_groups)
)
return SimpleMessage