Browse Source

Продолжение систематизации. Пока не работет редактирование.

test_bot
Alexei 2 years ago
parent
commit
ec4e83343c
  1. 19
      bot_modules/projects.py
  2. 39
      bot_modules/tasks.py
  3. 12
      template/bd_item.py
  4. 51
      template/bd_item_add.py
  5. 2
      template/bd_item_delete.py
  6. 2
      template/bd_item_edit.py
  7. 29
      template/bd_item_select.py
  8. 28
      template/bd_item_view.py

19
bot_modules/projects.py

@ -272,7 +272,23 @@ def RegisterHandlers(dp : Dispatcher):
bd_item_delete.DeleteBDItemRegisterHandlers(dp, del_project_button_name, table_name, key_name, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func)
# Добавление проекта
bd_item_add.AddBDItem3RegisterHandlers(dp, FSMCreateProject, FSMCreateProject.name, FSMCreateProject.desc, FSMCreateProject.photo, add_project_button_name, AddBDItemFunc, SimpleMessageTemplate(project_create_name_message), SimpleMessageTemplate(project_create_desc_message), SimpleMessageTemplate(project_create_photo_message), SimpleMessageTemplate(project_success_create_message), table_name, key_name, name_field, desc_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, GetStartProjectKeyboardButtons)
bd_item_add.AddBDItem3RegisterHandlers(dp, \
bd_item.GetCheckForTextFunc(add_project_button_name), \
FSMCreateProject, FSMCreateProject.name,\
FSMCreateProject.desc, FSMCreateProject.photo,\
AddBDItemFunc, SimpleMessageTemplate(project_create_name_message), \
SimpleMessageTemplate(project_create_desc_message), \
SimpleMessageTemplate(project_create_photo_message), \
SimpleMessageTemplate(project_success_create_message), \
None, \
None, \
name_field, \
desc_field, \
photo_field, \
GetButtonNameAndKeyValueAndAccess, \
GetAccess, \
GetStartProjectKeyboardButtons\
)
edit_keyboard_func = GetEditProjectKeyboardButtons
# Редактирование проекта
@ -281,4 +297,3 @@ def RegisterHandlers(dp : Dispatcher):
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_project_name_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_name_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_project_desc_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_desc_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text)
bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_project_access_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_access_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text)

39
bot_modules/tasks.py

