|
|
|
@ -51,6 +51,12 @@ class Messages(Enum):
|
|
|
|
|
SELECT_TO_DELETE = auto() |
|
|
|
|
SUCCESS_DELETE = auto() |
|
|
|
|
|
|
|
|
|
def GetCurItem(a_Bot, a_TableName, a_KeyName, a_KeyValue): |
|
|
|
|
items = bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_KeyName)(a_KeyValue) |
|
|
|
|
if len(items) == 1: |
|
|
|
|
return items[0] |
|
|
|
|
return None |
|
|
|
|
|
|
|
|
|
create_fsm_create_cmd = ''' |
|
|
|
|
class FSMCreate{a_ModName}(StatesGroup): |
|
|
|
|
{items} |
|
|
|
@ -253,6 +259,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
item_id = a_ItemID |
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, user_id) |
|
|
|
|
|
|
|
|
|
parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) |
|
|
|
|
|
|
|
|
|
if parent_id_field and a_ItemData[parent_id_field]: |
|
|
|
|
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT |
|
|
|
|
item_id = a_ItemData[parent_id_field] |
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, user_id) |
|
|
|
|
|
|
|
|
|
return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE)) |
|
|
|
|
|
|
|
|
|
async def AddBDItemFunc(self, a_ItemData, a_UserID): |
|
|
|
@ -296,10 +309,15 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
else: |
|
|
|
|
self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {request} {param}.') |
|
|
|
|
|
|
|
|
|
subscribe_type = bot_subscribes.SubscribeType.ADD |
|
|
|
|
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD |
|
|
|
|
item_id = -1 |
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, a_UserID) |
|
|
|
|
|
|
|
|
|
if parent_id_field and a_ItemData[parent_id_field]: |
|
|
|
|
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT |
|
|
|
|
item_id = a_ItemData[parent_id_field] |
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, a_UserID) |
|
|
|
|
|
|
|
|
|
return res, error |
|
|
|
|
|
|
|
|
|
async def SendSubscribe(self, a_Type, a_ItemID, a_OwnerUserID): |
|
|
|
@ -370,6 +388,18 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table_name = self.m_Table.GetName() |
|
|
|
|
key_name = self.GetKeyFieldName() |
|
|
|
|
|
|
|
|
|
cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_ItemID) |
|
|
|
|
print(cur_item) |
|
|
|
|
|
|
|
|
|
parent_id_field_index = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID) |
|
|
|
|
if parent_id_field_index and cur_item and cur_item[parent_id_field_index]: |
|
|
|
|
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT |
|
|
|
|
item_id = cur_item[parent_id_field_index] |
|
|
|
|
await self.SendSubscribe(subscribe_type, item_id, a_EditUserID) |
|
|
|
|
|
|
|
|
|
def RegisterEdit(self, a_Field, a_AccessMode = user_access.AccessMode.EDIT): |
|
|
|
|
a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny)) |
|
|
|
|
a_EditMessage = self.GetMessage(EditMessage(a_Field.m_Destiny)) |
|
|
|
@ -392,7 +422,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc |
|
|
|
|
GetAccess = self.m_GetAccessFunc |
|
|
|
|
|
|
|
|
|
a_Prefix = self.RegisterSelect(a_ButtonName, a_AccessMode, only_parent = True) |
|
|
|
|
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) |
|
|
|
|
|
|
|
|
|
bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ |
|
|
|
|
self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ |
|
|
|
@ -537,7 +567,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
|
|
|
|
|
# Удаление |
|
|
|
|
a_ButtonName = self.GetButton(ButtonNames.DEL) |
|
|
|
|
if a_ButtonName: |
|
|
|
|
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.DELETE) |
|
|
|
|
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW) |
|
|
|
|
bd_item_delete.DeleteBDItemRegisterHandlers(self.m_Bot, \ |
|
|
|
|
a_Prefix, \ |
|
|
|
|
table_name, \ |
|
|
|
@ -551,7 +581,7 @@ 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, only_parent = True) |
|
|
|
|
a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) |
|
|
|
|
|
|
|
|
|
check_func = bd_item.GetCheckForTextFunc(a_ButtonName) |
|
|
|
|
if a_Prefix: |
|
|
|
|