From 961bdcb3cf641a9dbe469ca389969245813ca37c Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Wed, 29 Nov 2023 22:46:30 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D1=80=D1=8B=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=20#21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/all_orders.py | 1 + bot_modules/mod_table_operate.py | 21 ++++++++++++++++++--- bot_modules/orders.py | 10 ++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py index b56bd0b..4aabf51 100644 --- a/bot_modules/all_orders.py +++ b/bot_modules/all_orders.py @@ -32,6 +32,7 @@ button_names.pop(mod_table_operate.ButtonNames.ADD) cur_button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Все заказы", + mod_table_operate.ButtonNames.SHOW: "☐ Открыть заказ", mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", orders.ButtonNames.LIST_ALL: "📃 Список всех заказов", ButtonNames.SHOW_USER_INFO: "👤 Информация о пользователе", diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index fcc011f..03df9fb 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -35,6 +35,7 @@ def SubscribeMessage(a_EnumItem): return 'subscribe ' + str(a_EnumItem) class ButtonNames(Enum): + SHOW = auto() LIST = auto() ADD = auto() EDIT = auto() @@ -153,6 +154,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), access, self.GetAccess()),] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) + def GetShowItemInlineKeyboardTemplate(self, a_ItemID): + def GetShowItemInlineKeyboard(a_Message, a_UserGroups): + return self.GetShowItemInlineKeyboard(a_Message, a_UserGroups, a_ItemID) + return GetShowItemInlineKeyboard + def GetViewItemInlineKeyboardTemplate(self, a_ItemID): def GetViewItemInlineKeyboard(a_Message, a_UserGroups): return self.GetViewItemInlineKeyboard(a_Message, a_UserGroups, a_ItemID) @@ -170,6 +176,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def GetShowPrefix(self): return self.m_ShowPrefix + def GetShowItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID): + cur_buttons = [ + keyboard.InlineButtonWithAccess(self.GetButton(ButtonNames.SHOW), self.GetShowPrefix(), a_ItemID, self.GetAccess(), user_access.AccessMode.VIEW), + ] + return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups) + def GetViewItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID): if not self.m_ChildModName: return None @@ -385,18 +397,21 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): 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)) + #print('s_user_id', s_user_id, a_BotMessage, a_OwnerUserID, a_TableItem, cur_item) if not a_BotMessage: continue if s_user_id == a_OwnerUserID: continue a_UserID = s_user_id a_BotMessage = a_BotMessage.StaticCopy() - a_BotMessage.UpdateDesc(a_BotMessage.GetDesc().replace("#item_id", str(a_ItemID))) + a_BotMessage.UpdateDesc(a_BotMessage.GetDesc().replace("#item_id", str(a_TableItem))) + + inline_keyboard_func = None if cur_item: a_BotMessage.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_BotMessage.GetDesc(), cur_item)) + inline_keyboard_func = self.GetShowItemInlineKeyboardTemplate(a_TableItem) - - await self.SendMessageToUser(a_BotMessage, a_UserID) + await self.SendMessageToUser(a_BotMessage, a_UserID, a_GetInlineButtonsFunc = inline_keyboard_func) def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 745ab5c..84f28d7 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -59,6 +59,7 @@ class ButtonNames(Enum): button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Заказы", + mod_table_operate.ButtonNames.SHOW: "☐ Открыть заказ", mod_table_operate.ButtonNames.LIST: "📃 Список моих текущих заказов", ButtonNames.LIST_ALL: "📃 Список всех моих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", @@ -294,3 +295,12 @@ class ModuleUserOrders(ModuleOrders): def GetName(self): return module_name + + def GetShowItemInlineKeyboard(self, a_Message, a_UserGroups, a_ItemID): + all_orders_mod = self.GetModule('all_orders') + if not all_orders_mod: + return None + cur_buttons = [ + keyboard.InlineButtonWithAccess(all_orders_mod.GetButton(mod_table_operate.ButtonNames.SHOW), all_orders_mod.GetShowPrefix(), a_ItemID, all_orders_mod.GetAccess(), user_access.AccessMode.VIEW), + ] + return keyboard.MakeInlineKeyboardButtons(self.m_Bot, cur_buttons, a_UserGroups)