@ -45,6 +45,7 @@ desc_field = 'taskDesc'
photo_field = 'taskPhoto'
access_field = 'taskAccess'
create_datetime_field = 'taskCreateDateTime'
parent_id_field = 'projectID'
init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
{key_name} INTEGER PRIMARY KEY,
@ -53,6 +54,7 @@ init_bd_cmds = [f'''CREATE TABLE IF NOT EXISTS {table_name}(
{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');"
]
@ -188,14 +190,12 @@ def GetStartTaskKeyboardButtons(a_Message, a_UserGroups):
# ---------------------------------------------------------
# Обработка сообщений
select_handler = 0
# стартовое сообщение
async def TasksOpen(a_Message : types.message, state = None):
user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(user_id)
await a_Message.answer(base_task_message, reply_markup = GetStartTaskKeyboardButtons(a_Message, user_groups))
await select_handler(a_Message)
return None
#user_id = str(a_Message.from_user.id)
#user_groups = groups.GetUserGroupData(user_id)
#await a_Message.answer(base_task_message, reply_markup = GetStartTaskKeyboardButtons(a_Message, user_groups))
return simple_message.WorkFuncResult(base_task_message)
def GetButtonNameAndKeyValueAndAccess(a_Item):
# taskName taskID taskAccess
@ -235,8 +235,8 @@ async def TaskPostDelete(a_CallbackQuery : types.CallbackQuery, a_ItemID):
# Работа с базой данных задач
def AddBDItemFunc(a_ItemData):
res, error = bot_bd.SQLRequestToBD(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_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)))
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), a_ItemData[desc_field]))
if error:
log.Error(f'Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
@ -263,16 +263,33 @@ def GetModuleButtons():
def RegisterHandlers(dp : Dispatcher):
defaul_keyboard_func = GetStartTaskKeyboardButtons
# Список задач
# Стартовое сообщение
dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name)
global select_handler
# Список задач
select_handler = bd_item_view.SelectAndShowBDItemRegisterHandlers(dp, list_task_button_name, table_name, key_name, ShowMessageTemplate(task_open_message), GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func)
# Удаление задачи
bd_item_delete.DeleteBDItemRegisterHandlers(dp, del_task_button_name, table_name, key_name, TaskPreDelete, TaskPostDelete, GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func)
# Добавление задачи
bd_item_add.AddBDItem3RegisterHandlers(dp, FSMCreateTask, FSMCreateTask.name, FSMCreateTask.desc, FSMCreateTask.photo, add_task_button_name, AddBDItemFunc, SimpleMessageTemplate(task_create_name_message), SimpleMessageTemplate(task_create_desc_message), SimpleMessageTemplate(task_create_photo_message), SimpleMessageTemplate(task_success_create_message), table_name, key_name, name_field, desc_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, defaul_keyboard_func)
bd_item_add.AddBDItem3RegisterHandlers(dp, \
bd_item.GetCheckForTextFunc(add_project_button_name), \
FSMCreateProject, FSMCreateProject.name,\
FSMCreateProject.desc, FSMCreateProject.photo,\
AddBDItemFunc, SimpleMessageTemplate(project_create_name_message), \
SimpleMessageTemplate(project_create_desc_message), \
SimpleMessageTemplate(project_create_photo_message), \
SimpleMessageTemplate(project_success_create_message), \
None, \
None, \
name_field, \
desc_field, \
photo_field, \
GetButtonNameAndKeyValueAndAccess, \
GetAccess, \
GetStartProjectKeyboardButtons\
)
edit_keyboard_func = GetEditTaskKeyboardButtons
# Редактирование задачи

12
template/bd_item.py

@ -26,6 +26,18 @@ class FieldType(Enum):
text = 'text'
photo = 'photo'
def GetCheckForPrefixFunc(a_Prefix):
return lambda x: x.data.startswith(a_Prefix)
def GetCheckForTextFunc(a_Text):
return lambda x: x.text == a_Text
def GetKeyDataFromCallbackMessage(a_Message, a_Prefix):
key_item_id = None
if hasattr(a_Message, 'data'):
key_item_id = str(a_Message.data).replace(a_PrevPrefix, '')
return key_item_id
def GetCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
def GetCancelKeyboardButtons(a_Message, a_UserGroups):
cur_buttons = [

51
template/bd_item_add.py

@ -16,21 +16,22 @@ cancel_message = '''
🚫 Добавление отменено
'''
def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_TableName, a_KeyName, a_FieldName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT):
parent_id_field_name = 'parent_id'
def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT):
async def StartAddBDItem(a_CallbackQuery : types.CallbackQuery, state : FSMContext):
user_id = str(a_CallbackQuery.from_user.id)
user_groups = groups.GetUserGroupData(user_id)
await a_FSMStart.set()
key_item_id = None
if hasattr(a_CallbackQuery, 'data'):
key_item_id = str(a_CallbackQuery.data).replace(a_Prefix, '')
parent_id = bd_item.GetKeyDataFromCallbackMessage(a_CallbackQuery, a_Prefix)
res_of_work_func = None
check = None
await a_FSMStart.set()
async with state.proxy() as item_data:
item_data['key_item_id'] = key_item_id
item_data[parent_id_field_name] = parent_id
if key_item_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_TableName, a_KeyName, key_item_id, a_MessageFunc, access_mode)(a_CallbackQuery)
if parent_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery)
else:
res_of_work_func = await a_MessageFunc(a_CallbackQuery)
@ -38,18 +39,18 @@ def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_TableName, a_KeyN
await state.finish()
check.keyboard_func = a_FinishButtonFunc
return check
if key_item_id:
if parent_id:
await a_FSM.next()
return res_of_work_func
return simple_message.SimpleMessageTemplate(StartAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode)
def FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, True, access_mode = access_mode, field_type = field_type)
def FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, True, access_mode = access_mode, field_type = field_type)
def NextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type)
def NextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
return FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type)
def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text):
async def FinishAddBDItem(a_Message : types.CallbackQuery, state : FSMContext):
state_func = None
if a_Finish:
@ -66,9 +67,9 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName
await state.finish()
return simple_message.WorkFuncResult(cancel_message, keyborad_func = a_FinishButtonFunc)
key_item_id = item_data['key_item_id']
if key_item_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_TableName, a_KeyName, key_item_id, a_MessageFunc, access_mode)(a_Message)
parent_id = item_data[parent_id_field_name]
if parent_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message)
else:
res_of_work_func = await a_MessageFunc(a_Message)
@ -97,14 +98,12 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName
return simple_message.SimpleMessageTemplate(FinishAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode)
def AddBDItem3RegisterHandlers(dp, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_ButtonName, a_AddBDItemFunc, a_AddNameMessageFunc, a_AddDescMessageFunc, a_AddPhotoMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_NameField, a_DescField, a_PhotoField, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD):
def AddBDItem3RegisterHandlers(dp, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_AddBDItemFunc, a_AddNameMessageFunc, a_AddDescMessageFunc, a_AddPhotoMessageFunc, a_FinishMessageFunc, a_ParentTableName : str, a_ParentKeyFieldName, a_NameField, a_DescField, a_PhotoField, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD):
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
a_Prefix = f'add_{a_TableName}_{a_KeyName}_{a_NameField}_{a_DescField}_{a_PhotoField}:'
# sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
# dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_message_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_TableName, a_KeyName, a_NameField, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), text = a_ButtonName)
dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_TableName, a_KeyName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName)
dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_TableName, a_KeyName, a_DescField, a_AddPhotoMessageFunc, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc)
dp.register_message_handler(FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo'], state = a_FSMPhoto)
dp.register_message_handler(FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_TableName, a_KeyName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['text'], state = a_FSMPhoto)
a_Prefix = f'add_{a_ParentTableName}_{a_ParentKeyFieldName}_{a_NameField}_{a_DescField}_{a_PhotoField}:'
dp.register_message_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc)
dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName)
dp.register_message_handler(NextAddBDItemTemplate(a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_DescField, a_AddPhotoMessageFunc, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc)
dp.register_message_handler(FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo'], state = a_FSMPhoto)
dp.register_message_handler(FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['text'], state = a_FSMPhoto)

2
template/bd_item_delete.py

@ -35,5 +35,5 @@ def DeleteBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName,
a_Prefix = f'delete_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(DeleteBDItemTemplate(a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix))
dp.register_callback_query_handler(DeleteBDItemTemplate(a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))

2
template/bd_item_edit.py

@ -80,7 +80,7 @@ def EditBDItemRegisterHandlers(dp, a_FSM, a_ButtonName, a_StartMessage, a_EditMe
a_Prefix = f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(StartEditBDItemTemplate(a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_FieldName, a_Prefix, a_AccessFunc, keyboard_cancel, access_mode), lambda x: x.data.startswith(a_Prefix))
dp.register_callback_query_handler(StartEditBDItemTemplate(a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_FieldName, a_Prefix, a_AccessFunc, keyboard_cancel, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
if field_type == bd_item.FieldType.photo:
dp.register_message_handler(FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = field_type), content_types = ['photo'], state = a_FSM.item_field)
dp.register_message_handler(FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = field_type), content_types = ['text'], state = a_FSM.item_field)

29
template/bd_item_select.py

@ -9,12 +9,15 @@ from template import simple_message, bd_item
from aiogram import types
def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_PrevPrefix, a_NextPrefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW):
def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW):
def GetBDItemsListKeyboardButtons(a_Message, a_UserGroups):
#if a_PrevPrefix:
parent_id = bd_item.GetKeyDataFromCallbackMessage(a_Message, a_PrevPrefix)
items = []
if a_ParentIDFieldName and parent_id and parent_id != '':
items = bd_item.GetBDItemsTemplate(a_TableName, a_ParentIDFieldName)(parent_id)
else:
items = bd_item.GetAllItemsTemplate(a_TableName)()
items = bd_item.GetAllItemsTemplate(a_TableName)()
items_button_list = []
for t in items:
bname, key_value, access = a_GetButtonNameAndKeyValueAndAccessFunc(t)
@ -25,7 +28,21 @@ def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_PrevPrefix, a_Nex
return keyboard.MakeInlineKeyboard(items_button_list, a_NextPrefix)
return GetBDItemsListKeyboardButtons
def SelectDBItemTemplate(a_TableName : str, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW):
keyborad_func = GetBDItemsListKeyboardButtonsTemplate(a_TableName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
def SelectDBItemTemplate(a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW):
keyborad_func = GetBDItemsListKeyboardButtonsTemplate(a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
return simple_message.InfoMessageTemplate(a_StartMessage, keyborad_func, a_AccessFunc, access_mode)
def FirstSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrefixBase}select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix
def NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ParentIDFieldName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrevPrefix}_select_{a_TableName}_{a_KeyName}_{a_ParentIDFieldName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, bd_iem.GetCheckForPrefixFunc(a_PrevPrefix))
return a_Prefix

28
template/bd_item_view.py

@ -5,36 +5,20 @@
from bot_sys import user_access, bot_bd, keyboard
from bot_modules import access, groups
from template import simple_message, bd_item_select, bd_item_delete
from template import simple_message, bd_item_select, bd_item_delete, bd_item
from aiogram import types
def ShowBDItemTemplate(a_TableName, a_KeyName, a_WorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
return bd_item_delete.DeleteBDItemTemplate(a_TableName, a_KeyName, a_WorkFunc, None, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, delete = False)
def ShowBDItemRegisterHandlers(dp, a_PrevPrefix, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode), bd_item.GetCheckForPrefixFunc(a_PrevPrefix))
def SelectAndShowBDItemRegisterHandlers(dp, a_ButtonName, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), lambda x: x.data.startswith(a_Prefix))
ShowBDItemRegisterHandlers(dp, a_Prefix, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode)
return sel_handler
def StartSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrefixBase}select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix
def NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW):
a_Prefix = f'{a_PrevPrefix}select_{a_TableName}_{a_KeyName}:'
sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode)
dp.register_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix
def ShowBDItemRegisterHandlers(dp, a_PrevPrefix, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW):
dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode), lambda x: x.data.startswith(a_PrevPrefix))

Loading…
Cancel
Save