Browse Source

Исправлено множество мелких багов и список задач

test_bot
Alexei 2 years ago
parent
commit
4659fc2312
  1. 2
      bot_modules/access.py
  2. 7
      bot_modules/projects.py
  3. 8
      bot_modules/tasks.py
  4. 2
      bot_sys/keyboard.py
  5. 2
      template/bd_item.py
  6. 29
      template/bd_item_add.py
  7. 4
      template/bd_item_edit.py
  8. 22
      template/bd_item_select.py
  9. 1
      template/simple_message.py

2
bot_modules/access.py

@ -17,12 +17,10 @@ class FSMRequestToBDAccess(StatesGroup):
class FSMEditAccessItem(StatesGroup): class FSMEditAccessItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
class FSMEditDefaultAccessItem(StatesGroup): class FSMEditDefaultAccessItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
# --------------------------------------------------------- # ---------------------------------------------------------
# БД # БД

7
bot_modules/projects.py

@ -20,19 +20,15 @@ class FSMCreateProject(StatesGroup):
photo = State() photo = State()
class FSMEditPhotoItem(StatesGroup): class FSMEditPhotoItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
class FSMEditNameItem(StatesGroup): class FSMEditNameItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
class FSMEditDeskItem(StatesGroup): class FSMEditDeskItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
class FSMEditAccessItem(StatesGroup): class FSMEditAccessItem(StatesGroup):
item_id = State()
item_field = State() item_field = State()
# --------------------------------------------------------- # ---------------------------------------------------------
# БД # БД
@ -216,7 +212,7 @@ def ShowMessageTemplate(a_StringMessage):
return ShowMessage return ShowMessage
def SimpleMessageTemplate(a_StringMessage): def SimpleMessageTemplate(a_StringMessage):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery): async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
return simple_message.WorkFuncResult(a_StringMessage) return simple_message.WorkFuncResult(a_StringMessage)
return ShowMessage return ShowMessage
@ -281,6 +277,7 @@ def RegisterHandlers(dp : Dispatcher):
SimpleMessageTemplate(project_create_desc_message), \ SimpleMessageTemplate(project_create_desc_message), \
SimpleMessageTemplate(project_create_photo_message), \ SimpleMessageTemplate(project_create_photo_message), \
SimpleMessageTemplate(project_success_create_message), \ SimpleMessageTemplate(project_success_create_message), \
None,\
None, \ None, \
None, \ None, \
name_field, \ name_field, \

8
bot_modules/tasks.py

@ -215,7 +215,7 @@ def ShowMessageTemplate(a_StringMessage):
return ShowMessage return ShowMessage
def SimpleMessageTemplate(a_StringMessage): def SimpleMessageTemplate(a_StringMessage):
async def ShowMessage(a_CallbackQuery : types.CallbackQuery): async def ShowMessage(a_CallbackQuery : types.CallbackQuery, a_Item):
return simple_message.WorkFuncResult(a_StringMessage) return simple_message.WorkFuncResult(a_StringMessage)
return ShowMessage return ShowMessage
@ -236,7 +236,7 @@ async def TaskPostDelete(a_CallbackQuery : types.CallbackQuery, a_ItemID):
def AddBDItemFunc(a_ItemData, a_UserID): 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()})', 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[desc_field])) 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: 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)}).') log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {access.GetItemDefaultAccessForModule(module_name)}).')
@ -264,7 +264,8 @@ def RegisterHandlers(dp : Dispatcher):
defaul_keyboard_func = GetStartTaskKeyboardButtons defaul_keyboard_func = GetStartTaskKeyboardButtons
# Стартовое сообщение # Стартовое сообщение
dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name) dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name)
# Список задач projects.
# Список задач
a_Prefix, sel_handler = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, 'view_task', list_task_button_name, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = user_access.AccessMode.VIEW) a_Prefix, sel_handler = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, 'view_task', list_task_button_name, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = user_access.AccessMode.VIEW)
bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, a_Prefix, parent_id_field, table_name, key_name, ShowMessageTemplate(task_open_message), GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func, access_mode = user_access.AccessMode.VIEW) bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, a_Prefix, parent_id_field, table_name, key_name, ShowMessageTemplate(task_open_message), GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func, access_mode = user_access.AccessMode.VIEW)
@ -287,6 +288,7 @@ def RegisterHandlers(dp : Dispatcher):
SimpleMessageTemplate(task_create_desc_message), \ SimpleMessageTemplate(task_create_desc_message), \
SimpleMessageTemplate(task_create_photo_message), \ SimpleMessageTemplate(task_create_photo_message), \
SimpleMessageTemplate(task_success_create_message), \ SimpleMessageTemplate(task_success_create_message), \
a_Prefix,\
projects.table_name, \ projects.table_name, \
projects.key_name, \ projects.key_name, \
name_field, \ name_field, \

2
bot_sys/keyboard.py

