|
|
|
@ -83,8 +83,8 @@ def MakeFSMForEdit(a_ModName, a_FieldName):
|
|
|
|
|
return _locals['fsm'] |
|
|
|
|
|
|
|
|
|
class TableOperateModule(mod_simple_message.SimpleMessageModule): |
|
|
|
|
def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): |
|
|
|
|
super().__init__(a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) |
|
|
|
|
def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): |
|
|
|
|
super().__init__(a_Messages, a_Buttons, a_InitAccess, a_DefInitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log) |
|
|
|
|
self.m_Table = a_Table |
|
|
|
|
self.m_EditModuleNameList = a_EditModuleNameList |
|
|
|
|
self.m_ChildModName = a_ChildModName |
|
|
|
@ -99,8 +99,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
return self.GetButtonNameAndKeyValueAndAccess(a_Item) |
|
|
|
|
self.m_GetButtonNameAndKeyValueAndAccessFunc = GetButtonNameAndKeyValueAndAccess |
|
|
|
|
|
|
|
|
|
async def PreDelete(a_CallbackQuery, a_Item): |
|
|
|
|
return await self.PreDelete(a_CallbackQuery, a_Item) |
|
|
|
|
async def PreDelete(a_CallbackQuery, a_Item, a_None): |
|
|
|
|
return await self.PreDelete(a_CallbackQuery, a_Item, a_None) |
|
|
|
|
self.m_PreDeleteFunc = PreDelete |
|
|
|
|
|
|
|
|
|
async def PostDelete(a_CallbackQuery, a_ItemID): |
|
|
|
@ -116,14 +116,21 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
self.m_Table.GetInitTableRequest(), |
|
|
|
|
] + super().GetInitBDCommands() |
|
|
|
|
|
|
|
|
|
def GetStartButtons(self, a_Message, a_UserGroups): |
|
|
|
|
return [ |
|
|
|
|
[ButtonNames.LIST, user_access.AccessMode.VIEW], |
|
|
|
|
[ButtonNames.ADD, user_access.AccessMode.ADD], |
|
|
|
|
[ButtonNames.DEL, user_access.AccessMode.DELETE], |
|
|
|
|
[ButtonNames.EDIT, user_access.AccessMode.EDIT], |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
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, 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()), |
|
|
|
|
] |
|
|
|
|
cur_buttons = [] |
|
|
|
|
for b in self.GetStartButtons(a_Message, a_UserGroups): |
|
|
|
|
bn = b[0] |
|
|
|
|
ba = b[1] |
|
|
|
|
cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(bn), ba, self.GetAccess())] |
|
|
|
|
return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) |
|
|
|
|
|
|
|
|
|
def GetAccessForEditKeyboardButtons(self, a_Field): |
|
|
|
@ -157,7 +164,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups) |
|
|
|
|
|
|
|
|
|
def GetButtonNameAndKeyValueAndAccess(self, a_Item): |
|
|
|
|
key_name_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY) |
|
|
|
|
key_name_id = self.GetKeyFieldID() |
|
|
|
|
name_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.NAME) |
|
|
|
|
access_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS) |
|
|
|
|
assert key_name_id != None |
|
|
|
@ -220,12 +227,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
msg = self.UpdateMessage(msg, lang, a_Item, a_EnablePhoto = a_EnablePhoto) |
|
|
|
|
item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] |
|
|
|
|
if Inline_keyboard_template_func: |
|
|
|
|
Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)]) |
|
|
|
|
Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.GetKeyFieldID()]) |
|
|
|
|
|
|
|
|
|
return simple_message.WorkFuncResult(msg, item_access = item_access, Inline_keyboard_func = Inline_keyboard_func) |
|
|
|
|
return ShowMessage |
|
|
|
|
|
|
|
|
|
async def PreDelete(self, a_CallbackQuery, a_Item): |
|
|
|
|
async def PreDelete(self, a_CallbackQuery, a_Item, a_None): |
|
|
|
|
if len(a_Item) < self.m_Table.GetFieldsCount(): |
|
|
|
|
return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND)) |
|
|
|
|
access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] |
|
|
|
@ -379,7 +386,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
return self.OnChange() |
|
|
|
|
|
|
|
|
|
table_name = self.m_Table.GetName() |
|
|
|
|
key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) |
|
|
|
|
key_name = self.GetKeyFieldName() |
|
|
|
|
edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc |
|
|
|
|
GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc |
|
|
|
|
GetAccess = self.m_GetAccessFunc |
|
|
|
@ -469,10 +476,19 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
f = fields[f_id] |
|
|
|
|
self.m_Bot.RegisterMessageHandler(bd_item_add.FinishAddBDItemTemplate(self.m_Bot, fsm, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, f.m_Name, self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_CREATE)), None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = GetFieldType(f)), content_types = GetContentTypes(f), state = getattr(fsm, f'item{f_id}')) |
|
|
|
|
|
|
|
|
|
def GetKeyFieldDestiny(self): |
|
|
|
|
return bd_table.TableFieldDestiny.KEY |
|
|
|
|
|
|
|
|
|
def GetKeyFieldName(self): |
|
|
|
|
return self.m_Table.GetFieldNameByDestiny(self.GetKeyFieldDestiny()) |
|
|
|
|
|
|
|
|
|
def GetKeyFieldID(self): |
|
|
|
|
return self.m_Table.GetFieldIDByDestiny(self.GetKeyFieldDestiny()) |
|
|
|
|
|
|
|
|
|
def RegisterHandlers(self): |
|
|
|
|
super().RegisterHandlers() |
|
|
|
|
table_name = self.m_Table.GetName() |
|
|
|
|
key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) |
|
|
|
|
key_name = self.GetKeyFieldName() |
|
|
|
|
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) |
|
|
|
@ -485,7 +501,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
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.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) |
|
|
|
|
parent_key_name = parent_mod.GetKeyFieldName() |
|
|
|
|
|
|
|
|
|
def GetViewItemInlineKeyboardTemplate(a_ItemID): |
|
|
|
|
return self.GetViewItemInlineKeyboardTemplate(a_ItemID) |
|
|
|
|