Browse Source

Правки в заказах #21

Исправлены оповещения о новых заказах и об изменениях в заказах
master
parent
commit
56f86e491c
  1. 33
      bot_modules/mod_table_operate.py

33
bot_modules/mod_table_operate.py

@ -289,11 +289,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL
item_id = -1 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 subscribe_type = bot_subscribes.SubscribeType.ITEM_DEL
item_id = a_ItemID 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() table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName() 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]: 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 subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_DEL_WITH_PARENT
item_id = cur_item[parent_id_field_index] 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)) return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE))
async def AddBDItemFunc(self, a_ItemData, a_UserID): async def AddBDItemFunc(self, a_ItemData, a_UserID):
table_name = self.m_Table.GetName() 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) name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME)
photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO) photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO)
desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC) desc_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.DESC)
@ -339,8 +340,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
values += ['?'] values += ['?']
param += (a_ItemData[n], ) param += (a_ItemData[n], )
request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})' request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)}) RETURNING {key_field}'
print('request', request, param) #print('request', request, param)
res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param) res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param)
self.OnChange() self.OnChange()
@ -349,14 +350,19 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
else: else:
self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {request} {param}.') 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 subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD
item_id = -1 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]: if parent_id_field and a_ItemData[parent_id_field]:
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_ADD_WITH_PARENT
item_id = a_ItemData[parent_id_field] 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 return res, error
@ -365,17 +371,17 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule):
a_MessageFromUSer = None a_MessageFromUSer = None
user_groups = groups_utils.GetUserGroupData(self.m_Bot, a_UserID) user_groups = groups_utils.GetUserGroupData(self.m_Bot, a_UserID)
try: 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) 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 return True
except: except:
return False 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() table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName() 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): for s_user_id in self.m_BotSubscribes.GetUserIDs(self.GetName(), a_Type, a_ItemID = a_ItemID):
a_BotMessage = self.GetMessage(SubscribeMessage(a_Type)) a_BotMessage = self.GetMessage(SubscribeMessage(a_Type))
if not a_BotMessage: 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): async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID):
subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT
item_id = -1 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 subscribe_type = bot_subscribes.SubscribeType.ITEM_EDIT
item_id = a_ItemID 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() table_name = self.m_Table.GetName()
key_name = self.GetKeyFieldName() 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]: 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 subscribe_type = bot_subscribes.SubscribeType.ANY_ITEM_EDIT_WITH_PARENT
item_id = cur_item[parent_id_field_index] 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): def RegisterEdit(self, a_Field, a_AccessMode = user_access.AccessMode.EDIT):
a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny)) a_ButtonName = self.GetButton(EditButton(a_Field.m_Destiny))

Loading…
Cancel
Save