@ -46,7 +46,7 @@ def MakeKeyboardForMods(a_ModList, a_UserGroups):
class Button: class Button:
def __init__(self, a_Label, a_CallBackData): def __init__(self, a_Label, a_CallBackData):
self.label = a_Label self.label = a_Label
self.callback_data = a_CallBackData self.callback_data = str(a_CallBackData)
def MakeInlineKeyboard(a_ButtonList : [Button], a_CallBackPrefix : str): def MakeInlineKeyboard(a_ButtonList : [Button], a_CallBackPrefix : str):
buttons = [] buttons = []

2
template/bd_item.py

@ -34,7 +34,7 @@ def GetCheckForTextFunc(a_Text):
def GetKeyDataFromCallbackMessage(a_Message, a_Prefix): def GetKeyDataFromCallbackMessage(a_Message, a_Prefix):
key_item_id = None key_item_id = None
if hasattr(a_Message, 'data'): if a_Prefix and hasattr(a_Message, 'data'):
key_item_id = str(a_Message.data).replace(a_Prefix, '') key_item_id = str(a_Message.data).replace(a_Prefix, '')
return key_item_id return key_item_id

29
template/bd_item_add.py

@ -16,8 +16,6 @@ cancel_message = '''
🚫 Добавление отменено 🚫 Добавление отменено
''' '''
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.ADD): 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.ADD):
async def StartAddBDItem(a_CallbackQuery : types.CallbackQuery, state : FSMContext): async def StartAddBDItem(a_CallbackQuery : types.CallbackQuery, state : FSMContext):
user_id = str(a_CallbackQuery.from_user.id) user_id = str(a_CallbackQuery.from_user.id)
@ -28,19 +26,18 @@ def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_ParentTableName,
await a_FSMStart.set() await a_FSMStart.set()
async with state.proxy() as item_data: async with state.proxy() as item_data:
item_data[parent_id_field_name] = parent_id if a_ParentKeyFieldName:
item_data[a_ParentKeyFieldName] = parent_id
if parent_id: if parent_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery) check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery)
else: else:
res_of_work_func = await a_MessageFunc(a_CallbackQuery) res_of_work_func = await a_MessageFunc(a_CallbackQuery, None)
if not check is None: if not check is None:
await state.finish() await state.finish()
check.keyboard_func = a_FinishButtonFunc check.keyboard_func = a_FinishButtonFunc
return check return check
if parent_id:
await a_FSM.next()
return res_of_work_func return res_of_work_func
return simple_message.SimpleMessageTemplate(StartAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) return simple_message.SimpleMessageTemplate(StartAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode)
@ -65,13 +62,15 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P
async with state.proxy() as item_data: async with state.proxy() as item_data:
if a_Message.text == bd_item.canсel_button_name: if a_Message.text == bd_item.canсel_button_name:
await state.finish() await state.finish()
return simple_message.WorkFuncResult(cancel_message, keyborad_func = a_FinishButtonFunc) return simple_message.WorkFuncResult(cancel_message, keyboard_func = a_FinishButtonFunc)
parent_id = item_data[parent_id_field_name] parent_id = None
if a_ParentKeyFieldName:
parent_id = item_data[a_ParentKeyFieldName]
if parent_id: if parent_id:
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message) check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message)
else: else:
res_of_work_func = await a_MessageFunc(a_Message) res_of_work_func = await a_MessageFunc(a_Message, None)
if not check is None: if not check is None:
await state_func() await state_func()
@ -84,7 +83,7 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P
else: else:
if a_Message.photo == None or len(a_Message.photo) == 0: if a_Message.photo == None or len(a_Message.photo) == 0:
await state.finish() await state.finish()
return simple_message.WorkFuncResult(error_photo_type_message, keyborad_func = a_FinishButtonFunc) return simple_message.WorkFuncResult(error_photo_type_message, keyboard_func = a_FinishButtonFunc)
field_value = a_Message.photo[0].file_id field_value = a_Message.photo[0].file_id
else: else:
field_value = a_Message.text field_value = a_Message.text
@ -98,14 +97,14 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P
return simple_message.SimpleMessageTemplate(FinishAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) return simple_message.SimpleMessageTemplate(FinishAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode)
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): def AddBDItem3RegisterHandlers(dp, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_AddBDItemFunc, a_AddNameMessageFunc, a_AddDescMessageFunc, a_AddPhotoMessageFunc, a_FinishMessageFunc, a_ParentPrefix, 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_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode)
a_Prefix = f'add_{a_ParentTableName}_{a_ParentKeyFieldName}_{a_NameField}_{a_DescField}_{a_PhotoField}:' reg_func = dp.register_message_handler
if a_ParentTableName: if a_ParentTableName:
dp.register_callback_query_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) reg_func = dp.register_callback_query_handler
else: reg_func(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc)
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_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(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, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto) dp.register_message_handler(FinishAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto)

4
template/bd_item_edit.py

@ -20,11 +20,11 @@ error_photo_type_message = '''
''' '''
def StartEditBDItemTemplate(a_FSM, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT): def StartEditBDItemTemplate(a_FSM, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT):
return bd_item_add.StartAddBDItemTemplate(a_FSM, a_FSM.item_id, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode) return bd_item_add.StartAddBDItemTemplate(a_FSM, a_FSM.item_field, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode)
def FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): def FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text):
def EditBDItemFunc(a_ItemData, a_UserID): def EditBDItemFunc(a_ItemData, a_UserID):
item_id = a_ItemData[bd_item_add.parent_id_field_name] item_id = a_ItemData[a_KeyName]
field_value = a_ItemData[a_FieldName] field_value = a_ItemData[a_FieldName]
res, error = bd_item.EditBDItemInTableTemplate(a_TableName, a_KeyName, a_FieldName)(item_id, field_value) res, error = bd_item.EditBDItemInTableTemplate(a_TableName, a_KeyName, a_FieldName)(item_id, field_value)
if error: if error:

