diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index ae6c11a..47d22c0 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -289,11 +289,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL item_id = -1 - await self.SendSubscribe(subscribe_type, item_id, user_id) + await self.SendSubscribe(subscribe_type, item_id, user_id, item_id) subscribe_type = bot_subscribes.SubscribeType.ITEM_DEL item_id = a_ItemID - await self.SendSubscribe(subscribe_type, item_id, user_id) + await self.SendSubscribe(subscribe_type, item_id, user_id, item_id) table_name = self.m_Table.GetName() key_name = self.GetKeyFieldName() @@ -304,12 +304,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): if parent_id_field_index and cur_item and cur_item[parent_id_field_index]: subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT item_id = cur_item[parent_id_field_index] - await self.SendSubscribe(subscribe_type, item_id, user_id) + await self.SendSubscribe(subscribe_type, item_id, user_id, item_id) return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE)) async def AddBDItemFunc(self, a_ItemData, a_UserID): table_name = self.m_Table.GetName() + key_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) 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) @@ -339,8 +340,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): values += ['?'] param += (a_ItemData[n], ) - request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})' - print('request', request, param) + request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)}) RETURNING {key_field}' + #print('request', request, param) res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param) self.OnChange() @@ -349,14 +350,19 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): else: self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {request} {param}.') + table_item_id = -1 + if not error and res and len(res) == 1 and len(res[0]) == 1: + table_item_id = str(res[0][0]) + #print('res_id', res, error, table_item_id) + subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD item_id = -1 - await self.SendSubscribe(subscribe_type, item_id, a_UserID) + await self.SendSubscribe(subscribe_type, item_id, a_UserID, table_item_id) 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) + await self.SendSubscribe(subscribe_type, item_id, a_UserID, table_item_id) return res, error @@ -365,17 +371,17 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_MessageFromUSer = None user_groups = groups_utils.GetUserGroupData(self.m_Bot, a_UserID) try: - print('SendMessage', self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode) + #print('SendMessage', self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode) await simple_message.SendMessage(self.m_Bot, a_Message, a_GetButtonsFunc, a_GetInlineButtonsFunc, a_UserID, a_MessageFromUSer, user_groups, parse_mode=parse_mode) return True except: return False - async def SendSubscribe(self, a_Type, a_ItemID, a_OwnerUserID): + async def SendSubscribe(self, a_Type, a_ItemID, a_OwnerUserID, a_TableItem): table_name = self.m_Table.GetName() key_name = self.GetKeyFieldName() - cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_ItemID) + cur_item = GetCurItem(self.m_Bot, table_name, key_name, a_TableItem) for s_user_id in self.m_BotSubscribes.GetUserIDs(self.GetName(), a_Type, a_ItemID = a_ItemID): a_BotMessage = self.GetMessage(SubscribeMessage(a_Type)) if not a_BotMessage: @@ -435,12 +441,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID): subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT item_id = -1 - await self.SendSubscribe(subscribe_type, item_id, a_EditUserID) + await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID) subscribe_type = bot_subscribes.SubscribeType.ITEM_EDIT item_id = a_ItemID - await self.SendSubscribe(subscribe_type, item_id, a_EditUserID) - + await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID) table_name = self.m_Table.GetName() key_name = self.GetKeyFieldName() @@ -452,7 +457,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): 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) + await self.SendSubscribe(subscribe_type, item_id, a_EditUserID, a_ItemID) def RegisterEdit(self, a_Field, a_AccessMode = user_access.AccessMode.EDIT): a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny))