Browse Source

В проектах работает добавление, удаление и просмотр

pull/2/head
Alexei 2 years ago
parent
commit
74760c35f1
  1. 121
      bot_modules/mod_table_operate.py
  2. 2
      bot_modules/projects.py
  3. 15
      bot_sys/bd_table.py
  4. 11
      bot_sys/bot_bd.py
  5. 2
      bot_sys/keyboard.py
  6. 2
      main.py
  7. 6
      template/bd_item.py
  8. 4
      template/bd_item_add.py
  9. 7
      template/bd_item_delete.py
  10. 3
      template/bd_item_select.py

121
bot_modules/mod_table_operate.py

@ -3,7 +3,7 @@
# Модуль для редактирования и просмотра таблицы в БД
from bot_sys import keyboard, user_access, bd_table
from bot_sys import keyboard, user_access, bd_table, bot_bd
from bot_modules import access_utils, mod_simple_message
from template import simple_message, bd_item, bd_item_select, bd_item_view, bd_item_delete, bd_item_add, bd_item_edit
@ -75,15 +75,15 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
self.m_GetButtonNameAndKeyValueAndAccessFunc = GetButtonNameAndKeyValueAndAccess
async def PreDelete(a_CallbackQuery, a_Item):
return await self.PreDelete(a_Item)
return await self.PreDelete(a_CallbackQuery, a_Item)
self.m_PreDeleteFunc = PreDelete
async def PostDelete(a_CallbackQuery, a_ItemID):
return await self.PostDelete(a_Item)
return await self.PostDelete(a_CallbackQuery, a_ItemID)
self.m_PostDeleteFunc = PostDelete
def AddBDItemFunc(a_ItemData, a_UserID):
return self.AddBDItemFunc(a_Item)
return self.AddBDItemFunc(a_ItemData, a_UserID)
self.m_AddBDItemFunc = AddBDItemFunc
@ -101,20 +101,20 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def GetStartKeyboardButtons(self, a_Message, a_UserGroups):
mod_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups)
cur_buttons = [
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST), user_access.AccessMode.VIEW, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.ADD), user_access.AccessMode.ADD, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.DEL), user_access.AccessMode.DELETE, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT), user_access.AccessMode.EDIT, GetAccess())
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST), user_access.AccessMode.VIEW, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.ADD), user_access.AccessMode.ADD, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.DEL), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT), user_access.AccessMode.EDIT, self.GetAccess())
]
return mod_buttons + keyboard.MakeButtons(cur_buttons, a_UserGroups)
def GetEditKeyboardButtons(self, a_Message, a_UserGroups):
mod_buttons = self.GetButtons(self.m_EditModuleNameList)
cur_buttons = [
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_PHOTO), user_access.AccessMode.VIEW, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_NAME), user_access.AccessMode.ADD, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.EDIT, GetAccess())
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_PHOTO), user_access.AccessMode.VIEW, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_NAME), user_access.AccessMode.ADD, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess())
]
return mod_buttons + keyboard.MakeButtons(cur_buttons, a_UserGroups)
@ -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, GetAccess(), user_access.AccessMode.VIEW),
keyboard.InlineButton(child_mod.GetButton(ButtonNames.LIST), child_mod.GetSelectPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW),
]
return keyboard.MakeInlineKeyboardButtons(cur_buttons, a_UserGroups)
@ -141,19 +141,22 @@ 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_MessageName : Messages, keyboard_template_func = None):
def ShowMessageTemplate(self, a_Message, keyboard_template_func = None):
async def ShowMessage(a_CallbackQuery, a_Item):
msg = a_Message.StaticCopy()
# TODO: добавить поддержку языка в a_MessageName
keyboard_func = None
item_access = None
if a_Item:
if len(a_Item) < self.m_Table.GetFieldsCount():
return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND))
msg = self.GetMessage(a_MessageName).StaticCopy()
msg.UpdateDesc(table.ReplaceAllFieldTags(msg.GetDesc(), a_Item))
msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item))
msg.UpdatePhotoID(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO)])
keyboard_func = None
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)])
return simple_message.WorkFuncResult(msg, item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)], keyboard_func = keyboard_func)
return simple_message.WorkFuncResult(msg, item_access = item_access, keyboard_func = keyboard_func)
return ShowMessage
# TODO: delete?
@ -168,23 +171,29 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)]
return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE), None, item_access = access)
async def TaskPostDelete(self, a_CallbackQuery, a_ItemID):
async def PostDelete(self, a_CallbackQuery, a_ItemID):
self.m_Log.Success(f'Задача №{a_ItemID} была удалена пользователем {a_CallbackQuery.from_user.id}.')
#TODO: удалить вложенные
return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE))
def AddBDItemFunc(self, a_ItemData, a_UserID):
table_name = self.m_Table.GetName()
name_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.NAME)
photo_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.PHOTO)
desc_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.DESC)
access_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.ACCESS)
create_datetime_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.CREATE_DATE)
parent_id_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME)
photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO)
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
access_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ACCESS)
create_datetime_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.CREATE_DATE)
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
res, error = None, None
def_access = access_utils.GetItemDefaultAccessForModule(self.m_Bot, self.GetName())
#TODO сделать список полей, чтобы запрос генерировался автоматически.
if parent_id_field:
res, error = self.m_Bot.SQLRequest(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], def_access + f";{a_UserID}=+", a_ItemData[parent_id_field]))
else:
res, error = self.m_Bot.SQLRequest(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], def_access + f";{a_UserID}=+"))
if error:
self.m_Log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).')
@ -193,27 +202,30 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
return res, error
def RegisterSelect(self, a_ButtonName, access_mode):
def RegisterSelect(self, a_ButtonName, access_mode, only_parent = False):
a_Prefix = None
if self.m_ParentModName:
parent_mod = self.GetModule(self.m_ParentModName)
a_Prefix = parent_mod.RegisterSelect(a_ButtonName, access_mode)
if not only_parent:
a_Prefix = bd_item_select.NextSelectBDItemRegisterHandlers(self.m_Bot, \
a_Prefix, \
self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.PARENT_ID), \
self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID), \
self.m_Table.GetName(), \
self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.KEY), \
self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY), \
self.m_GetButtonNameAndKeyValueAndAccessFunc, \
self.GetMessage(Messages.SELECT), \
self.m_GetAccessFunc,\
access_mode = access_mode\
)
else:
if not only_parent:
a_PrefixBase = a_ButtonName.GetDesc()
a_Prefix = bd_item_select.FirstSelectBDItemRegisterHandlers(self.m_Bot, \
a_PrefixBase, \
a_ButtonName, \
self.m_Table.GetName(), \
self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.KEY), \
self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY), \
self.m_GetButtonNameAndKeyValueAndAccessFunc, \
self.GetMessage(Messages.SELECT), \
self.m_GetAccessFunc,\
@ -224,24 +236,22 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
def RegisterHandlers(self):
super().RegisterHandlers()
table_name = self.m_Table.GetName()
key_name = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.KEY)
name_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.NAME)
desc_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.DESC)
photo_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.PHOTO)
access_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.ACCESS)
parent_id_field = self.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY)
name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME)
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO)
access_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ACCESS)
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)
parent_table_name = None
parent_key_name = None
if self.m_ParentModName:
parent_mod = self.GetModule(self.m_ParentModName)
parent_table_name = parent_mod.m_Table.GetName()
parent_key_name = parent_mod.m_Table.GetFieldByDestiny(bd_table.TableFieldDestiny.KEY)
parent_key_name = parent_mod.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY)
def GetViewItemInlineKeyboardTemplate(a_ItemID):
def GetViewItemInlineKeyboard(a_ItemID):
return self.GetViewItemInlineKeyboardTemplate(a_ItemID)
return GetViewItemInlineKeyboard
GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc
GetAccess = self.m_GetAccessFunc
@ -251,7 +261,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
# Список
a_ButtonName = self.GetButton(ButtonNames.LIST)
if a_ButtonName:
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW)
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True)
if a_Prefix:
bd_item_view.LastSelectAndShowBDItemRegisterHandlers(self.m_Bot, \
a_Prefix,\
parent_id_field, \
@ -264,6 +275,17 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
defaul_keyboard_func, \
access_mode = user_access.AccessMode.VIEW\
)
else:
bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(self.m_Bot, \
a_ButtonName, \
table_name, \
key_name, \
self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate), \
GetButtonNameAndKeyValueAndAccess, \
self.GetMessage(Messages.SELECT), \
GetAccess, \
defaul_keyboard_func\
)
self.m_SelectPrefix = a_Prefix
# Удаление
@ -272,14 +294,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.DELETE)
bd_item_delete.DeleteBDItemRegisterHandlers(self.m_Bot, \
a_Prefix, \
bd_item.GetCheckForPrefixFunc(a_Prefix), \
table_name, \
key_name, \
parent_id_field, \
self.m_PreDeleteFunc, \
self.m_PostDeleteFunc, \
GetButtonNameAndKeyValueAndAccess, \
self.GetMessage(Messages.SELECT), \
GetAccess, \
defaul_keyboard_func\
)
@ -287,9 +305,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
# Добавление
a_ButtonName = self.GetButton(ButtonNames.ADD)
if a_ButtonName:
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.ADD)
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.ADD, only_parent = True)
check_func = bd_item.GetCheckForTextFunc(a_ButtonName)
if a_Prefix:
check_func = bd_item.GetCheckForPrefixFunc(a_Prefix)
bd_item_add.AddBDItem3RegisterHandlers(self.m_Bot, \
bd_item.GetCheckForPrefixFunc(a_Prefix), \
check_func, \
self.m_FSMs.m_FSMCreate, \
self.m_FSMs.m_FSMCreate.name,\
self.m_FSMs.m_FSMCreate.desc, \
@ -309,7 +330,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
GetAccess, \
self.m_GetStartKeyboardButtonsFunc\
)
'''
# Редактирование
edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc
def RegisterEdit(a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT):
@ -351,3 +372,5 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.m_FSMs.m_FSMEditDesc, self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text)
RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.m_FSMs.m_FSMEditPhoto, self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo)
RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.m_FSMs.m_FSMEditAccess, self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text)
'''