22
template/bd_item_select.py

@ -18,30 +18,42 @@ def GetBDItemsListKeyboardButtonsTemplate(a_TableName : str, a_ParentIDFieldName
else: else:
items = bd_item.GetAllItemsTemplate(a_TableName)() items = bd_item.GetAllItemsTemplate(a_TableName)()
print('GetBDItemsListKeyboardButtons', parent_id, a_PrevPrefix, a_ParentIDFieldName, "\n", items)
items_button_list = [] items_button_list = []
for t in items: for t in items:
print('GetBDItemsListKeyboardButtons items', t)
bname, key_value, access = a_GetButtonNameAndKeyValueAndAccessFunc(t) bname, key_value, access = a_GetButtonNameAndKeyValueAndAccessFunc(t)
if access is None: if access is None:
access = '' access = ''
if not bname is None and user_access.CheckAccessString(access, a_UserGroups, access_mode): if not bname is None and user_access.CheckAccessString(access, a_UserGroups, access_mode):
items_button_list += [keyboard.Button(bname, key_value)] b = keyboard.Button(bname, key_value)
print(bname, key_value, b)
items_button_list += [b]
print(items_button_list)
return keyboard.MakeInlineKeyboard(items_button_list, a_NextPrefix) return keyboard.MakeInlineKeyboard(items_button_list, a_NextPrefix)
return GetBDItemsListKeyboardButtons return GetBDItemsListKeyboardButtons
def SelectDBItemTemplate(a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW): 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) keyboard_func = GetBDItemsListKeyboardButtonsTemplate(a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc)
return simple_message.InfoMessageTemplate(a_StartMessage, keyborad_func, a_AccessFunc, access_mode) return simple_message.InfoMessageTemplate(a_StartMessage, keyboard_func, a_AccessFunc, access_mode)
def hash_str(a_Str):
summ = 0
for i in a_Str:
summ += ord(i)
return f'{summ}:'
def FirstSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): 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}:' a_Prefix = hash_str(f'first_select_{a_TableName}_{a_KeyName}_in_base_{a_PrefixBase}:')
sel_handler = SelectDBItemTemplate(a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode) sel_handler = 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_message_handler(sel_handler, text = a_ButtonName)
return a_Prefix, sel_handler return a_Prefix, sel_handler
def NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ParentIDFieldName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): 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}:' a_Prefix = f'next_select_{a_TableName}_{a_KeyName}_{a_ParentIDFieldName}_after_prefix_{a_PrevPrefix}:'
sel_handler = SelectDBItemTemplate(a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode) sel_handler = SelectDBItemTemplate(a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode)
dp.register_callback_query_handler(sel_handler, bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) dp.register_callback_query_handler(sel_handler, bd_item.GetCheckForPrefixFunc(a_PrevPrefix))

1
template/simple_message.py

@ -49,6 +49,7 @@ def SimpleMessageTemplate(a_WorkFunc, a_GetButtonsFunc, a_AccessFunc, access_mod
return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = keyboard_func(a_Message, user_groups)) return await bot.send_message(a_Message.from_user.id, access.access_denied_message, reply_markup = keyboard_func(a_Message, user_groups))
if photo_id is None or photo_id == 0 or photo_id == '0': if photo_id is None or photo_id == 0 or photo_id == '0':
print(keyboard_func)
return await bot.send_message(a_Message.from_user.id, msg, reply_markup = keyboard_func(a_Message, user_groups)) return await bot.send_message(a_Message.from_user.id, msg, reply_markup = keyboard_func(a_Message, user_groups))
await bot.send_photo(user_id, photo_id, msg, reply_markup = keyboard_func(a_Message, user_groups)) await bot.send_photo(user_id, photo_id, msg, reply_markup = keyboard_func(a_Message, user_groups))

Loading…
Cancel
Save