diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 9bc3946..1f0bcfb 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -239,15 +239,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.OnChange() if error: - self.m_Log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') + self.m_Log.Error(f'Пользователь {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') else: - self.m_Log.Success(f'Пользоватлель {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') + self.m_Log.Success(f'Пользователь {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[photo_field]}, {a_ItemData[name_field]}, {a_ItemData[desc_field]}, {def_access}).') return res, error - def SelectItemsTemplate(self): - return bd_item_select.GetBDItemsTemplate(self.m_Bot, self.m_Table.GetName(), self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID)) - def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) return bd_item_select.DBItemSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 836c59f..bc59059 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -5,6 +5,7 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message +from template import bd_item_select from enum import Enum from enum import auto @@ -55,7 +56,7 @@ class Messages(Enum): EDIT_ADDRESS = auto() button_names = { - mod_simple_message.ButtonNames.START: "👨‍👨‍👧‍👦 🛒 Заказы", + mod_simple_message.ButtonNames.START: "‍🛒 Заказы", mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", ButtonNames.LIST_ALL: "📃 Список всех заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", @@ -150,12 +151,29 @@ messages = { mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''', } -class ModuleProjects(mod_table_operate.TableOperateModule): +def GetBDItemsForUserTemplate(a_GetItemsFunc): + def GetBDItems(a_Message, a_UserGroups, a_ParentID): + def GetBDItem(a_KeyValue): + user_id = str(a_Message.from_user.id) + return a_GetItemsFunc(a_Message, a_UserGroups, a_ParentID)(user_id) + return GetBDItem + + return items + return GetBDItems + +class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): + def GetItemsFunc(self): + return GetBDItemsForUserTemplate(super().GetItemsFunc()) + +class ModuleOrders(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): super().__init__(table, messages, button_names, a_ParentModName, a_ChildModName, init_access, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def GetName(self): return module_name + def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): + parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) diff --git a/main.py b/main.py index 86c6f2e..e0defa3 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import os from bot_sys import config, log, aiogram_bot, bot_messages, bd_table, user_access from bot_modules import mod_agregator, start, profile, backup, users_groups_agregator, access, projects, tasks, needs, comments from bot_modules import languages, messages, buttons, users, groups, user_in_groups +from bot_modules import orders log_start_message = 'Бот успешно запущен!' @@ -34,6 +35,7 @@ mod_buttons_name = buttons.module_name mod_users_name = users.module_name mod_groups_name = groups.module_name mod_user_in_groups_name = user_in_groups.module_name +mod_orders_name = orders.module_name start_mod_list = [mod_start_name] mod_access = access.ModuleAccess(start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) @@ -87,6 +89,10 @@ child_mod_name_list = [mod_start_name] mod_buttons = buttons.ModuleButtons(mod_languages_name, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) g_ModuleAgregator.AddModule(mod_buttons) +child_mod_name_list = [mod_start_name] +mod_orders = orders.ModuleOrders(None, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) +g_ModuleAgregator.AddModule(mod_orders) + child_mod_name_list = [ mod_profile.GetName(), mod_backup.GetName(), @@ -94,6 +100,7 @@ child_mod_name_list = [ mod_access.GetName(), mod_project.GetName(), mod_languages.GetName(), + mod_orders.GetName(), ] mod_start = start.ModuleStart(child_mod_name_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) g_ModuleAgregator.AddModule(mod_start) diff --git a/template/bd_item_select.py b/template/bd_item_select.py index 9e87e7b..de6bea8 100644 --- a/template/bd_item_select.py +++ b/template/bd_item_select.py @@ -61,7 +61,7 @@ class ISelectSource(ABC): def GetPrefixBase(self): pass -class DBItemSelectSource: +class DBItemSelectSource(ISelectSource): def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName): self.m_Bot = a_Bot self.m_TableName = a_TableName