2
bot_modules/projects.py

@ -147,7 +147,7 @@ class ModuleProjects(mod_table_operate.TableOperateModule):
def GetModuleButtons(self):
return super().GetModuleButtons() + [
keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST), user_access.AccessMode.VIEW, self.GetAccess()),
keyboard.ButtonWithAccess(self.GetButton(mod_table_operate.ButtonNames.LIST), user_access.AccessMode.VIEW, self.GetAccess()),
]

15
bot_sys/bd_table.py

@ -38,7 +38,7 @@ class Table:
return self.TableFieldType
def GetFieldsCount(self):
return len(self.TableFieldType)
return len(self.m_Fields)
def GetFieldByDestiny(self, a_Destiny):
for f in self.m_Fields:
@ -46,6 +46,12 @@ class Table:
return f
return None
def GetFieldNameByDestiny(self, a_Destiny):
f = self.GetFieldByDestiny(a_Destiny)
if f:
return f.m_Name
return None
def GetFieldIDByDestiny(self, a_Destiny):
for i in range(len(self.m_Fields)):
f = self.m_Fields[i]
@ -78,23 +84,28 @@ def Test():
])
assert table.GetName() == 'tname'
assert table.GetFieldByDestiny(TableFieldDestiny.KEY).m_Name == 'f1'
assert table.GetFieldNameByDestiny(TableFieldDestiny.KEY) == 'f1'
assert table.GetFieldByDestiny(TableFieldDestiny.KEY).m_Destiny == TableFieldDestiny.KEY
assert table.GetFieldByDestiny(TableFieldDestiny.KEY).m_Type == TableFieldType.INT
assert table.GetFieldIDByDestiny(TableFieldDestiny.KEY) == 0
assert table.GetFieldByDestiny(TableFieldDestiny.NAME).m_Name == 'f2'
assert table.GetFieldNameByDestiny(TableFieldDestiny.NAME) == 'f2'
assert table.GetFieldByDestiny(TableFieldDestiny.NAME).m_Destiny == TableFieldDestiny.NAME
assert table.GetFieldByDestiny(TableFieldDestiny.NAME).m_Type == TableFieldType.STR
assert table.GetFieldIDByDestiny(TableFieldDestiny.NAME) == 1
assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Name == 'f3'
assert table.GetFieldNameByDestiny(TableFieldDestiny.DESC) == 'f3'
assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Destiny == TableFieldDestiny.DESC
assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Type == TableFieldType.STR
assert table.GetFieldIDByDestiny(TableFieldDestiny.DESC) == 2
assert table.GetFieldByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldIDByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldNameByDestiny(TableFieldDestiny.PHOTO) == None
assert table.GetFieldsCount() == 3
assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT , f3 TEXT );'
item = [10, 'i1', 'i2']
print( table.ReplaceAllFieldTags('#f1 #f2 #f3', item))
assert table.ReplaceAllFieldTags('#f1 #f2 #f3', item) == '10 i1 i2'

11
bot_sys/bot_bd.py

@ -19,18 +19,11 @@ def GetBDFileName():
def GetBDDateTimeNow():
return 'datetime(\'now\')'
def BDExecute(a_Commands):
for cmd in a_Commands:
SQLRequestToBD(cmd, commit = True)
def SelectBDTemplate(a_TableName):
def SelectBDTemplate(a_Bot, a_TableName):
def SelectBD():
return SQLRequestToBD(f'SELECT * FROM {a_TableName}')
return a_Bot.SQLRequest(f'SELECT * FROM {a_TableName}')
return SelectBD
def SQLRequestToBD(a_Request : str, commit = False, return_error = False, param = None):
return SQLRequest(GetBDFileName(), a_Request, commit = commit, return_error = return_error, param = param)
def RequestsExecute(a_BDFileName, a_Commands):
for cmd in a_Commands:
SQLRequest(a_BDFileName, cmd, commit = True)

2
bot_sys/keyboard.py

@ -75,7 +75,7 @@ def MakeAiogramInlineKeyboard(a_ButtonList : [InlineButton]):
r = []
for b in row:
r += [types.InlineKeyboardButton(text = str(b.label), callback_data = b.callback_data)]
buttons += r
buttons += [r]
inline_keyboard = InlineKeyboardMarkup(inline_keyboard=buttons)
return inline_keyboard

2
main.py

@ -38,7 +38,7 @@ 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]
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)
g_ModuleAgregator.AddModule(mod_project)

6
template/bd_item.py

@ -47,7 +47,7 @@ def GetCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
cur_buttons = [
keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()),
]
return keyboard.MakeInlineKeyboardButtons(cur_buttons, a_UserGroups)
return keyboard.MakeButtons(cur_buttons, a_UserGroups)
return GetCancelKeyboardButtons
def GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
@ -56,7 +56,7 @@ def GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, a_AccessMode):
keyboard.ButtonWithAccess(skip_button_name, a_AccessMode, a_AccessFunc()),
keyboard.ButtonWithAccess(canсel_button_name, a_AccessMode, a_AccessFunc()),
]
return keyboard.MakeInlineKeyboardButtons(cur_buttons, a_UserGroups)
return keyboard.MakeButtons(cur_buttons, a_UserGroups)
return GetSkipAndCancelKeyboardButtons
def GetAllItemsTemplate(a_Bot, a_TableName):
@ -91,7 +91,7 @@ def CheckAccessBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_KeyValue, a_WorkF
return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(msg)), None
result_work_func = await a_WorkFunc(a_CallbackQuery, item[0])
if result_work_func is None or result_work_func.string_message is None:
if result_work_func is None or result_work_func.m_BotMessage is None:
return result_work_func, result_work_func
if not result_work_func.item_access is None and not user_access.CheckAccessString(result_work_func.item_access, user_groups, a_AccessMode):

4
template/bd_item_add.py

@ -14,7 +14,7 @@ cancel_message = '''
def StartAddBDItemTemplate(a_Bot, 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, state):
user_id = str(a_CallbackQuery.from_user.id)
user_groups = groups.GetUserGroupData(a_Bot, user_id)
user_groups = groups_utils.GetUserGroupData(a_Bot, user_id)
parent_id = bd_item.GetKeyDataFromCallbackMessage(a_CallbackQuery, a_Prefix)
res_of_work_func = None
check = None
@ -50,7 +50,7 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa
else:
state_func = a_FSM.next
user_id = str(a_Message.from_user.id)
user_groups = groups.GetUserGroupData(a_Bot, user_id)
user_groups = groups_utils.GetUserGroupData(a_Bot, user_id)
error = None
res_of_work_func = None
check = None

7
template/bd_item_delete.py

@ -10,7 +10,7 @@ from template import simple_message, bd_item_select, bd_item
def DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, delete = True, access_mode = user_access.AccessMode.DELETE):
async def DeleteBDItem(a_CallbackQuery, state = None):
user_id = str(a_CallbackQuery.from_user.id)
user_groups = groups.GetUserGroupData(a_Bot, user_id)
user_groups = groups_utils.GetUserGroupData(a_Bot, user_id)
item_id = str(a_CallbackQuery.data).replace(a_Prefix, '')
check, res_of_pre_del = await bd_item.CheckAccessBDItemTemplate(a_Bot, a_TableName, a_KeyName, item_id, a_PreDeleteWorkFunc, access_mode)(a_CallbackQuery)
@ -29,7 +29,7 @@ def DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_P
return simple_message.SimpleMessageTemplate(a_Bot, DeleteBDItem, a_ButtonFunc, None, a_AccessFunc, access_mode)
def DeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_StartCheckFunc, a_TableName : str, a_KeyName, a_ParentIDFieldName,a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE):
def SelectAndDeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_StartCheckFunc, a_TableName : str, a_KeyName, a_ParentIDFieldName,a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE):
reg_func = a_Bot.RegisterMessageHandler
if a_ParentIDFieldName:
reg_func = a_Bot.RegisterCallbackHandler
@ -39,3 +39,6 @@ def DeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_StartCheckFunc, a_TableN
reg_func(sel_handler, a_StartCheckFunc)
a_Bot.RegisterCallbackHandler(DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix))
def DeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_TableName : str, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE):
a_Bot.RegisterCallbackHandler(DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_PrevPrefix))

3
template/bd_item_select.py

@ -23,13 +23,14 @@ 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, keyboard_func, None, a_AccessFunc, access_mode)
return simple_message.InfoMessageTemplate(a_Bot, a_StartMessage, None, 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):

Loading…
Cancel
Save