From 82b15597bc89b95e7112c73bd5310dfb155d3381 Mon Sep 17 00:00:00 2001 From: Alexei Date: Sat, 27 May 2023 16:34:55 +0300 Subject: [PATCH 01/15] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 81 ++++++++------------ bot_modules/orders.py | 161 +++++++++++++++++++++++++++++++++++++++ bot_sys/bd_table.py | 2 + template/bd_item_delete.py | 10 --- template/bd_item_edit.py | 11 +-- template/bd_item_select.py | 89 +++++++++++++++++----- template/bd_item_view.py | 10 +-- 7 files changed, 270 insertions(+), 94 deletions(-) create mode 100644 bot_modules/orders.py diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index a0cfb86..c6ae5a5 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -245,35 +245,28 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): 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 DBItemSelectSource(self.m_Bot, self.m_TableName.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) + def RegisterSelect(self, a_ButtonName, access_mode, only_parent = False): a_Prefix = None if self.m_ParentModName: parent_mod = self.GetModule(self.m_ParentModName) a_Prefix = parent_mod.RegisterSelect(a_ButtonName, access_mode, only_parent = False) - if not only_parent: - a_Prefix = bd_item_select.NextSelectBDItemRegisterHandlers(self.m_Bot, \ - a_Prefix, \ - self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID), \ - self.m_Table.GetName(), \ - self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY), \ - self.m_GetButtonNameAndKeyValueAndAccessFunc, \ - self.GetMessage(Messages.SELECT), \ - self.m_GetAccessFunc,\ - access_mode = access_mode\ - ) - else: - if not only_parent: - a_PrefixBase = a_ButtonName.GetDesc() - a_Prefix = bd_item_select.FirstSelectBDItemRegisterHandlers(self.m_Bot, \ - a_PrefixBase, \ - a_ButtonName, \ - self.m_Table.GetName(), \ - self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY), \ + + if not only_parent: + a_Prefix = bd_item_select.SelectRegisterHandlers(self.m_Bot, \ + self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ self.m_GetButtonNameAndKeyValueAndAccessFunc, \ self.GetMessage(Messages.SELECT), \ self.m_GetAccessFunc,\ access_mode = access_mode\ ) + return a_Prefix def RegisterHandlers(self): @@ -306,30 +299,23 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_ButtonName = self.GetButton(ButtonNames.LIST) if a_ButtonName: a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) - if a_Prefix: - bd_item_view.LastSelectAndShowBDItemRegisterHandlers(self.m_Bot, \ - a_Prefix,\ - parent_id_field, \ - table_name,\ - key_name, \ - self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate), \ - GetButtonNameAndKeyValueAndAccess, \ - self.GetMessage(Messages.SELECT), \ - GetAccess, \ - defaul_keyboard_func, \ - access_mode = user_access.AccessMode.VIEW\ - ) - else: - bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(self.m_Bot, \ - a_ButtonName, \ - table_name, \ - key_name, \ - self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate), \ - GetButtonNameAndKeyValueAndAccess, \ - self.GetMessage(Messages.SELECT), \ - GetAccess, \ - defaul_keyboard_func\ - ) + + a_Prefix = bd_item_select.SelectRegisterHandlers(self.m_Bot,\ + self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ + a_GetButtonNameAndKeyValueAndAccessFunc,\ + self.GetMessage(Messages.SELECT),\ + GetAccess,\ + access_mode = user_access.AccessMode.VIEW\ + ) + bd_item_view.ShowBDItemRegisterHandlers(self.m_Bot,\ + a_Prefix,\ + table_name,\ + key_name,\ + self.ShowMessageTemplate(self.GetMessage(Messages.OPEN),GetViewItemInlineKeyboardTemplate),\ + GetAccess,\ + defaul_keyboard_func,\ + access_mode = user_access.AccessMode.VIEW\ + ) self.m_SelectPrefix = a_Prefix # Удаление @@ -387,20 +373,15 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return self.OnChange() a_Prefix = self.RegisterSelect(a_ButtonName, a_AccessMode, only_parent = True) - check_func = bd_item.GetCheckForTextFunc(a_ButtonName) - if a_Prefix: - check_func = bd_item.GetCheckForPrefixFunc(a_Prefix) - #print(a_ButtonName, a_Prefix, check_func) + bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ - a_Prefix, \ + self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ a_FSM, \ - check_func, \ self.GetMessage(Messages.SELECT_TO_EDIT), \ self.ShowMessageTemplate(a_EditMessage), \ self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_EDIT)), \ table_name, \ key_name, \ - parent_id_field, \ a_FieldName, \ GetButtonNameAndKeyValueAndAccess, \ GetAccess, \ diff --git a/bot_modules/orders.py b/bot_modules/orders.py new file mode 100644 index 0000000..836c59f --- /dev/null +++ b/bot_modules/orders.py @@ -0,0 +1,161 @@ +# -*- coding: utf8 -*- +# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) + +# Заказы + +from bot_sys import bot_bd, keyboard, user_access, bd_table +from bot_modules import mod_table_operate, mod_simple_message + +from enum import Enum +from enum import auto + +class OrderStatus(Enum): + NEW = auto() + PAY = auto() + ADDRESS = auto() + FINISH = auto() + +# --------------------------------------------------------- +# БД +module_name = 'orders' + +table_name = module_name +key_name = 'orderID' +name_field = 'orderName' +desc_field = 'orderDesc' +photo_field = 'orderPhoto' +status_field = 'orderStatus' +address_field = 'orderAddres' +access_field = 'orderAccess' +create_datetime_field = 'orderCreateDateTime' +parent_id_field = 'userID' + +table = bd_table.Table(table_name, [ + bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), + bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), + bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.STR), + bd_table.TableField(address_field, bd_table.TableFieldDestiny.ADDRESS, bd_table.TableFieldType.STR), + bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), + bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), + bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), + ]) + +init_access = f'{user_access.user_access_group_new}=va' + +# --------------------------------------------------------- +# Сообщения и кнопки + +class ButtonNames(Enum): + LIST_ALL = auto() + EDIT_ADDRESS = auto() + +class Messages(Enum): + EDIT_ADDRESS = auto() + +button_names = { + mod_simple_message.ButtonNames.START: "👨‍👨‍👧‍👦 🛒 Заказы", + mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", + ButtonNames.LIST_ALL: "📃 Список всех заказов", + mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", + mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", + mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в заказе", + mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в заказе", + mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в заказе", + mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к заказу", + mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", +} + +messages = { + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} + +''', + mod_table_operate.Messages.SELECT: ''' +Пожалуйста, выберите заказ: +''', + mod_table_operate.Messages.ERROR_FIND: ''' +❌ Ошибка, заказ не найден +''', + mod_table_operate.Messages.OPEN: f''' +Заказ: #{name_field} + +#{desc_field} + +Статус:#{status_field} + +Адрес доставки:#{address_field} + +Время создания: #{create_datetime_field} +''', + mod_table_operate.Messages.CREATE_NAME: ''' +Создание заказа. Шаг №1 + +Введите название заказа: +''', + mod_table_operate.Messages.CREATE_DESC: ''' +Создание заказа. Шаг №2 + +Введите описание заказа: +''', + mod_table_operate.Messages.CREATE_PHOTO: ''' +Создание заказа. Шаг №3 + +Загрузите обложку для заказа (Фото): +Она будет отображаться в его описании. +''', + mod_table_operate.Messages.SUCCESS_CREATE: '''✅ Заказ успешно добавлен!''', + mod_table_operate.Messages.START_EDIT: ''' +Пожалуйста, выберите действие: +''', + mod_table_operate.Messages.SELECT_TO_EDIT: ''' +Выберите заказ, который вы хотите отредактировать. +''', + mod_table_operate.Messages.EDIT_PHOTO: ''' +Загрузите новую обложку для заказа (Фото): +Она будет отображаться в его описании. +''', + mod_table_operate.Messages.EDIT_NAME: f''' +Текущее название заказа: +#{name_field} + +Введите новое название заказа: +''', + mod_table_operate.Messages.EDIT_DESC: f''' +Текущее описание заказа: +#{desc_field} + +Введите новое описание заказа: +''', + Messages.EDIT_ADDRESS: f''' +Текущий адрес заказа: +#{desc_field} + +Введите новый адрес доставки заказа (укажите, кто, когда и где его сможет забрать): +''', + mod_table_operate.Messages.EDIT_ACCESS: f''' +Текущий доступ к заказу: +#{access_field} + +{user_access.user_access_readme} + +Введите новую строку доступа: +''', + mod_table_operate.Messages.SUCCESS_EDIT: '''✅ Заказ успешно отредактирован!''', + mod_table_operate.Messages.SELECT_TO_DELETE: ''' +Выберите заказ, который вы хотите удалить. +Все задачи и потребности в этом заказе так же будут удалены! +''', + mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''', +} + +class ModuleProjects(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 + + + diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index aaacb4f..26eaaab 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -19,6 +19,8 @@ class TableFieldDestiny(Enum): DEFAULT_ACCESS = auto() CREATE_DATE = auto() PARENT_ID = auto() + STATUS = auto() + ADDRESS = auto() OTHER = auto() class TableField: diff --git a/template/bd_item_delete.py b/template/bd_item_delete.py index 7c7a355..51345ec 100644 --- a/template/bd_item_delete.py +++ b/template/bd_item_delete.py @@ -29,16 +29,6 @@ def DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_P return simple_message.SimpleMessageTemplate(a_Bot, DeleteBDItem, a_ButtonFunc, None, a_AccessFunc, access_mode) -def SelectAndDeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_StartCheckFunc, a_TableName : str, a_KeyName, a_ParentIDFieldName,a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE): - reg_func = a_Bot.RegisterMessageHandler - if a_ParentIDFieldName: - reg_func = a_Bot.RegisterCallbackHandler - - a_Prefix = bd_item.HashPrefix(f'delete_{a_TableName}_{a_KeyName}:') - sel_handler = bd_item_select.SelectDBItemTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode) - reg_func(sel_handler, a_StartCheckFunc) - a_Bot.RegisterCallbackHandler(DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) - def DeleteBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_TableName : str, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.DELETE): a_Bot.RegisterCallbackHandler(DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_PreDeleteWorkFunc, a_PostDeleteWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index a665349..a443b3d 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -33,15 +33,12 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type) -def EditBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_FSM, a_StartCheckFunc, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_ParentIDFieldName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): - reg_func = a_Bot.RegisterMessageHandler - if a_ParentIDFieldName: - reg_func = a_Bot.RegisterCallbackHandler - +def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode) a_Prefix = bd_item.HashPrefix(f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:') - sel_handler = bd_item_select.SelectDBItemTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode) - reg_func(sel_handler, a_StartCheckFunc) + + SelectCustomRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) + a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) if field_type == bd_item.FieldType.photo: a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field) diff --git a/template/bd_item_select.py b/template/bd_item_select.py index 2e199bd..50151b6 100644 --- a/template/bd_item_select.py +++ b/template/bd_item_select.py @@ -7,14 +7,12 @@ from bot_sys import user_access, bot_bd, keyboard from bot_modules import access_utils, groups_utils from template import simple_message, bd_item -def GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName : str, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW): +from abc import ABC, abstractmethod + +def GetCustomListKeyboardButtonsTemplate(a_Bot, a_GetItemsFunc, a_PrevPrefix, a_NextPrefix : str, a_GetButtonNameAndKeyValueAndAccessFunc, access_mode = user_access.AccessMode.VIEW): def GetBDItemsListKeyboardButtons(a_Message, a_UserGroups): parent_id = bd_item.GetKeyDataFromCallbackMessage(a_Message, a_PrevPrefix) - items = [] - if a_ParentIDFieldName and parent_id and parent_id != '': - items = bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_ParentIDFieldName)(parent_id) - else: - items = bd_item.GetAllItemsTemplate(a_Bot, a_TableName)() + items = a_GetItemsFunc(a_Message, a_UserGroups, parent_id) items_button_list = [] for t in items: @@ -27,23 +25,78 @@ def GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName : str, a_ParentIDFi return keyboard.MakeInlineKeyboardButtons(a_Bot, items_button_list, a_UserGroups) return GetBDItemsListKeyboardButtons -def SelectDBItemTemplate(a_Bot, a_TableName : str, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW): - inline_keyboard_func = GetBDItemsListKeyboardButtonsTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc) +def GetBDItemsTemplate(a_Bot, a_TableName : str, a_ParentIDFieldName): + def GetBDItems(a_Message, a_UserGroups, a_ParentID): + items = [] + if a_ParentIDFieldName and a_ParentID and a_ParentID != '': + items = bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_ParentIDFieldName)(a_ParentID) + else: + items = bd_item.GetAllItemsTemplate(a_Bot, a_TableName)() + + return items + return GetBDItems + +def SelectCustomTemplate(a_Bot, a_GetItemsFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_NextPrefix, access_mode = user_access.AccessMode.VIEW): + inline_keyboard_func = GetCustomListKeyboardButtonsTemplate(a_Bot, a_GetItemsFunc, a_PrevPrefix, a_NextPrefix, a_GetButtonNameAndKeyValueAndAccessFunc) return simple_message.InfoMessageTemplate(a_Bot, a_StartMessage, None, inline_keyboard_func, a_AccessFunc, access_mode) -def FirstSelectBDItemRegisterHandlers(a_Bot, a_PrefixBase, a_ButtonName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): +class ISelectSource(ABC): + @abstractmethod + def IsFirst(self): + pass + + @abstractmethod + def GetItemsFunc(self): + pass + + @abstractmethod + def GetCheckFunc(self): + pass + + @abstractmethod + def GetPrevPrefix(self): + pass + + @abstractmethod + def GetPrefixBase(self): + pass + +class DBItemSelectSource: + def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName): + self.a_Bot = a_Bot + self.a_TableName = a_TableName + self.a_ParentIDFieldName = a_ParentIDFieldName + self.a_PrevPrefix = a_PrevPrefix + self.a_ButtonName = a_ButtonName + + def IsFirst(self): + return not self.a_ParentIDFieldName + + def GetItemsFunc(self): + return GetBDItemsTemplate(self.a_Bot, self.a_TableName, self.a_ParentIDFieldName) + + def GetCheckFunc(self): + if self.IsFirst(): + return bd_item.GetCheckForTextFunc(a_ButtonName) + return bd_item.GetCheckForPrefixFunc(a_PrevPrefix) + + def GetPrevPrefix(self): + return self.a_PrevPrefix - a_Prefix = bd_item.HashPrefix(f'first_select_{a_TableName}_{a_KeyName}_in_base_{a_PrefixBase}:') + def GetPrefixBase(self): + if self.a_PrevPrefix: + return self.a_PrevPrefix + return self.a_ButtonName - sel_handler = SelectDBItemTemplate(a_Bot, a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode) - a_Bot.RegisterMessageHandler(sel_handler, bd_item.GetCheckForTextFunc(a_ButtonName)) +def SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): + reg_func = a_Bot.RegisterMessageHandler + if not a_SelectSource.IsFirst(): + reg_func = a_Bot.RegisterCallbackHandler - return a_Prefix + a_NextPrefix = bd_item.HashPrefix(f'select_{a_SelectSource}_after_prefix_or_in_base_{a_SelectSource.GetPrefixBase()}:') -def NextSelectBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_ParentIDFieldName, a_TableName : str, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): - a_Prefix = bd_item.HashPrefix(f'next_select_{a_TableName}_{a_KeyName}_{a_ParentIDFieldName}_after_prefix_{a_PrevPrefix}:') + sel_handler = SelectCustomTemplate(a_Bot, a_SelectSource.GetItemsFunc(), a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_SelectSource.GetPrevPrefix(), a_NextPrefix, access_mode = access_mode) + reg_func(sel_handler, a_SelectSource.GetCheckFunc()) - sel_handler = SelectDBItemTemplate(a_Bot, a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode) - a_Bot.RegisterCallbackHandler(sel_handler, bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) + return a_NextPrefix - return a_Prefix diff --git a/template/bd_item_view.py b/template/bd_item_view.py index e40b06f..6513d41 100644 --- a/template/bd_item_view.py +++ b/template/bd_item_view.py @@ -5,18 +5,10 @@ from bot_sys import user_access, bot_bd, keyboard from bot_modules import access_utils, groups_utils -from template import simple_message, bd_item_select, bd_item_delete, bd_item +from template import simple_message, bd_item_delete, bd_item def ShowBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_WorkFunc, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW): return bd_item_delete.DeleteBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_WorkFunc, None, a_Prefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, delete = False) def ShowBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW): a_Bot.RegisterCallbackHandler(ShowBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode), bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) - -def FirstSelectAndShowBDItemRegisterHandlers(a_Bot, a_ButtonName, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW): - a_Prefix = bd_item_select.FirstSelectBDItemRegisterHandlers(a_Bot, '', a_ButtonName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) - ShowBDItemRegisterHandlers(a_Bot, a_Prefix, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode) - -def LastSelectAndShowBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_ParentIDFieldName, a_TableName : str, a_KeyName, a_ShowItemWorkFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.VIEW): - a_Prefix = bd_item_select.NextSelectBDItemRegisterHandlers(a_Bot, a_PrevPrefix, a_ParentIDFieldName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) - ShowBDItemRegisterHandlers(a_Bot, a_Prefix, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode) -- 2.11.0 From d9cfb97626e68ebf088999c0ef50630e139de9e0 Mon Sep 17 00:00:00 2001 From: Alexei Date: Sat, 27 May 2023 20:46:36 +0300 Subject: [PATCH 02/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8E=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2=20=D0=B8=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=81=D0=BC=D0=BE=D1=82=D1=80=D0=B5=20=D0=B4=D0=BE=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=BD=D1=8B=D1=85=20=D0=BF=D1=80=D0=BE=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 7 +++---- template/bd_item_edit.py | 3 +-- template/bd_item_select.py | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index c6ae5a5..9bc3946 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -250,7 +250,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) - return DBItemSelectSource(self.m_Bot, self.m_TableName.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) + return bd_item_select.DBItemSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) def RegisterSelect(self, a_ButtonName, access_mode, only_parent = False): a_Prefix = None @@ -299,10 +299,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_ButtonName = self.GetButton(ButtonNames.LIST) if a_ButtonName: a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) - + self.m_SelectPrefix = a_Prefix a_Prefix = bd_item_select.SelectRegisterHandlers(self.m_Bot,\ self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ - a_GetButtonNameAndKeyValueAndAccessFunc,\ + GetButtonNameAndKeyValueAndAccess,\ self.GetMessage(Messages.SELECT),\ GetAccess,\ access_mode = user_access.AccessMode.VIEW\ @@ -316,7 +316,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): defaul_keyboard_func,\ access_mode = user_access.AccessMode.VIEW\ ) - self.m_SelectPrefix = a_Prefix # Удаление a_ButtonName = self.GetButton(ButtonNames.DEL) diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index a443b3d..01cfafd 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -35,9 +35,8 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode) - a_Prefix = bd_item.HashPrefix(f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:') - SelectCustomRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) + a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) if field_type == bd_item.FieldType.photo: diff --git a/template/bd_item_select.py b/template/bd_item_select.py index 50151b6..9e87e7b 100644 --- a/template/bd_item_select.py +++ b/template/bd_item_select.py @@ -63,30 +63,30 @@ class ISelectSource(ABC): class DBItemSelectSource: def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName): - self.a_Bot = a_Bot - self.a_TableName = a_TableName - self.a_ParentIDFieldName = a_ParentIDFieldName - self.a_PrevPrefix = a_PrevPrefix - self.a_ButtonName = a_ButtonName + self.m_Bot = a_Bot + self.m_TableName = a_TableName + self.m_ParentIDFieldName = a_ParentIDFieldName + self.m_PrevPrefix = a_PrevPrefix + self.m_ButtonName = a_ButtonName def IsFirst(self): - return not self.a_ParentIDFieldName + return not self.m_ParentIDFieldName def GetItemsFunc(self): - return GetBDItemsTemplate(self.a_Bot, self.a_TableName, self.a_ParentIDFieldName) + return GetBDItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName) def GetCheckFunc(self): if self.IsFirst(): - return bd_item.GetCheckForTextFunc(a_ButtonName) - return bd_item.GetCheckForPrefixFunc(a_PrevPrefix) + return bd_item.GetCheckForTextFunc(self.m_ButtonName) + return bd_item.GetCheckForPrefixFunc(self.m_PrevPrefix) def GetPrevPrefix(self): - return self.a_PrevPrefix + return self.m_PrevPrefix def GetPrefixBase(self): - if self.a_PrevPrefix: - return self.a_PrevPrefix - return self.a_ButtonName + if self.m_PrevPrefix: + return self.m_PrevPrefix + return self.m_ButtonName def SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = user_access.AccessMode.VIEW): reg_func = a_Bot.RegisterMessageHandler -- 2.11.0 From 28e549de67e208e2aadd0d0c4989a6e7486b49c5 Mon Sep 17 00:00:00 2001 From: Alexei Date: Sat, 27 May 2023 22:16:25 +0300 Subject: [PATCH 03/15] =?UTF-8?q?=D0=92=D0=BA=D0=BB=D1=8E=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D1=8B.=20=D0=9D?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 7 ++----- bot_modules/orders.py | 22 ++++++++++++++++++++-- main.py | 7 +++++++ template/bd_item_select.py | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) 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 -- 2.11.0 From 166f5ce98252f35358499251133cc56d7a68810e Mon Sep 17 00:00:00 2001 From: Alexei Date: Sun, 28 May 2023 10:00:44 +0300 Subject: [PATCH 04/15] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 80 ++++++++++++++++++++++++---------------- bot_modules/orders.py | 78 ++++++++++++++++++++++++++++++++++----- template/bd_item_add.py | 3 ++ 3 files changed, 119 insertions(+), 42 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 1f0bcfb..9dff4db 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -22,6 +22,7 @@ class ButtonNames(Enum): EDIT_DESC = auto() EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() + EDIT_ADDRESS = auto() DEL = auto() class Messages(Enum): @@ -39,6 +40,7 @@ class Messages(Enum): EDIT_DESC = auto() EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() + EDIT_ADDRESS = auto() SUCCESS_EDIT = auto() SELECT_TO_DELETE = auto() SUCCESS_DELETE = auto() @@ -49,7 +51,8 @@ class FSMs(Enum): EDIT_NAME = auto() EDIT_DESC = auto() EDIT_ACCESS = auto() - EDIT_DEFAULT_ACCESS = auto() + EDIT_DEFAULT_ACCESS = auto() + EDIT_ADDRESS = auto() create_fsms_cmd = ''' class FSMCreate{a_ModName}(StatesGroup): @@ -72,6 +75,9 @@ class FSMEdit{a_ModName}AccessItem(StatesGroup): class FSMEdit{a_ModName}DefaultAccessItem(StatesGroup): item_field = State() +class FSMEdit{a_ModName}AddressItem(StatesGroup): + item_field = State() + fsm = { FSMs.CREATE: FSMCreate{a_ModName}, FSMs.EDIT_NAME: FSMEdit{a_ModName}NameItem, @@ -79,6 +85,7 @@ fsm = { FSMs.EDIT_PHOTO: FSMEdit{a_ModName}PhotoItem, FSMs.EDIT_ACCESS: FSMEdit{a_ModName}AccessItem, FSMs.EDIT_DEFAULT_ACCESS: FSMEdit{a_ModName}DefaultAccessItem, + FSMs.EDIT_ADDRESS: FSMEdit{a_ModName}AddressItem, } ''' @@ -266,6 +273,38 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix + def RegisterEdit(self, a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): + if not a_ButtonName: + return + + def OnChange(): + return self.OnChange() + + table_name = self.m_Table.GetName() + key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc + GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc + GetAccess = self.m_GetAccessFunc + + a_Prefix = self.RegisterSelect(a_ButtonName, a_AccessMode, only_parent = True) + + bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ + self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ + a_FSM, \ + self.GetMessage(Messages.SELECT_TO_EDIT), \ + self.ShowMessageTemplate(a_EditMessage), \ + self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_EDIT)), \ + table_name, \ + key_name, \ + a_FieldName, \ + GetButtonNameAndKeyValueAndAccess, \ + GetAccess, \ + edit_keyboard_func, \ + OnChange,\ + access_mode = a_AccessMode, \ + field_type = a_FieldType\ + ) + def RegisterHandlers(self): super().RegisterHandlers() table_name = self.m_Table.GetName() @@ -361,32 +400,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): # Редактирование edit_keyboard_func = self.m_GetEditKeyboardButtonsFunc - def RegisterEdit(a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): - if not a_ButtonName: - return - - def OnChange(): - return self.OnChange() - - a_Prefix = self.RegisterSelect(a_ButtonName, a_AccessMode, only_parent = True) - - bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ - self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ - a_FSM, \ - self.GetMessage(Messages.SELECT_TO_EDIT), \ - self.ShowMessageTemplate(a_EditMessage), \ - self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_EDIT)), \ - table_name, \ - key_name, \ - a_FieldName, \ - GetButtonNameAndKeyValueAndAccess, \ - GetAccess, \ - edit_keyboard_func, \ - OnChange,\ - access_mode = a_AccessMode, \ - field_type = a_FieldType\ - ) - a_ButtonName = self.GetButton(ButtonNames.EDIT) if a_ButtonName: self.m_Bot.RegisterMessageHandler(\ @@ -400,11 +413,14 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): bd_item.GetCheckForTextFunc(a_ButtonName)\ ) - RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) - RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) - RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetFSM(FSMs.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) - RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) - RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) + address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS) + + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetFSM(FSMs.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetFSM(FSMs.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text) def OnChange(self): pass diff --git a/bot_modules/orders.py b/bot_modules/orders.py index bc59059..74a7e7d 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -5,7 +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 template import bd_item_select, bd_item_view from enum import Enum from enum import auto @@ -49,21 +49,18 @@ init_access = f'{user_access.user_access_group_new}=va' # Сообщения и кнопки class ButtonNames(Enum): - LIST_ALL = auto() - EDIT_ADDRESS = auto() - -class Messages(Enum): - EDIT_ADDRESS = auto() + LIST_CURRENT = auto() button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Заказы", - mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", - ButtonNames.LIST_ALL: "📃 Список всех заказов", + mod_table_operate.ButtonNames.LIST: "📃 Список всех заказов", + ButtonNames.LIST_CURRENT: "📃 Список текущих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в заказе", mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в заказе", mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в заказе", + mod_table_operate.ButtonNames.EDIT_ADDRESS: "𝌴 Изменить адрес в заказе", mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к заказу", mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", } @@ -129,7 +126,7 @@ messages = { Введите новое описание заказа: ''', - Messages.EDIT_ADDRESS: f''' + mod_table_operate.Messages.EDIT_ADDRESS: f''' Текущий адрес заказа: #{desc_field} @@ -151,6 +148,11 @@ messages = { mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''', } +def GetCurItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName, a_StatusFieldName): + def GetBDItem(a_KeyValue): + return a_Bot.SQLRequest(f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?', param = ([a_KeyValue, OrderStatus.FINISH])) + return GetBDItem + def GetBDItemsForUserTemplate(a_GetItemsFunc): def GetBDItems(a_Message, a_UserGroups, a_ParentID): def GetBDItem(a_KeyValue): @@ -162,8 +164,15 @@ def GetBDItemsForUserTemplate(a_GetItemsFunc): return GetBDItems class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): + def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurent = False): + super().__init__(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName) + self.m_OnlyCurent = a_OnlyCurent + def GetItemsFunc(self): - return GetBDItemsForUserTemplate(super().GetItemsFunc()) + get_items_func = super().GetItemsFunc() + if self.m_OnlyCurent: + get_items_func = GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field) + return GetBDItemsForUserTemplate(get_items_func) 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): @@ -176,4 +185,53 @@ class ModuleOrders(mod_table_operate.TableOperateModule): 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) + def SelectSourceForCurrentTemplate(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, a_OnlyCurent = True) + + def AddBDItemFunc(self, a_ItemData, a_UserID): + parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) + a_ItemData[parent_id_field] = a_UserID + return super().AddBDItemFunc(a_ItemData, a_UserID) + + def GetStartKeyboardButtons(self, a_Message, a_UserGroups): + parent_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups) + cur_buttons = [ + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST_CURRENT), user_access.AccessMode.VIEW, self.GetAccess()), + ] + return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) + + def RegisterHandlers(self): + super().RegisterHandlers() + table_name = self.m_Table.GetName() + key_name = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + + def GetViewItemInlineKeyboardTemplate(a_ItemID): + return self.GetViewItemInlineKeyboardTemplate(a_ItemID) + + GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc + GetAccess = self.m_GetAccessFunc + + default_keyboard_func = self.m_GetStartKeyboardButtonsFunc + + # Список текущих, открытых заказов + a_ButtonName = self.GetButton(ButtonNames.LIST_CURRENT) + if a_ButtonName: + a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) + a_Prefix = bd_item_select.SelectRegisterHandlers(self.m_Bot,\ + self.SelectSourceForCurrentTemplate(a_Prefix, a_ButtonName), \ + GetButtonNameAndKeyValueAndAccess,\ + self.GetMessage(mod_table_operate.Messages.SELECT),\ + GetAccess,\ + access_mode = user_access.AccessMode.VIEW\ + ) + bd_item_view.ShowBDItemRegisterHandlers(self.m_Bot,\ + a_Prefix,\ + table_name,\ + key_name,\ + self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.OPEN),GetViewItemInlineKeyboardTemplate),\ + GetAccess,\ + default_keyboard_func,\ + access_mode = user_access.AccessMode.VIEW\ + ) diff --git a/template/bd_item_add.py b/template/bd_item_add.py index 2bcb39d..73cbd71 100644 --- a/template/bd_item_add.py +++ b/template/bd_item_add.py @@ -10,6 +10,9 @@ from template import simple_message, bd_item_select, bd_item cancel_message = ''' 🚫 Добавление отменено ''' +error_photo_type_message = ''' +🚫 Неверный формат изображений +''' def StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMStart, a_MessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD): async def StartAddBDItem(a_CallbackQuery, state): -- 2.11.0 From f6d60532cf33ec7a77803de16314d08fd3bfbea1 Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 29 May 2023 23:21:34 +0300 Subject: [PATCH 05/15] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 11 +++++++++++ bot_modules/orders.py | 33 +++++++++++++++++++++------------ main.py | 4 ++-- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 9dff4db..f0e35fb 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -23,6 +23,7 @@ class ButtonNames(Enum): EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() EDIT_ADDRESS = auto() + EDIT_STATUS = auto() DEL = auto() class Messages(Enum): @@ -41,6 +42,7 @@ class Messages(Enum): EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() EDIT_ADDRESS = auto() + EDIT_STATUS = auto() SUCCESS_EDIT = auto() SELECT_TO_DELETE = auto() SUCCESS_DELETE = auto() @@ -53,6 +55,7 @@ class FSMs(Enum): EDIT_ACCESS = auto() EDIT_DEFAULT_ACCESS = auto() EDIT_ADDRESS = auto() + EDIT_STATUS = auto() create_fsms_cmd = ''' class FSMCreate{a_ModName}(StatesGroup): @@ -78,6 +81,9 @@ class FSMEdit{a_ModName}DefaultAccessItem(StatesGroup): class FSMEdit{a_ModName}AddressItem(StatesGroup): item_field = State() +class FSMEdit{a_ModName}StatusItem(StatesGroup): + item_field = State() + fsm = { FSMs.CREATE: FSMCreate{a_ModName}, FSMs.EDIT_NAME: FSMEdit{a_ModName}NameItem, @@ -86,6 +92,7 @@ fsm = { FSMs.EDIT_ACCESS: FSMEdit{a_ModName}AccessItem, FSMs.EDIT_DEFAULT_ACCESS: FSMEdit{a_ModName}DefaultAccessItem, FSMs.EDIT_ADDRESS: FSMEdit{a_ModName}AddressItem, + FSMs.EDIT_STATUS: FSMEdit{a_ModName}StatusItem, } ''' @@ -152,6 +159,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.DELETE, self.GetAccess()), keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ADDRESS), user_access.AccessMode.EDIT, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_STATUS), user_access.AccessMode.EDIT, self.GetAccess()), ] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) @@ -414,6 +423,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): ) address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS) + status_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.STATUS) self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) @@ -421,6 +431,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetFSM(FSMs.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_STATUS), self.GetFSM(FSMs.EDIT_STATUS), self.GetMessage(Messages.EDIT_STATUS), status_field, bd_item.FieldType.text) def OnChange(self): pass diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 74a7e7d..06576e0 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -5,7 +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, bd_item_view +from template import bd_item_select, bd_item_view, bd_item from enum import Enum from enum import auto @@ -61,6 +61,7 @@ button_names = { mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в заказе", mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в заказе", mod_table_operate.ButtonNames.EDIT_ADDRESS: "𝌴 Изменить адрес в заказе", + mod_table_operate.ButtonNames.EDIT_STATUS: "𝌴 Изменить статус в заказе", mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к заказу", mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", } @@ -132,6 +133,12 @@ messages = { Введите новый адрес доставки заказа (укажите, кто, когда и где его сможет забрать): ''', + mod_table_operate.Messages.EDIT_STATUS: f''' +Текущий статус заказа: +#{status_field} + +Введите новый статус заказа: +''', mod_table_operate.Messages.EDIT_ACCESS: f''' Текущий доступ к заказу: #{access_field} @@ -149,18 +156,17 @@ messages = { } def GetCurItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName, a_StatusFieldName): - def GetBDItem(a_KeyValue): - return a_Bot.SQLRequest(f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?', param = ([a_KeyValue, OrderStatus.FINISH])) - return GetBDItem - -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 + request = f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?' + print('GetCurItemsTemplate', a_TableName, a_UserIDFieldName, a_KeyValue) + return a_Bot.SQLRequest(request, param = ([a_KeyValue, OrderStatus.FINISH])) + return GetBDItems - return items +def GetBDItemsForUserTemplate(a_Bot, a_TableName, a_UserIDFieldName): + def GetBDItems(a_Message, a_UserGroups, a_ParentID): + user_id = str(a_Message.from_user.id) + print('user_id', a_Message, user_id) + return bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName)(user_id) return GetBDItems class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): @@ -172,7 +178,10 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): get_items_func = super().GetItemsFunc() if self.m_OnlyCurent: get_items_func = GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field) - return GetBDItemsForUserTemplate(get_items_func) + return GetBDItemsForUserTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName) + + def IsFirst(self): + return True 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): diff --git a/main.py b/main.py index e0defa3..eafe68c 100644 --- a/main.py +++ b/main.py @@ -134,8 +134,8 @@ for m in test_mods: m.Test() if __name__ == '__main__': -# os.system('clear') -# os.system('cls') + #os.system('clear') + #os.system('cls') g_Log.Success(log_start_message) g_Bot.StartPolling() -- 2.11.0 From 1c68ec034f0549c84092c9ef80c1d3ca01613168 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 30 May 2023 16:33:22 +0300 Subject: [PATCH 06/15] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D0=B3=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20FSM=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B5=D0=B0=D0=B4=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 74 +++++++++++++--------------------------- 1 file changed, 24 insertions(+), 50 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index f0e35fb..c805dad 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -49,13 +49,6 @@ class Messages(Enum): class FSMs(Enum): CREATE = auto() - EDIT_PHOTO = auto() - EDIT_NAME = auto() - EDIT_DESC = auto() - EDIT_ACCESS = auto() - EDIT_DEFAULT_ACCESS = auto() - EDIT_ADDRESS = auto() - EDIT_STATUS = auto() create_fsms_cmd = ''' class FSMCreate{a_ModName}(StatesGroup): @@ -63,36 +56,9 @@ class FSMCreate{a_ModName}(StatesGroup): desc = State() photo = State() -class FSMEdit{a_ModName}PhotoItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}NameItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}DescItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}AccessItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}DefaultAccessItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}AddressItem(StatesGroup): - item_field = State() - -class FSMEdit{a_ModName}StatusItem(StatesGroup): - item_field = State() fsm = { FSMs.CREATE: FSMCreate{a_ModName}, - FSMs.EDIT_NAME: FSMEdit{a_ModName}NameItem, - FSMs.EDIT_DESC: FSMEdit{a_ModName}DescItem, - FSMs.EDIT_PHOTO: FSMEdit{a_ModName}PhotoItem, - FSMs.EDIT_ACCESS: FSMEdit{a_ModName}AccessItem, - FSMs.EDIT_DEFAULT_ACCESS: FSMEdit{a_ModName}DefaultAccessItem, - FSMs.EDIT_ADDRESS: FSMEdit{a_ModName}AddressItem, - FSMs.EDIT_STATUS: FSMEdit{a_ModName}StatusItem, } ''' @@ -103,6 +69,20 @@ def MakeFSMs(a_ModName): return _locals['fsm'] +edit_fsm_cmd = ''' +class FSMEdit{a_ModName}_{a_FieldName}_Item(StatesGroup): + item_field = State() + +fsm = FSMEdit{a_ModName}_{a_FieldName}_Item +''' + +def MakeFSMForEdit(a_ModName, a_FieldName): + cmd = edit_fsm_cmd.replace("{a_ModName}", a_ModName).replace("{a_FieldName}", a_FieldName) + print ('cmd', cmd) + _locals = locals() + exec(cmd, globals(), _locals) + return _locals['fsm'] + class TableOperateModule(mod_simple_message.SimpleMessageModule): def __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): super().__init__(a_Messages, a_Buttons, a_InitAccess, a_ChildModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) @@ -216,12 +196,6 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return simple_message.WorkFuncResult(msg, item_access = item_access, Inline_keyboard_func = Inline_keyboard_func) return ShowMessage - # TODO: delete? - def SimpleMessageTemplate(self, a_MessageName : Messages): - async def ShowMessage(a_CallbackQuery, a_Item): - return simple_message.WorkFuncResult(self.GetMessage(a_MessageName)) - return ShowMessage - async def PreDelete(self, a_CallbackQuery, a_Item): if len(a_Item) < self.m_Table.GetFieldsCount(): return simple_message.WorkFuncResult(error_find_proj_message) @@ -282,7 +256,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix - def RegisterEdit(self, a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): + def RegisterEdit(self, a_ButtonName, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): if not a_ButtonName: return @@ -299,7 +273,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): bd_item_edit.EditBDItemRegisterHandlers(self.m_Bot, \ self.SelectSourceTemplate(a_Prefix, a_ButtonName), \ - a_FSM, \ + MakeFSMForEdit(self.GetName(), a_FieldName), \ self.GetMessage(Messages.SELECT_TO_EDIT), \ self.ShowMessageTemplate(a_EditMessage), \ self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_EDIT)), \ @@ -356,7 +330,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_Prefix,\ table_name,\ key_name,\ - self.ShowMessageTemplate(self.GetMessage(Messages.OPEN),GetViewItemInlineKeyboardTemplate),\ + self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate),\ GetAccess,\ defaul_keyboard_func,\ access_mode = user_access.AccessMode.VIEW\ @@ -425,13 +399,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS) status_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.STATUS) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetFSM(FSMs.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetFSM(FSMs.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetFSM(FSMs.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetFSM(FSMs.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetFSM(FSMs.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetFSM(FSMs.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_STATUS), self.GetFSM(FSMs.EDIT_STATUS), self.GetMessage(Messages.EDIT_STATUS), status_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text) + self.RegisterEdit(self.GetButton(ButtonNames.EDIT_STATUS), self.GetMessage(Messages.EDIT_STATUS), status_field, bd_item.FieldType.text) def OnChange(self): pass -- 2.11.0 From a8ff8c24559c5245ad3c59213cc0562f6a6e2189 Mon Sep 17 00:00:00 2001 From: Alexei Date: Tue, 30 May 2023 23:01:18 +0300 Subject: [PATCH 07/15] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20=D0=BD=D0=B0=20=D1=83=D0=BD=D0=B8=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D1=81=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 36 ++++++++++++++++++++++++++---------- bot_modules/orders.py | 4 +++- bot_modules/user_in_groups.py | 13 ------------- bot_sys/bd_table.py | 2 +- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index c805dad..02ff12e 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -217,21 +217,37 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): create_datetime_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.CREATE_DATE) parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) - res, error = None, None def_access = access_utils.GetItemDefaultAccessForModule(self.m_Bot, self.GetName()) - #TODO сделать список полей, чтобы запрос генерировался автоматически. - if parent_id_field: - res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})', - commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], def_access + f";{a_UserID}=+", a_ItemData[parent_id_field])) - else: - res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({photo_field}, {name_field}, {desc_field}, {access_field}, {create_datetime_field}) VALUES(?, ?, ?, ?, {bot_bd.GetBDDateTimeNow()})', - commit = True, return_error = True, param = (a_ItemData[photo_field], a_ItemData[name_field], a_ItemData[desc_field], def_access + f";{a_UserID}=+")) + + fields = [] + values = [] + param = () + for f in self.m_Table.GetFields(): + d = f.m_Destiny + n = f.m_Name + if d == bd_table.TableFieldDestiny.KEY: + continue + elif d == bd_table.TableFieldDestiny.CREATE_DATE: + fields += [n] + values += [bot_bd.GetBDDateTimeNow()] + elif d == bd_table.TableFieldDestiny.ACCESS: + fields += [n] + values += ['?'] + param += (def_access + f";{a_UserID}=+", ) + else: + fields += [n] + values += ['?'] + param += (a_ItemData[n], ) + + request = f'INSERT INTO {table_name}({",".join(fields)}) VALUES({",".join(values)})' + print('request', request, param) + res, error = self.m_Bot.SQLRequest(request, commit = True, return_error = True, param = param) 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}. Ошибка добавления записи в таблицу {request} {param}.') 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}. Добавлена запись в таблицу {request} {param}.') return res, error diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 06576e0..cb3d82f 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -26,7 +26,7 @@ name_field = 'orderName' desc_field = 'orderDesc' photo_field = 'orderPhoto' status_field = 'orderStatus' -address_field = 'orderAddres' +address_field = 'orderAddress' access_field = 'orderAccess' create_datetime_field = 'orderCreateDateTime' parent_id_field = 'userID' @@ -201,6 +201,8 @@ class ModuleOrders(mod_table_operate.TableOperateModule): def AddBDItemFunc(self, a_ItemData, a_UserID): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) a_ItemData[parent_id_field] = a_UserID + a_ItemData[status_field] = str(OrderStatus.NEW) + a_ItemData[address_field] = '' return super().AddBDItemFunc(a_ItemData, a_UserID) def GetStartKeyboardButtons(self, a_Message, a_UserGroups): diff --git a/bot_modules/user_in_groups.py b/bot_modules/user_in_groups.py index da376e6..9bf9bba 100644 --- a/bot_modules/user_in_groups.py +++ b/bot_modules/user_in_groups.py @@ -118,19 +118,6 @@ class ModuleUserInGroups(mod_table_operate.TableOperateModule): ] return t_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) - def AddBDItemFunc(self, a_ItemData, a_UserID): - def_access = access_utils.GetItemDefaultAccessForModule(self.m_Bot, self.GetName()) - res, error = self.m_Bot.SQLRequest(f'INSERT INTO {table_name}({name_field}, {access_field}, {parent_id_field}, {create_datetime_field}) VALUES(?, ?, ?, {bot_bd.GetBDDateTimeNow()})', - commit = True, return_error = True, param = (a_ItemData[name_field], def_access + f";{a_UserID}=+", a_ItemData[parent_id_field])) - - self.OnChange() - if error: - self.m_Log.Error(f'Пользоватлель {a_UserID}. Ошибка добавления записи в таблицу {table_name} ({a_ItemData[name_field]}, {def_access}).') - else: - self.m_Log.Success(f'Пользоватлель {a_UserID}. Добавлена запись в таблицу {table_name} ({a_ItemData[name_field]}, {def_access}).') - - return res, error - def RegisterHandlers(self): super().RegisterHandlers() GetButtonNameAndKeyValueAndAccess = self.m_GetButtonNameAndKeyValueAndAccessFunc diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index 26eaaab..9cf80d7 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -39,7 +39,7 @@ class Table: return self.m_TableName def GetFields(self): - return self.TableFieldType + return self.m_Fields def GetFieldsCount(self): return len(self.m_Fields) -- 2.11.0 From 7ab55fb27d14c52b5e135c5ed3677380f7447c70 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 11:09:06 +0300 Subject: [PATCH 08/15] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B2=D1=81=D0=B5=D1=85=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/access.py | 8 ++-- bot_modules/buttons.py | 22 +++++------ bot_modules/comments.py | 22 +++++------ bot_modules/groups.py | 22 +++++------ bot_modules/languages.py | 22 +++++------ bot_modules/messages.py | 22 +++++------ bot_modules/mod_table_operate.py | 79 ++++++++++++++++++++-------------------- bot_modules/needs.py | 22 +++++------ bot_modules/orders.py | 53 +++++++++++++++++---------- bot_modules/projects.py | 22 +++++------ bot_modules/tasks.py | 22 +++++------ bot_modules/user_in_groups.py | 8 ++-- bot_modules/users.py | 22 +++++------ bot_sys/bd_table.py | 1 + template/bd_item_edit.py | 8 ++-- 15 files changed, 185 insertions(+), 170 deletions(-) diff --git a/bot_modules/access.py b/bot_modules/access.py index d6ecd2d..cebb89b 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -87,8 +87,8 @@ moduleaccess_success_edit_message = '''✅ Доступ к модулю успе button_names = { mod_simple_message.ButtonNames.START: start_button_name, mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать доступ", - mod_table_operate.ButtonNames.EDIT_ACCESS: edit_moduleaccess_access_button_name, - mod_table_operate.ButtonNames.EDIT_DEFAULT_ACCESS: edit_moduleaccess_default_access_button_name, + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): edit_moduleaccess_access_button_name, + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DEFAULT_ACCESS): edit_moduleaccess_default_access_button_name, } messages = { @@ -97,8 +97,8 @@ messages = { Пожалуйста, выберите действие: ''', mod_table_operate.Messages.SELECT_TO_EDIT: moduleaccess_select_to_edit_message, - mod_table_operate.Messages.EDIT_ACCESS: moduleaccess_edit_access_message, - mod_table_operate.Messages.EDIT_DEFAULT_ACCESS: moduleaccess_edit_default_access_message, + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): moduleaccess_edit_access_message, + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DEFAULT_ACCESS): moduleaccess_edit_default_access_message, mod_table_operate.Messages.SUCCESS_EDIT: moduleaccess_success_edit_message, } diff --git a/bot_modules/buttons.py b/bot_modules/buttons.py index 991af83..a38cc71 100644 --- a/bot_modules/buttons.py +++ b/bot_modules/buttons.py @@ -47,10 +47,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список названий кнопок", mod_table_operate.ButtonNames.ADD: "☑ Добавить название кнопки", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать названия кнопок", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у названия кнопок", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у названия кнопок", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у названия кнопок", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к названию кнопки", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у названия кнопок", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у названия кнопок", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у названия кнопок", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к названию кнопки", mod_table_operate.ButtonNames.DEL: "❌ Удалить название кнопки", } @@ -72,17 +72,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание названия кнопки Шаг №1 Введите название название кнопки: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание названия кнопки. Шаг №2 Введите описание название кнопки: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание названия кнопки Загрузите обложку для названия кнопок (Фото): На данный момент не поддерживается! @@ -95,23 +95,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите название кнопки, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для названия кнопок (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название названия кнопок: #{name_field} Введите новое название названия кнопки: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание названия кнопок: #{desc_field} Введите новое описание названия кнопки: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к названию кнопки: #{access_field} diff --git a/bot_modules/comments.py b/bot_modules/comments.py index d9c9c42..3359cd6 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -39,10 +39,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список комментариев", mod_table_operate.ButtonNames.ADD: "☑ Добавить комментарий", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать комментарий", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у комментария", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у комментария", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у комментария", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к комментарию", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у комментария", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у комментария", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у комментария", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к комментарию", mod_table_operate.ButtonNames.DEL: "❌ Удалить комментарий", } @@ -64,17 +64,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание комментария. Шаг №1 Введите название комментария: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание комментария. Шаг №2 Введите описание комментария: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание комментария. Шаг №3 Загрузите обложку для комментария (Фото): @@ -87,23 +87,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите комментарий, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для комментария (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название комментария: #{name_field} Введите новое название комментария: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание комментария: #{desc_field} Введите новое описание комментария: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к комментарийу: #{access_field} diff --git a/bot_modules/groups.py b/bot_modules/groups.py index 1707abe..0a51cc5 100644 --- a/bot_modules/groups.py +++ b/bot_modules/groups.py @@ -44,10 +44,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список групп", mod_table_operate.ButtonNames.ADD: "✅ Добавить группу", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать группу", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в группе", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в группе", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в группе", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к группе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в группе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в группе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в группе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к группе", mod_table_operate.ButtonNames.DEL: "❌ Удалить группу", } @@ -69,17 +69,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание группы. Шаг №1 Введите название группы: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание группы. Шаг №2 Введите описание группы: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание группы. Шаг №3 Загрузите обложку для группы (Фото): @@ -92,23 +92,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите группу, которого вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для группы (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название группы: #{name_field} Введите новое название группы: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание группы: #{desc_field} Введите новое описание группы: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к группе: #{access_field} diff --git a/bot_modules/languages.py b/bot_modules/languages.py index 350a433..c6a1b15 100644 --- a/bot_modules/languages.py +++ b/bot_modules/languages.py @@ -44,10 +44,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список языков", mod_table_operate.ButtonNames.ADD: "✅ Добавить язык", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать язык", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в языке", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в языке", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в языке", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к языку", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в языке", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в языке", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в языке", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к языку", mod_table_operate.ButtonNames.DEL: "❌ Удалить язык", } @@ -69,17 +69,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание языка. Шаг №1 Введите название языка: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание языка. Шаг №2 Введите описание языка: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание языка. Шаг №3 Загрузите обложку для языка (Фото): @@ -92,23 +92,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите язык, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для языка (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название языка: #{name_field} Введите новое название языка: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание языка: #{desc_field} Введите новое описание языка: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к языку: #{access_field} diff --git a/bot_modules/messages.py b/bot_modules/messages.py index e87c8dc..b8bae87 100644 --- a/bot_modules/messages.py +++ b/bot_modules/messages.py @@ -47,10 +47,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список сообщений", mod_table_operate.ButtonNames.ADD: "☑ Добавить сообщение", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать сообщение", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у сообщения", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у сообщения", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у сообщения", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к сообщению", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у сообщения", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у сообщения", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у сообщения", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к сообщению", mod_table_operate.ButtonNames.DEL: "❌ Удалить сообщение", } @@ -72,17 +72,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание сообщения. Шаг №1 Введите название сообщения: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание сообщения. Шаг №2 Введите описание сообщения: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание сообщения. Шаг №3 Загрузите обложку для сообщения (Фото): @@ -95,23 +95,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите сообщение, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для сообщения (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название сообщения: #{name_field} Введите новое название сообщения: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание сообщения: #{desc_field} Введите новое описание сообщения: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к сообщениеу: #{access_field} diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 02ff12e..3a62594 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -13,36 +13,28 @@ from aiogram.dispatcher.filters.state import State, StatesGroup from enum import Enum from enum import auto +def EditButton(a_BDTableDestiny): + return 'edit' + str(a_BDTableDestiny) + +def EditMessage(a_BDTableDestiny): + return 'edit' + str(a_BDTableDestiny) + +def CreateMessage(a_BDTableDestiny): + return 'create' + str(a_BDTableDestiny) + class ButtonNames(Enum): LIST = auto() ADD = auto() EDIT = auto() - EDIT_PHOTO = auto() - EDIT_NAME = auto() - EDIT_DESC = auto() - EDIT_ACCESS = auto() - EDIT_DEFAULT_ACCESS = auto() - EDIT_ADDRESS = auto() - EDIT_STATUS = auto() DEL = auto() class Messages(Enum): SELECT = auto() ERROR_FIND = auto() OPEN = auto() - CREATE_NAME = auto() - CREATE_DESC = auto() - CREATE_PHOTO = auto() SUCCESS_CREATE = auto() START_EDIT = auto() SELECT_TO_EDIT = auto() - EDIT_PHOTO = auto() - EDIT_NAME = auto() - EDIT_DESC = auto() - EDIT_ACCESS = auto() - EDIT_DEFAULT_ACCESS = auto() - EDIT_ADDRESS = auto() - EDIT_STATUS = auto() SUCCESS_EDIT = auto() SELECT_TO_DELETE = auto() SUCCESS_DELETE = auto() @@ -134,13 +126,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def GetEditKeyboardButtons(self, a_Message, a_UserGroups): mod_buttons = keyboard.MakeButtons(self.m_Bot, self.GetButtons(self.m_EditModuleNameList), a_UserGroups) cur_buttons = [ - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_PHOTO), user_access.AccessMode.VIEW, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_NAME), user_access.AccessMode.ADD, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DESC), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ACCESS), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_ADDRESS), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.EDIT_STATUS), user_access.AccessMode.EDIT, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.PHOTO)), user_access.AccessMode.VIEW, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.NAME)), user_access.AccessMode.ADD, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DESC)), user_access.AccessMode.DELETE, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ACCESS)), user_access.AccessMode.DELETE, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DEFAULT_ACCESS)), user_access.AccessMode.EDIT, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ADDRESS)), user_access.AccessMode.EDIT, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.STATUS)), user_access.AccessMode.EDIT, self.GetAccess()), ] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) @@ -173,6 +165,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_Item[key_name_id],\ a_Item[access_field_id] + def UpdateMessage(self, a_Msg, a_Lang, a_Item): + a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_Msg.GetDesc(), a_Item)) + photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) + if photo_field: + a_Msg.UpdatePhotoID(a_Item[photo_field]) + return a_Msg + def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None): async def ShowMessage(a_CallbackQuery, a_Item): msg = a_Message.StaticCopy() @@ -185,10 +184,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): elif len(a_Item) == self.m_Table.GetFieldsCount(): lang = str(a_CallbackQuery.from_user.language_code) msg = msg.GetMessageForLang(lang).StaticCopy() - msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(msg.GetDesc(), a_Item)) - photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) - if photo_field: - msg.UpdatePhotoID(a_Item[photo_field]) + msg = self.UpdateMessage(msg, lang, a_Item) item_access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] if Inline_keyboard_template_func: Inline_keyboard_func = Inline_keyboard_template_func(a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.KEY)]) @@ -272,8 +268,16 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix - def RegisterEdit(self, a_ButtonName, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): - if not a_ButtonName: + 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)) + a_FieldName = a_Field.m_Name + + a_FieldType = bd_item.FieldType.text + if a_Field.m_Destiny == bd_table.TableFieldDestiny.PHOTO: + a_FieldType = bd_item.FieldType.photo + + if not a_ButtonName or not a_EditMessage: return def OnChange(): @@ -382,9 +386,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.GetFSM(FSMs.CREATE).desc, \ self.GetFSM(FSMs.CREATE).photo,\ self.m_AddBDItemFunc, \ - self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_NAME)), \ - self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_DESC)), \ - self.ShowMessageTemplate(self.GetMessage(Messages.CREATE_PHOTO)), \ + self.ShowMessageTemplate(self.GetMessage(CreateMessage(bd_table.TableFieldDestiny.NAME))), \ + self.ShowMessageTemplate(self.GetMessage(CreateMessage(bd_table.TableFieldDestiny.DESC))), \ + self.ShowMessageTemplate(self.GetMessage(CreateMessage(bd_table.TableFieldDestiny.PHOTO))), \ self.ShowMessageTemplate(self.GetMessage(Messages.SUCCESS_CREATE)), \ a_Prefix,\ parent_table_name, \ @@ -415,13 +419,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): address_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.ADDRESS) status_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.STATUS) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_NAME), self.GetMessage(Messages.EDIT_NAME), name_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DESC), self.GetMessage(Messages.EDIT_DESC), desc_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_PHOTO), self.GetMessage(Messages.EDIT_PHOTO), photo_field, bd_item.FieldType.photo) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ACCESS), self.GetMessage(Messages.EDIT_ACCESS), access_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_DEFAULT_ACCESS), self.GetMessage(Messages.EDIT_DEFAULT_ACCESS), def_access_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_ADDRESS), self.GetMessage(Messages.EDIT_ADDRESS), address_field, bd_item.FieldType.text) - self.RegisterEdit(self.GetButton(ButtonNames.EDIT_STATUS), self.GetMessage(Messages.EDIT_STATUS), status_field, bd_item.FieldType.text) + for f in self.m_Table.GetFields(): + self.RegisterEdit(f) def OnChange(self): pass diff --git a/bot_modules/needs.py b/bot_modules/needs.py index 993fe88..d180438 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -39,10 +39,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список потребностей", mod_table_operate.ButtonNames.ADD: "☑ Добавить потребность", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать потребность", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у потребности", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у потребности", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у потребности", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к потребности", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у потребности", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у потребности", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у потребности", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к потребности", mod_table_operate.ButtonNames.DEL: "❌ Удалить потребность", } @@ -64,17 +64,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание потребности. Шаг №1 Введите название потребности: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание потребности. Шаг №2 Введите описание потребности: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание потребности. Шаг №3 Загрузите обложку для потребности (Фото): @@ -87,23 +87,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите потребность, которую вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для потребности (Фото): Она будет отображаться в её описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название потребности: #{name_field} Введите новое название потребности: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание потребности: #{desc_field} Введите новое описание потребности: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к потребности: #{access_field} diff --git a/bot_modules/orders.py b/bot_modules/orders.py index cb3d82f..b16421e 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -57,12 +57,12 @@ button_names = { ButtonNames.LIST_CURRENT: "📃 Список текущих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в заказе", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в заказе", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в заказе", - mod_table_operate.ButtonNames.EDIT_ADDRESS: "𝌴 Изменить адрес в заказе", - mod_table_operate.ButtonNames.EDIT_STATUS: "𝌴 Изменить статус в заказе", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к заказу", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.STATUS): "𝌴 Изменить статус в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к заказу", mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", } @@ -78,27 +78,27 @@ messages = { ❌ Ошибка, заказ не найден ''', mod_table_operate.Messages.OPEN: f''' -Заказ: #{name_field} +Заказ: #{name_field} -#{desc_field} +Описание и состав заказа: #{desc_field} -Статус:#{status_field} +Статус: #{status_field} -Адрес доставки:#{address_field} +Адрес доставки: #{address_field} Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание заказа. Шаг №1 Введите название заказа: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание заказа. Шаг №2 Введите описание заказа: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание заказа. Шаг №3 Загрузите обложку для заказа (Фото): @@ -111,35 +111,35 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите заказ, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для заказа (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название заказа: #{name_field} Введите новое название заказа: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание заказа: #{desc_field} Введите новое описание заказа: ''', - mod_table_operate.Messages.EDIT_ADDRESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ADDRESS): f''' Текущий адрес заказа: #{desc_field} Введите новый адрес доставки заказа (укажите, кто, когда и где его сможет забрать): ''', - mod_table_operate.Messages.EDIT_STATUS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.STATUS): f''' Текущий статус заказа: #{status_field} Введите новый статус заказа: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к заказу: #{access_field} @@ -155,6 +155,15 @@ messages = { mod_table_operate.Messages.SUCCESS_DELETE: '''✅ Заказ успешно удалён!''', } +messages_order_status = { + OrderStatus.NEW: f'''Заказ создан, ожидает модерации''', + OrderStatus.PAY: f'''Заказ ожидает оплаты''', + OrderStatus.ADDRESS: f'''Заказ ожидает указания адреса доставки''', + OrderStatus.FINISH: f'''Заказ выполнен''', +} + +messages.update(messages_order_status) + def GetCurItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName, a_StatusFieldName): def GetBDItems(a_Message, a_UserGroups, a_ParentID): request = f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?' @@ -212,6 +221,12 @@ class ModuleOrders(mod_table_operate.TableOperateModule): ] return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) + def UpdateMessage(self, a_Msg, a_Lang, a_Item): + a_Msg = super().UpdateMessage(a_Msg, a_Lang, a_Item) + for s in OrderStatus: + a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(self.GetMessage(s).GetMessageForLang(a_Lang).StaticCopy()))) + return a_Msg + def RegisterHandlers(self): super().RegisterHandlers() table_name = self.m_Table.GetName() diff --git a/bot_modules/projects.py b/bot_modules/projects.py index ef5d54e..315899c 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -37,10 +37,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список проектов", mod_table_operate.ButtonNames.ADD: "✅ Добавить проект", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать проект", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в проекте", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в проекте", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в проекте", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к проекту", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в проекте", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в проекте", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в проекте", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к проекту", mod_table_operate.ButtonNames.DEL: "❌ Удалить проект", } @@ -62,17 +62,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание проекта. Шаг №1 Введите название проекта: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание проекта. Шаг №2 Введите описание проекта: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание проекта. Шаг №3 Загрузите обложку для проекта (Фото): @@ -85,23 +85,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите проект, который вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для проекта (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название проекта: #{name_field} Введите новое название проекта: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание проекта: #{desc_field} Введите новое описание проекта: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к проекту: #{access_field} diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index 56b4c49..39a3dfa 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -39,10 +39,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список задач", mod_table_operate.ButtonNames.ADD: "☑ Добавить задачу", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать задачу", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение у задачи", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название у задачи", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание у задачи", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к задаче", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение у задачи", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название у задачи", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание у задачи", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к задаче", mod_table_operate.ButtonNames.DEL: "❌ Удалить задачу", } @@ -64,17 +64,17 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание задачи. Шаг №1 Введите название задачи: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание задачи. Шаг №2 Введите описание задачи: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание задачи. Шаг №3 Загрузите обложку для задачи (Фото): @@ -87,23 +87,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите задачу, которую вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для задачи (Фото): Она будет отображаться в её описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название задачи: #{name_field} Введите новое название задачи: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание задачи: #{desc_field} Введите новое описание задачи: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к задаче: #{access_field} diff --git a/bot_modules/user_in_groups.py b/bot_modules/user_in_groups.py index 9bf9bba..a7bacda 100644 --- a/bot_modules/user_in_groups.py +++ b/bot_modules/user_in_groups.py @@ -55,7 +55,7 @@ button_names = { mod_simple_message.ButtonNames.START: "🗫 Пользователи в группах", mod_table_operate.ButtonNames.LIST: "📃 Список пользователей в группах", ButtonNames.ADD_USER: "✅ Добавить пользователя в группу", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Доступ к пользователю в группе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Доступ к пользователю в группе", mod_table_operate.ButtonNames.DEL: "❌ Удалить пользователя из группы", } @@ -77,7 +77,7 @@ messages = { Время создания: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание пользователя в группе. Укажите ID пользователя: @@ -89,7 +89,7 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите пользователя в группе, которого вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к пользователю в группе: #{access_field} @@ -145,7 +145,7 @@ class ModuleUserInGroups(mod_table_operate.TableOperateModule): check_func,\ FSMAddUserInGroups,\ self.m_AddBDItemFunc,\ - self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.CREATE_NAME)),\ + self.ShowMessageTemplate(self.GetMessage(mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME))),\ self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.SUCCESS_CREATE)),\ a_Prefix,\ parent_table_name,\ diff --git a/bot_modules/users.py b/bot_modules/users.py index 1fcd569..8b871ab 100644 --- a/bot_modules/users.py +++ b/bot_modules/users.py @@ -44,10 +44,10 @@ button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список пользователей", # mod_table_operate.ButtonNames.ADD: "✅ Добавить пользователя", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать пользователя", - mod_table_operate.ButtonNames.EDIT_PHOTO: "☐ Изменить изображение в пользователяе", - mod_table_operate.ButtonNames.EDIT_NAME: "≂ Изменить название в пользователяе", - mod_table_operate.ButtonNames.EDIT_DESC: "𝌴 Изменить описание в пользователяе", - mod_table_operate.ButtonNames.EDIT_ACCESS: "✋ Изменить доступ к пользователю", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в пользователяе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в пользователяе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в пользователяе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к пользователю", mod_table_operate.ButtonNames.DEL: "❌ Удалить пользователя", } @@ -72,17 +72,17 @@ messages = { Код языка: #{language_code_field} Дата добавления: #{create_datetime_field} ''', - mod_table_operate.Messages.CREATE_NAME: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.NAME): ''' Создание пользователя. Шаг №1 Введите название пользователя: ''', - mod_table_operate.Messages.CREATE_DESC: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.DESC): ''' Создание пользователя. Шаг №2 Введите описание пользователя: ''', - mod_table_operate.Messages.CREATE_PHOTO: ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.PHOTO): ''' Создание пользователя. Шаг №3 Загрузите обложку для пользователя (Фото): @@ -95,23 +95,23 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите пользователя, которого вы хотите отредактировать. ''', - mod_table_operate.Messages.EDIT_PHOTO: ''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для пользователя (Фото): Она будет отображаться в его описании. ''', - mod_table_operate.Messages.EDIT_NAME: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.NAME): f''' Текущее название пользователя: #{name_field} Введите новое название пользователя: ''', - mod_table_operate.Messages.EDIT_DESC: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.DESC): f''' Текущее описание пользователя: #{name1_field} Введите новое описание пользователя: ''', - mod_table_operate.Messages.EDIT_ACCESS: f''' + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к пользователю: #{access_field} diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index 9cf80d7..e4ed87b 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -119,6 +119,7 @@ def Test(): assert table.GetFieldNameByDestiny(TableFieldDestiny.PHOTO) == None assert table.GetFieldsCount() == 3 + assert len(table.GetFields()) == 3 print(table.GetInitTableRequest()) assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, UNIQUE(f1), UNIQUE(f2, f3));' diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index 01cfafd..972c715 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -33,13 +33,13 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type) -def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): +def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode) a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) - a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) + a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) if field_type == bd_item.FieldType.photo: - a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field) + a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field) else: - a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field) + a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field) -- 2.11.0 From b665e7cfbe40501be9ba2ea296c2a7fba357c3b9 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 12:22:36 +0300 Subject: [PATCH 09/15] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82?= =?UTF-8?q?=D0=B8=D0=BF=20=D0=BF=D0=BE=D0=BB=D1=8F=20-=20ENUM=20=D0=90?= =?UTF-8?q?=D0=B2=D1=82=D0=BE=D0=BC=D0=B0=D1=82=D0=B8=D1=87=D0=B5=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BF=D0=BE=D0=B4=20=D0=BD=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D1=8E=D1=82=D1=81=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B8=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B8=D0=B8=20=D0=B8=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D1=80=D1=83=D1=8E=D1=82=D1=81=D1=8F=20=D0=B2?= =?UTF-8?q?=20=D1=83=D0=B4=D0=BE=D0=B1=D0=BE=D0=B2=D0=B0=D1=80=D0=B8=D0=BC?= =?UTF-8?q?=D1=8B=D0=B9=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/mod_table_operate.py | 41 +++++++++++++++++++++++++++++++++++++--- bot_modules/orders.py | 36 ++++++++++++++++------------------- bot_sys/bd_table.py | 37 ++++++++++++++++++++++++++++-------- template/bd_item.py | 10 ++++++++++ template/bd_item_add.py | 23 ++++++++++++---------- template/bd_item_edit.py | 14 +++++++------- 6 files changed, 113 insertions(+), 48 deletions(-) diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 3a62594..8705d8d 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -14,13 +14,19 @@ from enum import Enum from enum import auto def EditButton(a_BDTableDestiny): - return 'edit' + str(a_BDTableDestiny) + return 'edit ' + str(a_BDTableDestiny) + +def EnumButton(a_EnumItem): + return 'enum ' + str(a_EnumItem) def EditMessage(a_BDTableDestiny): - return 'edit' + str(a_BDTableDestiny) + return 'edit ' + str(a_BDTableDestiny) def CreateMessage(a_BDTableDestiny): - return 'create' + str(a_BDTableDestiny) + return 'create ' + str(a_BDTableDestiny) + +def EnumMessageForView(a_EnumItem): + return 'enum ' + str(a_EnumItem) class ButtonNames(Enum): LIST = auto() @@ -170,8 +176,15 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) if photo_field: a_Msg.UpdatePhotoID(a_Item[photo_field]) + for f in self.m_Table.GetFields(): + if f.m_Type == bd_table.TableFieldType.ENUM: + for s in f.m_Enum: + msg = self.GetMessage(EnumMessageForView(s)) + if msg: + a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(msg.GetMessageForLang(a_Lang).StaticCopy()))) return a_Msg + def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None): async def ShowMessage(a_CallbackQuery, a_Item): msg = a_Message.StaticCopy() @@ -268,6 +281,26 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix + def AdditionalKeyboardForEditTemplate(self, a_Field): + if a_Field.m_Type == bd_table.TableFieldType.ENUM: + def KeyboardButtons(a_Message, a_UserGroups): + cur_buttons = [] + for s in a_Field.m_Enum: + cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EnumButton(s)), user_access.AccessMode.EDIT, self.GetAccess()),] + return keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) + return KeyboardButtons + return None + + def PostProccessingForFieldForEditTemplate(self, a_Field): + if a_Field.m_Type == bd_table.TableFieldType.ENUM: + def PostProccessing(a_Message): + for s in a_Field.m_Enum: + if a_Message == str(self.GetButton(EnumButton(s))): + return str(s) + return a_Message + return PostProccessing + return None + 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)) @@ -300,8 +333,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): table_name, \ key_name, \ a_FieldName, \ + self.PostProccessingForFieldForEditTemplate(a_Field),\ GetButtonNameAndKeyValueAndAccess, \ GetAccess, \ + self.AdditionalKeyboardForEditTemplate(a_Field),\ edit_keyboard_func, \ OnChange,\ access_mode = a_AccessMode, \ diff --git a/bot_modules/orders.py b/bot_modules/orders.py index b16421e..4bf4a9b 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -36,7 +36,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), - bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.STR), + bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.ENUM, a_Enum = OrderStatus), bd_table.TableField(address_field, bd_table.TableFieldDestiny.ADDRESS, bd_table.TableFieldType.STR), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), @@ -63,6 +63,10 @@ button_names = { mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.STATUS): "𝌴 Изменить статус в заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к заказу", + mod_table_operate.EnumButton(OrderStatus.NEW): "Заказ ожидает модерации", + mod_table_operate.EnumButton(OrderStatus.PAY): "Заказ ожидает оплаты", + mod_table_operate.EnumButton(OrderStatus.ADDRESS): "Заказ ожидает уточнения адреса", + mod_table_operate.EnumButton(OrderStatus.FINISH): "Заказ выполнен", mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", } @@ -156,37 +160,35 @@ messages = { } messages_order_status = { - OrderStatus.NEW: f'''Заказ создан, ожидает модерации''', - OrderStatus.PAY: f'''Заказ ожидает оплаты''', - OrderStatus.ADDRESS: f'''Заказ ожидает указания адреса доставки''', - OrderStatus.FINISH: f'''Заказ выполнен''', + mod_table_operate.EnumMessageForView(OrderStatus.NEW): f'''Заказ создан, ожидает модерации''', + mod_table_operate.EnumMessageForView(OrderStatus.PAY): f'''Заказ ожидает оплаты''', + mod_table_operate.EnumMessageForView(OrderStatus.ADDRESS): f'''Заказ ожидает указания адреса доставки''', + mod_table_operate.EnumMessageForView(OrderStatus.FINISH): f'''Заказ выполнен''', } messages.update(messages_order_status) def GetCurItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName, a_StatusFieldName): def GetBDItems(a_Message, a_UserGroups, a_ParentID): + user_id = str(a_Message.from_user.id) request = f'SELECT * FROM {a_TableName} WHERE {a_UserIDFieldName} = ? AND {a_StatusFieldName} != ?' - print('GetCurItemsTemplate', a_TableName, a_UserIDFieldName, a_KeyValue) - return a_Bot.SQLRequest(request, param = ([a_KeyValue, OrderStatus.FINISH])) + return a_Bot.SQLRequest(request, param = ([user_id, str(OrderStatus.FINISH)])) return GetBDItems def GetBDItemsForUserTemplate(a_Bot, a_TableName, a_UserIDFieldName): def GetBDItems(a_Message, a_UserGroups, a_ParentID): user_id = str(a_Message.from_user.id) - print('user_id', a_Message, user_id) return bd_item.GetBDItemsTemplate(a_Bot, a_TableName, a_UserIDFieldName)(user_id) return GetBDItems class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): - def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurent = False): + def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = False): super().__init__(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName) - self.m_OnlyCurent = a_OnlyCurent + self.m_OnlyCurrent = a_OnlyCurrent def GetItemsFunc(self): - get_items_func = super().GetItemsFunc() - if self.m_OnlyCurent: - get_items_func = GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field) + if self.m_OnlyCurrent: + return GetCurItemsTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName, status_field) return GetBDItemsForUserTemplate(self.m_Bot, self.m_TableName, self.m_ParentIDFieldName) def IsFirst(self): @@ -205,7 +207,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): def SelectSourceForCurrentTemplate(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, a_OnlyCurent = True) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = True) def AddBDItemFunc(self, a_ItemData, a_UserID): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) @@ -221,12 +223,6 @@ class ModuleOrders(mod_table_operate.TableOperateModule): ] return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) - def UpdateMessage(self, a_Msg, a_Lang, a_Item): - a_Msg = super().UpdateMessage(a_Msg, a_Lang, a_Item) - for s in OrderStatus: - a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(self.GetMessage(s).GetMessageForLang(a_Lang).StaticCopy()))) - return a_Msg - def RegisterHandlers(self): super().RegisterHandlers() table_name = self.m_Table.GetName() diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index e4ed87b..6223308 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -8,6 +8,15 @@ from enum import auto class TableFieldType(Enum): INT = 'INTEGER' STR = 'TEXT' + ENUM = 'ENUM' + +def InitTableType(a_TableFieldType): + types = { + TableFieldType.INT: 'INTEGER', + TableFieldType.STR: 'TEXT', + TableFieldType.ENUM: 'TEXT', + } + return types.get(a_TableFieldType, None) # Предназначение поля в таблице class TableFieldDestiny(Enum): @@ -24,10 +33,11 @@ class TableFieldDestiny(Enum): OTHER = auto() class TableField: - def __init__(self, a_Name, a_Destiny : TableFieldDestiny, a_Type : TableFieldType): + def __init__(self, a_Name, a_Destiny : TableFieldDestiny, a_Type : TableFieldType, a_Enum = None): self.m_Name = a_Name self.m_Destiny = a_Destiny self.m_Type = a_Type + self.m_Enum = a_Enum class Table: def __init__(self, a_TableName, a_Fields : [TableField], a_UniqueFields = None): @@ -67,7 +77,7 @@ class Table: request = f'CREATE TABLE IF NOT EXISTS {self.GetName()}(' items = [] for f in self.m_Fields: - item = f.m_Name + ' ' + str(f.m_Type.value) + item = f.m_Name + ' ' + str(InitTableType(f.m_Type)) if f.m_Destiny == TableFieldDestiny.KEY: item += ' PRIMARY KEY' items += [item] @@ -86,14 +96,20 @@ class Table: result = result.replace(f'#{f.m_Name}', str(a_BDItem[i])) return result +class Status(Enum): + NEW = auto() + FINISH = auto() + def Test(): f1 = TableField('f1', TableFieldDestiny.KEY, TableFieldType.INT) f2 = TableField('f2', TableFieldDestiny.NAME, TableFieldType.STR) f3 = TableField('f3', TableFieldDestiny.DESC, TableFieldType.STR) + f4 = TableField('f4', TableFieldDestiny.STATUS, TableFieldType.ENUM, a_Enum = Status) table = Table('tname', [ f1, f2, - f3 + f3, + f4, ], [[f1], [f2, f3]] ) @@ -113,16 +129,21 @@ def Test(): assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Destiny == TableFieldDestiny.DESC assert table.GetFieldByDestiny(TableFieldDestiny.DESC).m_Type == TableFieldType.STR assert table.GetFieldIDByDestiny(TableFieldDestiny.DESC) == 2 + assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Name == 'f4' + assert table.GetFieldNameByDestiny(TableFieldDestiny.STATUS) == 'f4' + assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Destiny == TableFieldDestiny.STATUS + assert table.GetFieldByDestiny(TableFieldDestiny.STATUS).m_Type == TableFieldType.ENUM + assert table.GetFieldIDByDestiny(TableFieldDestiny.STATUS) == 3 assert table.GetFieldByDestiny(TableFieldDestiny.PHOTO) == None assert table.GetFieldIDByDestiny(TableFieldDestiny.PHOTO) == None assert table.GetFieldNameByDestiny(TableFieldDestiny.PHOTO) == None - assert table.GetFieldsCount() == 3 - assert len(table.GetFields()) == 3 + assert table.GetFieldsCount() == 4 + assert len(table.GetFields()) == 4 print(table.GetInitTableRequest()) - assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, UNIQUE(f1), UNIQUE(f2, f3));' + assert table.GetInitTableRequest() == 'CREATE TABLE IF NOT EXISTS tname(f1 INTEGER PRIMARY KEY, f2 TEXT, f3 TEXT, f4 TEXT, UNIQUE(f1), UNIQUE(f2, f3));' - item = [10, 'i1', 'i2'] - assert table.ReplaceAllFieldTags('#f1 #f2 #f3', item) == '10 i1 i2' + item = [10, 'i2', 'i3', 'i4'] + assert table.ReplaceAllFieldTags('#f1 #f2 #f3 #f4', item) == '10 i2 i3 i4' diff --git a/template/bd_item.py b/template/bd_item.py index b0cadc6..5a08a84 100644 --- a/template/bd_item.py +++ b/template/bd_item.py @@ -42,6 +42,16 @@ def GetKeyDataFromCallbackMessage(a_Message, a_Prefix): key_item_id = str(a_Message.data).replace(a_Prefix, '') return key_item_id +def MixKeyboardFuncTemplate(a_Func1, a_Func2): + def KeyboardButtons(a_Message, a_UserGroups): + func = [a_Func1, a_Func2] + result = [] + for f in func: + if f: + result += f(a_Message, a_UserGroups) + return result + return KeyboardButtons + def GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, a_AccessMode): def GetCancelKeyboardButtons(a_Message, a_UserGroups): cur_buttons = [ diff --git a/template/bd_item_add.py b/template/bd_item_add.py index 73cbd71..373bac3 100644 --- a/template/bd_item_add.py +++ b/template/bd_item_add.py @@ -39,13 +39,13 @@ def StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMStart, a_MessageFunc, a_ParentTabl return res_of_work_func return simple_message.SimpleMessageTemplate(a_Bot, StartAddBDItem, a_ButtonFunc, None, a_AccessFunc, access_mode) -def FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): - return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, True, access_mode = access_mode, field_type = field_type) +def FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): + return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_ButtonFunc, True, access_mode = access_mode, field_type = field_type) -def NextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): - return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type) +def NextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): + return FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, False, access_mode = access_mode, field_type = field_type) -def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): +def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, a_Finish, access_mode = user_access.AccessMode.ADD, field_type = bd_item.FieldType.text): async def FinishAddBDItem(a_Message, state): state_func = None if a_Finish: @@ -84,7 +84,10 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(error_photo_type_message), keyboard_func = a_FinishButtonFunc) field_value = a_Message.photo[0].file_id else: - field_value = a_Message.text + result = a_Message.text + if a_PostProcessFunc: + result = a_PostProcessFunc(result) + field_value = result item_data[a_FieldName] = field_value if a_Finish: res, error = a_AddBDItemFunc(item_data, user_id) @@ -104,9 +107,9 @@ def AddBDItem3RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMD reg_func(StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) # TODO: Сделать возможность не указывать все поля. пусть a_FSMName и a_NameField например могут быть пустыми. Возможно лучше вообще передавать список полей и их fsm - a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_NameField, a_AddDescMessageFunc, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName) - a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_DescField, a_AddPhotoMessageFunc, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc) - a_Bot.RegisterMessageHandler(FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto) + a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_NameField, a_AddDescMessageFunc, None, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMName) + a_Bot.RegisterMessageHandler(NextAddBDItemTemplate(a_Bot, a_FSM, None, a_ParentTableName, a_ParentKeyFieldName, a_DescField, a_AddPhotoMessageFunc, None, a_AccessFunc, keyboard_skip_and_cancel, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.text), state = a_FSMDesc) + a_Bot.RegisterMessageHandler(FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_PhotoField, a_FinishMessageFunc, None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = bd_item.FieldType.photo), content_types = ['photo', 'text'], state = a_FSMPhoto) def AddBDItem1RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_AddBDItemFunc, a_AddMessageFunc, a_FinishMessageFunc, a_ParentPrefix, a_ParentTableName : str, a_ParentKeyFieldName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, a_FieldType, access_mode = user_access.AccessMode.ADD): keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode) @@ -114,7 +117,7 @@ def AddBDItem1RegisterHandlers(a_Bot, a_StartCheckFunc, a_FSM, a_AddBDItemFunc, if a_ParentTableName: reg_func = a_Bot.RegisterCallbackHandler reg_func(StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.bd_item, a_AddMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) - finish_handler = FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = a_FieldType) + finish_handler = FinishAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableName, a_ParentKeyFieldName, a_FieldName, a_FinishMessageFunc, None, a_AccessFunc, a_ButtonFunc, access_mode, field_type = a_FieldType) if a_FieldType == bd_item.FieldType.photo: a_Bot.RegisterMessageHandler(finish_handler, content_types = ['photo', 'text'], state = a_FSM.bd_item) else: diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index 972c715..8b85a66 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -18,7 +18,7 @@ error_photo_type_message = ''' def StartEditBDItemTemplate(a_Bot, a_FSM, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.EDIT): return bd_item_add.StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.item_field, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode) -def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): +def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): def EditBDItemFunc(a_ItemData, a_UserID): item_id = a_ItemData[a_KeyName] field_value = a_ItemData[a_FieldName] @@ -31,15 +31,15 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_OnChangeFunc() return res, error - return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type) + return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type) -def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): - keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode) +def EditBDItemRegisterHandlers(a_Bot, a_SelectSource, a_FSM, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName, a_KeyName, a_FieldName, a_PostProcessFunc, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_AdditionalButtonFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): + keyboard = bd_item.MixKeyboardFuncTemplate(a_AdditionalButtonFunc, bd_item.GetCancelKeyboardButtonsTemplate(a_Bot, a_AccessFunc, access_mode)) a_Prefix = bd_item_select.SelectRegisterHandlers(a_Bot, a_SelectSource, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) - a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard_cancel, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) + a_Bot.RegisterCallbackHandler(StartEditBDItemTemplate(a_Bot, a_FSM, a_EditMessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, keyboard, a_FinishButtonFunc, access_mode), bd_item.GetCheckForPrefixFunc(a_Prefix)) if field_type == bd_item.FieldType.photo: - a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field) + a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field) else: - a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field) + a_Bot.RegisterMessageHandler(FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_PostProcessFunc, a_AccessFunc, a_FinishButtonFunc, a_OnChangeFunc, access_mode, field_type = field_type), state = a_FSM.item_field) -- 2.11.0 From 60caff8426cd9f04ad64bd4eb18eea44707acaf1 Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 13:30:53 +0300 Subject: [PATCH 10/15] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B4=D1=83=D0=BB=D1=8C=20-=20=D0=B2=D1=81=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/all_orders.py | 118 ++++++++++++++++++++++++++++++++++++++++++++++ bot_modules/orders.py | 42 +++++++---------- main.py | 10 +++- 3 files changed, 143 insertions(+), 27 deletions(-) create mode 100644 bot_modules/all_orders.py diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py new file mode 100644 index 0000000..a98b0df --- /dev/null +++ b/bot_modules/all_orders.py @@ -0,0 +1,118 @@ +# -*- coding: utf8 -*- +# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) + +# Заказы + +from bot_sys import bot_bd, keyboard, user_access, bd_table +from bot_modules import mod_table_operate, mod_simple_message, orders +from template import bd_item_select, bd_item_view, bd_item + + +# --------------------------------------------------------- +# БД +module_name = 'all_orders' + +table = orders.table + +init_access = f'{user_access.user_access_group_new}=-' + +# --------------------------------------------------------- +# Сообщения и кнопки + +button_names = {} +button_names.update(orders.button_names) +button_names.pop(mod_table_operate.ButtonNames.ADD) + +cur_button_names = { + mod_simple_message.ButtonNames.START: "‍🛒 Все заказы", + mod_table_operate.ButtonNames.LIST: "📃 Список всех заказов", + orders.ButtonNames.LIST_CURRENT: "📃 Список текущих заказов", + mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к заказу", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.STATUS): "𝌴 Изменить статус в заказе", + mod_table_operate.EnumButton(orders.OrderStatus.NEW): "Заказ ожидает модерации", + mod_table_operate.EnumButton(orders.OrderStatus.PAY): "Заказ ожидает оплаты", + mod_table_operate.EnumButton(orders.OrderStatus.ADDRESS): "Заказ ожидает уточнения адреса", + mod_table_operate.EnumButton(orders.OrderStatus.FINISH): "Заказ выполнен", + mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ",} +button_names.update(cur_button_names) + +messages = {} +messages.update(orders.messages) + +cur_messages = { + mod_simple_message.Messages.START: f''' +{button_names[mod_simple_message.ButtonNames.START]} + +''', + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.STATUS): f''' +Текущий статус заказа: +#{orders.status_field} + +Введите новый статус заказа: +''', + mod_table_operate.Messages.OPEN: f''' +Заказ: #{orders.name_field} + +Описание и состав заказа: #{orders.desc_field} + +Статус: #{orders.status_field} + +Пользователь: #{orders.parent_id_field} + +Адрес доставки: #{orders.address_field} + +Время создания: #{orders.create_datetime_field} +''', +} + +messages.update(orders.messages_order_status) +messages.update(cur_messages) + +def GetCurItemsTemplate(a_Bot, a_TableName, a_StatusFieldName): + def GetBDItems(a_Message, a_UserGroups, a_ParentID): + request = f'SELECT * FROM {a_TableName} WHERE {a_StatusFieldName} != ?' + return a_Bot.SQLRequest(request, param = ([user_id, str(OrderStatus.FINISH)])) + return GetBDItems + +def GetBDItemsForUserTemplate(a_Bot, a_TableName): + def GetBDItems(a_Message, a_UserGroups, a_ParentID): + return bd_item.GetAllItemsTemplate(a_Bot, a_TableName)() + return GetBDItems + +class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): + def __init__(self, a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = False): + super().__init__(a_Bot, a_TableName, a_ParentIDFieldName, a_PrevPrefix, a_ButtonName) + self.m_OnlyCurrent = a_OnlyCurrent + + def GetItemsFunc(self): + if self.m_OnlyCurrent: + return GetCurItemsTemplate(self.m_Bot, self.m_TableName, orders.status_field) + return GetBDItemsForUserTemplate(self.m_Bot, self.m_TableName) + + def IsFirst(self): + return True + +class ModuleAllOrders(orders.ModuleOrders): + 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 GetInitBDCommands(self): + # уже сделано в ModuleUserOrders + return [] + + 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) + + def SelectSourceForCurrentTemplate(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, a_OnlyCurrent = True) + diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 4bf4a9b..227ea9f 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -53,21 +53,16 @@ class ButtonNames(Enum): button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Заказы", - mod_table_operate.ButtonNames.LIST: "📃 Список всех заказов", - ButtonNames.LIST_CURRENT: "📃 Список текущих заказов", + mod_table_operate.ButtonNames.LIST: "📃 Список всех моих заказов", + ButtonNames.LIST_CURRENT: "📃 Список моих текущих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", - mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в заказе", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в заказе", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в заказе", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.STATUS): "𝌴 Изменить статус в заказе", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к заказу", - mod_table_operate.EnumButton(OrderStatus.NEW): "Заказ ожидает модерации", - mod_table_operate.EnumButton(OrderStatus.PAY): "Заказ ожидает оплаты", - mod_table_operate.EnumButton(OrderStatus.ADDRESS): "Заказ ожидает уточнения адреса", - mod_table_operate.EnumButton(OrderStatus.FINISH): "Заказ выполнен", - mod_table_operate.ButtonNames.DEL: "❌ Удалить заказ", + mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в моём заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ADDRESS): "𝌴 Изменить адрес в моём заказе", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Изменить доступ к моему заказу", + mod_table_operate.ButtonNames.DEL: "❌ Удалить мой заказ", } messages = { @@ -137,12 +132,6 @@ messages = { Введите новый адрес доставки заказа (укажите, кто, когда и где его сможет забрать): ''', - mod_table_operate.EditMessage(bd_table.TableFieldDestiny.STATUS): f''' -Текущий статус заказа: -#{status_field} - -Введите новый статус заказа: -''', mod_table_operate.EditMessage(bd_table.TableFieldDestiny.ACCESS): f''' Текущий доступ к заказу: #{access_field} @@ -195,11 +184,8 @@ class DBItemForUserSelectSource(bd_item_select.DBItemSelectSource): return True 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 __init__(self, a_Table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log): + super().__init__(table, a_Messages, a_Buttons, a_ParentModName, a_ChildModName, a_InitAccess, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_Log) def SelectSourceTemplate(self, a_PrevPrefix, a_ButtonName): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) @@ -257,3 +243,9 @@ class ModuleOrders(mod_table_operate.TableOperateModule): access_mode = user_access.AccessMode.VIEW\ ) +class ModuleUserOrders(ModuleOrders): + 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 diff --git a/main.py b/main.py index eafe68c..e6de562 100644 --- a/main.py +++ b/main.py @@ -6,7 +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 +from bot_modules import orders, all_orders log_start_message = 'Бот успешно запущен!' @@ -36,6 +36,7 @@ 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 +mod_all_orders_name = all_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) @@ -90,9 +91,13 @@ mod_buttons = buttons.ModuleButtons(mod_languages_name, None, child_mod_name_lis 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) +mod_orders = orders.ModuleUserOrders(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_start_name] +mod_all_orders = all_orders.ModuleAllOrders(None, None, child_mod_name_list, start_mod_list, g_Bot, g_ModuleAgregator, g_BotMessages, g_BotButtons, g_Log) +g_ModuleAgregator.AddModule(mod_all_orders) + child_mod_name_list = [ mod_profile.GetName(), mod_backup.GetName(), @@ -101,6 +106,7 @@ child_mod_name_list = [ mod_project.GetName(), mod_languages.GetName(), mod_orders.GetName(), + mod_all_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) -- 2.11.0 From 242cb4631eb39b9f23ba53ec47da0f5531e1023b Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 13:31:36 +0300 Subject: [PATCH 11/15] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.=20=D0=A3=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D0=B2=20=D1=81=20=D0=B3=D0=BB=D0=B0?= =?UTF-8?q?=D0=B2=D0=BD=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/projects.py | 6 ------ bot_sys/bd_table.py | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bot_modules/projects.py b/bot_modules/projects.py index 315899c..fb28514 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -124,9 +124,3 @@ class ModuleProjects(mod_table_operate.TableOperateModule): def GetName(self): return module_name - def GetModuleButtons(self): - return super().GetModuleButtons() + [ - keyboard.ButtonWithAccess(self.GetButton(mod_table_operate.ButtonNames.LIST), user_access.AccessMode.VIEW, self.GetAccess()), - ] - - diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index 6223308..e09f4b4 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -6,9 +6,9 @@ from enum import auto # Тип поля в таблице class TableFieldType(Enum): - INT = 'INTEGER' - STR = 'TEXT' - ENUM = 'ENUM' + INT = auto() + STR = auto() + ENUM = auto() def InitTableType(a_TableFieldType): types = { -- 2.11.0 From dbb12983fb6ca561dca34c3cd0e91c34581dc7ab Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 14:36:58 +0300 Subject: [PATCH 12/15] =?UTF-8?q?=D0=A4=D0=BE=D1=82=D0=BE=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D1=87=D0=B5=D0=BA=D0=B0=20=D0=B2=20=D0=B7=D0=B0=D0=BA?= =?UTF-8?q?=D0=B0=D0=B7=D0=B0=D1=85=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=D0=BE=D1=81=D1=8C=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF=D0=BE=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=B8=D1=85=20=D1=84=D0=BE=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D1=80=D0=B0=D1=84=D0=B8=D0=B9=20=D0=B7=D0=B0=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/buttons.py | 2 +- bot_modules/comments.py | 2 +- bot_modules/groups.py | 2 +- bot_modules/languages.py | 2 +- bot_modules/messages.py | 2 +- bot_modules/mod_simple_message.py | 1 + bot_modules/mod_table_operate.py | 24 ++++++++++-------------- bot_modules/needs.py | 2 +- bot_modules/orders.py | 9 ++++++++- bot_modules/projects.py | 2 +- bot_modules/tasks.py | 2 +- bot_modules/users.py | 2 +- bot_sys/aiogram_bot.py | 24 +++++++++++++++++++++--- bot_sys/bd_table.py | 3 +++ 14 files changed, 52 insertions(+), 27 deletions(-) diff --git a/bot_modules/buttons.py b/bot_modules/buttons.py index a38cc71..a268b93 100644 --- a/bot_modules/buttons.py +++ b/bot_modules/buttons.py @@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), table_parent_id_field, diff --git a/bot_modules/comments.py b/bot_modules/comments.py index 3359cd6..28eb8c7 100644 --- a/bot_modules/comments.py +++ b/bot_modules/comments.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), diff --git a/bot_modules/groups.py b/bot_modules/groups.py index 0a51cc5..7724eeb 100644 --- a/bot_modules/groups.py +++ b/bot_modules/groups.py @@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), ], diff --git a/bot_modules/languages.py b/bot_modules/languages.py index c6a1b15..66af1b9 100644 --- a/bot_modules/languages.py +++ b/bot_modules/languages.py @@ -25,7 +25,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), ], diff --git a/bot_modules/messages.py b/bot_modules/messages.py index b8bae87..2506c2a 100644 --- a/bot_modules/messages.py +++ b/bot_modules/messages.py @@ -27,7 +27,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), table_name_field, bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), table_parent_id_field, diff --git a/bot_modules/mod_simple_message.py b/bot_modules/mod_simple_message.py index 40c78fd..1cc9621 100644 --- a/bot_modules/mod_simple_message.py +++ b/bot_modules/mod_simple_message.py @@ -72,6 +72,7 @@ class SimpleMessageModule(mod_interface.IModule): assert len(a_ButtonDesc) < 41 # Телеграм не поддерживает больше assert a_ButtonDesc[0] != ' ' # Телеграм не поддерживает пробелы в начале assert a_ButtonDesc[-1:] != ' ' # Телеграм не поддерживает пробелы в конце + # TODO добавить проверку, что все кнопки (a_ButtonDesc) разные btn = self.m_BotButtons.CreateMessage(f'{self.GetName()} {str(a_ButtonName).replace("ButtonNames.", "")}', a_ButtonDesc, self.m_Log.GetTimeNow()) return btn diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index 8705d8d..dd109b6 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -131,15 +131,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def GetEditKeyboardButtons(self, a_Message, a_UserGroups): mod_buttons = keyboard.MakeButtons(self.m_Bot, self.GetButtons(self.m_EditModuleNameList), a_UserGroups) - cur_buttons = [ - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.PHOTO)), user_access.AccessMode.VIEW, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.NAME)), user_access.AccessMode.ADD, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DESC)), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ACCESS)), user_access.AccessMode.DELETE, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.DEFAULT_ACCESS)), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.ADDRESS)), user_access.AccessMode.EDIT, self.GetAccess()), - keyboard.ButtonWithAccess(self.GetButton(EditButton(bd_table.TableFieldDestiny.STATUS)), user_access.AccessMode.EDIT, self.GetAccess()), - ] + cur_buttons = [] + for f in self.m_Table.GetFields(): + cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), user_access.AccessMode.EDIT, self.GetAccess()),] return mod_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) def GetViewItemInlineKeyboardTemplate(self, a_ItemID): @@ -173,18 +167,20 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): def UpdateMessage(self, a_Msg, a_Lang, a_Item): a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_Msg.GetDesc(), a_Item)) - photo_field = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PHOTO) - if photo_field: - a_Msg.UpdatePhotoID(a_Item[photo_field]) + photos = [] + field_id = 0 for f in self.m_Table.GetFields(): if f.m_Type == bd_table.TableFieldType.ENUM: for s in f.m_Enum: msg = self.GetMessage(EnumMessageForView(s)) if msg: a_Msg.UpdateDesc(a_Msg.GetDesc().replace(str(s), str(msg.GetMessageForLang(a_Lang).StaticCopy()))) + elif f.m_Type == bd_table.TableFieldType.PHOTO: + photos += [str(a_Item[field_id])] + field_id += 1 + a_Msg.UpdatePhotoID(','.join(photos)) return a_Msg - def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None): async def ShowMessage(a_CallbackQuery, a_Item): msg = a_Message.StaticCopy() @@ -307,7 +303,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_FieldName = a_Field.m_Name a_FieldType = bd_item.FieldType.text - if a_Field.m_Destiny == bd_table.TableFieldDestiny.PHOTO: + if a_Field.m_Type == bd_table.TableFieldType.PHOTO: a_FieldType = bd_item.FieldType.photo if not a_ButtonName or not a_EditMessage: diff --git a/bot_modules/needs.py b/bot_modules/needs.py index d180438..449f413 100644 --- a/bot_modules/needs.py +++ b/bot_modules/needs.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 227ea9f..82184a9 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -25,6 +25,7 @@ key_name = 'orderID' name_field = 'orderName' desc_field = 'orderDesc' photo_field = 'orderPhoto' +photo_pay_field = 'orderPhotoPay' status_field = 'orderStatus' address_field = 'orderAddress' access_field = 'orderAccess' @@ -35,7 +36,8 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), + bd_table.TableField(photo_pay_field, bd_table.TableFieldDestiny.PHOTO_PAY, bd_table.TableFieldType.PHOTO), bd_table.TableField(status_field, bd_table.TableFieldDestiny.STATUS, bd_table.TableFieldType.ENUM, a_Enum = OrderStatus), bd_table.TableField(address_field, bd_table.TableFieldDestiny.ADDRESS, bd_table.TableFieldType.STR), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), @@ -57,6 +59,7 @@ button_names = { ButtonNames.LIST_CURRENT: "📃 Список моих текущих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить фото оплаты моего заказа", mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе", @@ -110,6 +113,9 @@ messages = { mod_table_operate.Messages.SELECT_TO_EDIT: ''' Выберите заказ, который вы хотите отредактировать. ''', + mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO_PAY): ''' +Загрузите чек по оплате заказа (фото): +''', mod_table_operate.EditMessage(bd_table.TableFieldDestiny.PHOTO): ''' Загрузите новую обложку для заказа (Фото): Она будет отображаться в его описании. @@ -200,6 +206,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): a_ItemData[parent_id_field] = a_UserID a_ItemData[status_field] = str(OrderStatus.NEW) a_ItemData[address_field] = '' + a_ItemData[photo_pay_field] = '0' return super().AddBDItemFunc(a_ItemData, a_UserID) def GetStartKeyboardButtons(self, a_Message, a_UserGroups): diff --git a/bot_modules/projects.py b/bot_modules/projects.py index fb28514..8a601ee 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -22,7 +22,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), ]) diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index 39a3dfa..4234622 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -23,7 +23,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(key_name, bd_table.TableFieldDestiny.KEY, bd_table.TableFieldType.INT), bd_table.TableField(name_field, bd_table.TableFieldDestiny.NAME, bd_table.TableFieldType.STR), bd_table.TableField(desc_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), diff --git a/bot_modules/users.py b/bot_modules/users.py index 8b871ab..f56386c 100644 --- a/bot_modules/users.py +++ b/bot_modules/users.py @@ -29,7 +29,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(name2_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), bd_table.TableField(is_bot_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), bd_table.TableField(language_code_field, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldType.STR), - bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.STR), + bd_table.TableField(photo_field, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldType.PHOTO), bd_table.TableField(access_field, bd_table.TableFieldDestiny.ACCESS, bd_table.TableFieldType.STR), bd_table.TableField(create_datetime_field, bd_table.TableFieldDestiny.CREATE_DATE, bd_table.TableFieldType.STR), ]) diff --git a/bot_sys/aiogram_bot.py b/bot_sys/aiogram_bot.py index 6b4ccca..692c0a1 100644 --- a/bot_sys/aiogram_bot.py +++ b/bot_sys/aiogram_bot.py @@ -9,6 +9,16 @@ from aiogram.dispatcher import Dispatcher from aiogram.contrib.fsm_storage.memory import MemoryStorage from aiogram.utils import executor +def GetPhotoList(a_PhotoIDs): + if not a_PhotoIDs or a_PhotoIDs == 0: + return [] + photos = a_PhotoIDs.split(",") + result = [] + for p in photos: + if p != '0' and p != '': + result += [p] + return result + class AiogramBot(interfaces.IBot): def __init__(self, a_TelegramBotApiToken, a_BDFileName, a_RootIDs, a_Log): self.m_TelegramBotApiToken = a_TelegramBotApiToken @@ -39,19 +49,27 @@ class AiogramBot(interfaces.IBot): base_keyboards = [keyboard.MakeAiogramKeyboard(a_KeyboardButtons)] if inline_keyboards: base_keyboards = inline_keyboards - if a_PhotoIDs and a_PhotoIDs != 0 and a_PhotoIDs != '0': + photos = GetPhotoList(a_PhotoIDs) + if len(photos) > 0: + for p in photos[:-1]: + await self.m_TBot.send_photo( + a_UserID, + p, + '' + ) + p = photos[-1] if base_keyboards: for k in base_keyboards: await self.m_TBot.send_photo( a_UserID, - a_PhotoIDs, + p, a_Message, reply_markup = k ) else: await self.m_TBot.send_photo( a_UserID, - a_PhotoIDs, + p, a_Message ) else: diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index e09f4b4..d9c6bb9 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -9,12 +9,14 @@ class TableFieldType(Enum): INT = auto() STR = auto() ENUM = auto() + PHOTO = auto() def InitTableType(a_TableFieldType): types = { TableFieldType.INT: 'INTEGER', TableFieldType.STR: 'TEXT', TableFieldType.ENUM: 'TEXT', + TableFieldType.PHOTO: 'TEXT', } return types.get(a_TableFieldType, None) @@ -24,6 +26,7 @@ class TableFieldDestiny(Enum): NAME = auto() DESC = auto() PHOTO = auto() + PHOTO_PAY = auto() ACCESS = auto() DEFAULT_ACCESS = auto() CREATE_DATE = auto() -- 2.11.0 From aa3fb3351a00605727ecd17614280cc5a2c6f64a Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 14:57:33 +0300 Subject: [PATCH 13/15] =?UTF-8?q?=D0=92=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=81=D0=B5=D1=85=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=20=D0=BE=D0=B1=D0=BE=D1=82=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20id=20=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/all_orders.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py index a98b0df..c42a249 100644 --- a/bot_modules/all_orders.py +++ b/bot_modules/all_orders.py @@ -76,7 +76,7 @@ messages.update(cur_messages) def GetCurItemsTemplate(a_Bot, a_TableName, a_StatusFieldName): def GetBDItems(a_Message, a_UserGroups, a_ParentID): request = f'SELECT * FROM {a_TableName} WHERE {a_StatusFieldName} != ?' - return a_Bot.SQLRequest(request, param = ([user_id, str(OrderStatus.FINISH)])) + return a_Bot.SQLRequest(request, param = ([str(orders.OrderStatus.FINISH)])) return GetBDItems def GetBDItemsForUserTemplate(a_Bot, a_TableName): @@ -116,3 +116,7 @@ class ModuleAllOrders(orders.ModuleOrders): 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, a_OnlyCurrent = True) + def GetButtonNameAndKeyValueAndAccess(self, a_Item): + parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID) + n, k, a = super().GetButtonNameAndKeyValueAndAccess(a_Item) + return n + ":" + str(a_Item[parent_field_id]), k, a -- 2.11.0 From e0f005f68a1ebdd0962e5bea3112c10dd557ba8a Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 16:04:48 +0300 Subject: [PATCH 14/15] =?UTF-8?q?=D0=97=D0=B0=D0=BA=D0=B0=D0=B7=D1=8B=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E=D1=82=20=D1=82=D0=BE?= =?UTF-8?q?=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=81=20=D1=82=D0=B5=D0=BA=D1=83?= =?UTF-8?q?=D1=89=D0=B8=D0=BC=D0=B8=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/all_orders.py | 10 +++++----- bot_modules/orders.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py index c42a249..f7de343 100644 --- a/bot_modules/all_orders.py +++ b/bot_modules/all_orders.py @@ -25,8 +25,8 @@ button_names.pop(mod_table_operate.ButtonNames.ADD) cur_button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Все заказы", - mod_table_operate.ButtonNames.LIST: "📃 Список всех заказов", - orders.ButtonNames.LIST_CURRENT: "📃 Список текущих заказов", + mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", + orders.ButtonNames.LIST_ALL: "📃 Список всех заказов", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в заказе", @@ -110,11 +110,11 @@ class ModuleAllOrders(orders.ModuleOrders): 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) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = True) - def SelectSourceForCurrentTemplate(self, a_PrevPrefix, a_ButtonName): + def SelectSourceForAllTemplate(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, a_OnlyCurrent = True) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) def GetButtonNameAndKeyValueAndAccess(self, a_Item): parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID) diff --git a/bot_modules/orders.py b/bot_modules/orders.py index 82184a9..a19209e 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -51,12 +51,12 @@ init_access = f'{user_access.user_access_group_new}=va' # Сообщения и кнопки class ButtonNames(Enum): - LIST_CURRENT = auto() + LIST_ALL = auto() button_names = { mod_simple_message.ButtonNames.START: "‍🛒 Заказы", - mod_table_operate.ButtonNames.LIST: "📃 Список всех моих заказов", - ButtonNames.LIST_CURRENT: "📃 Список моих текущих заказов", + mod_table_operate.ButtonNames.LIST: "📃 Список моих текущих заказов", + ButtonNames.LIST_ALL: "📃 Список всех моих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ", mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить фото оплаты моего заказа", @@ -195,11 +195,11 @@ class ModuleOrders(mod_table_operate.TableOperateModule): 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) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName, a_OnlyCurrent = True) - def SelectSourceForCurrentTemplate(self, a_PrevPrefix, a_ButtonName): + def SelectSourceForAllTemplate(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, a_OnlyCurrent = True) + return DBItemForUserSelectSource(self.m_Bot, self.m_Table.GetName(), parent_id_field, a_PrevPrefix, a_ButtonName) def AddBDItemFunc(self, a_ItemData, a_UserID): parent_id_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PARENT_ID) @@ -212,7 +212,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): def GetStartKeyboardButtons(self, a_Message, a_UserGroups): parent_buttons = super().GetStartKeyboardButtons(a_Message, a_UserGroups) cur_buttons = [ - keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST_CURRENT), user_access.AccessMode.VIEW, self.GetAccess()), + keyboard.ButtonWithAccess(self.GetButton(ButtonNames.LIST_ALL), user_access.AccessMode.VIEW, self.GetAccess()), ] return parent_buttons + keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) @@ -229,12 +229,12 @@ class ModuleOrders(mod_table_operate.TableOperateModule): default_keyboard_func = self.m_GetStartKeyboardButtonsFunc - # Список текущих, открытых заказов - a_ButtonName = self.GetButton(ButtonNames.LIST_CURRENT) + # Список всех заказов + a_ButtonName = self.GetButton(ButtonNames.LIST_ALL) if a_ButtonName: a_Prefix = self.RegisterSelect(a_ButtonName, user_access.AccessMode.VIEW, only_parent = True) a_Prefix = bd_item_select.SelectRegisterHandlers(self.m_Bot,\ - self.SelectSourceForCurrentTemplate(a_Prefix, a_ButtonName), \ + self.SelectSourceForAllTemplate(a_Prefix, a_ButtonName), \ GetButtonNameAndKeyValueAndAccess,\ self.GetMessage(mod_table_operate.Messages.SELECT),\ GetAccess,\ -- 2.11.0 From 775c03d57477f2d2ce5b2b6171f155d007586c2c Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 31 May 2023 18:15:50 +0300 Subject: [PATCH 15/15] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=B2=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B5=D0=B9?= =?UTF-8?q?=D1=88=D0=B5=D0=BC=20=D0=B2=D0=B8=D0=B4=D0=B5=20=D0=BE=D0=BF?= =?UTF-8?q?=D0=BE=D0=B2=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=B9=20=D0=BE=D0=B1=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=B0=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot_modules/all_orders.py | 42 ++++++++++++++++++++++++++++++++++++++- bot_modules/mod_table_operate.py | 29 ++++++++++++++++++--------- bot_modules/orders.py | 6 +++--- bot_sys/bot_subscribes.py | 43 ++++++++++++++++++++++++++++++++++++++++ template/bd_item_add.py | 2 +- template/bd_item_edit.py | 4 ++-- 6 files changed, 110 insertions(+), 16 deletions(-) create mode 100644 bot_sys/bot_subscribes.py diff --git a/bot_modules/all_orders.py b/bot_modules/all_orders.py index f7de343..2c1b30b 100644 --- a/bot_modules/all_orders.py +++ b/bot_modules/all_orders.py @@ -7,7 +7,6 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table from bot_modules import mod_table_operate, mod_simple_message, orders from template import bd_item_select, bd_item_view, bd_item - # --------------------------------------------------------- # БД module_name = 'all_orders' @@ -28,6 +27,7 @@ cur_button_names = { mod_table_operate.ButtonNames.LIST: "📃 Список текущих заказов", orders.ButtonNames.LIST_ALL: "📃 Список всех заказов", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать заказ", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить чек по оплате заказа", mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в заказе", @@ -70,7 +70,19 @@ cur_messages = { ''', } +messages_notification = { + mod_table_operate.NotificationMessage(orders.OrderStatus.NEW): f'''Статус заказа "#{orders.name_field}" изменён на - ожидает модерации''', + mod_table_operate.NotificationMessage(orders.OrderStatus.PAY): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ ожидает оплаты. + +Оплатите заказ и прикрепите чек об оплате к заказу. Для этого проследуйте по пути "Заказы"->"Редактировать мой заказ"->"Загрузить чек по оплате моего заказа"''', + mod_table_operate.NotificationMessage(orders.OrderStatus.ADDRESS): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ ожидает указания адреса доставки. + +Для этого проследуйте по пути "Заказы"->"Редактировать мой заказ"->"Изменить адрес в моём заказе"''', + mod_table_operate.NotificationMessage(orders.OrderStatus.FINISH): f'''Статус заказа "#{orders.name_field}" изменён на - Заказ выполнен''', +} + messages.update(orders.messages_order_status) +messages.update(messages_notification) messages.update(cur_messages) def GetCurItemsTemplate(a_Bot, a_TableName, a_StatusFieldName): @@ -120,3 +132,31 @@ class ModuleAllOrders(orders.ModuleOrders): parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID) n, k, a = super().GetButtonNameAndKeyValueAndAccess(a_Item) return n + ":" + str(a_Item[parent_field_id]), k, a + + async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID): + if a_Field.m_Destiny == bd_table.TableFieldDestiny.STATUS: + key_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.KEY) + item = bd_item.GetBDItemsTemplate(self.m_Bot, self.m_Table.GetName(), key_field)(a_ItemID) + if len(item) < 1: + self.m_Log.Error(f'Не удалось оповестить по заказу №{a_ItemID}.') + return + + item = item[0] + parent_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.PARENT_ID) + status_field_id = self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.STATUS) + print('OnChangeField', item, parent_field_id, status_field_id) + owner_id = item[parent_field_id] + new_status = item[status_field_id] + msg = self.GetMessage(mod_table_operate.NotificationMessage(new_status)) + if not msg: + self.m_Log.Error(f'Не удалось оповестить по заказу №{a_ItemID}. Пустое сообщение для нового статуса {new_status}') + return + msg = self.UpdateMessage(msg, None, item) + await self.m_Bot.SendMessage( + owner_id, + msg.GetDesc(), + msg.GetPhotoID(), + None, + None + ) + diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index dd109b6..f1a3347 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -28,6 +28,9 @@ def CreateMessage(a_BDTableDestiny): def EnumMessageForView(a_EnumItem): return 'enum ' + str(a_EnumItem) +def NotificationMessage(a_EnumItem): + return 'notification ' + str(a_EnumItem) + class ButtonNames(Enum): LIST = auto() ADD = auto() @@ -107,8 +110,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return await self.PostDelete(a_CallbackQuery, a_ItemID) self.m_PostDeleteFunc = PostDelete - def AddBDItemFunc(a_ItemData, a_UserID): - return self.AddBDItemFunc(a_ItemData, a_UserID) + async def AddBDItemFunc(a_ItemData, a_UserID): + return await self.AddBDItemFunc(a_ItemData, a_UserID) self.m_AddBDItemFunc = AddBDItemFunc def GetFSM(self, a_FSMName): @@ -133,7 +136,10 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): mod_buttons = keyboard.MakeButtons(self.m_Bot, self.GetButtons(self.m_EditModuleNameList), a_UserGroups) cur_buttons = [] for f in self.m_Table.GetFields(): - cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EditButton(f.m_Destiny)), user_access.AccessMode.EDIT, self.GetAccess()),] + access = user_access.AccessMode.EDIT + if f.m_Destiny == bd_table.TableFieldDestiny.ACCESS or f.m_Destiny == bd_table.TableFieldDestiny.DEFAULT_ACCESS: + access = user_access.AccessMode.ACCEES_EDIT + 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 GetViewItemInlineKeyboardTemplate(self, a_ItemID): @@ -165,7 +171,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_Item[key_name_id],\ a_Item[access_field_id] - def UpdateMessage(self, a_Msg, a_Lang, a_Item): + def UpdateMessage(self, a_Msg, a_Lang, a_Item, a_EnablePhoto = False): a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTags(a_Msg.GetDesc(), a_Item)) photos = [] field_id = 0 @@ -178,10 +184,11 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): elif f.m_Type == bd_table.TableFieldType.PHOTO: photos += [str(a_Item[field_id])] field_id += 1 - a_Msg.UpdatePhotoID(','.join(photos)) + if a_EnablePhoto: + a_Msg.UpdatePhotoID(','.join(photos)) return a_Msg - def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None): + def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None, a_EnablePhoto = False): async def ShowMessage(a_CallbackQuery, a_Item): msg = a_Message.StaticCopy() # TODO: добавить поддержку языка в a_MessageName @@ -213,7 +220,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): self.OnChange() return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE)) - def AddBDItemFunc(self, a_ItemData, a_UserID): + async def AddBDItemFunc(self, a_ItemData, a_UserID): table_name = self.m_Table.GetName() name_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.NAME) photo_field = self.m_Table.GetFieldNameByDestiny(bd_table.TableFieldDestiny.PHOTO) @@ -297,6 +304,9 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return PostProccessing return None + async def OnChangeField(self, a_Field, a_ItemID, a_ItemData, a_EditUserID): + pass + 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)) @@ -309,7 +319,8 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): if not a_ButtonName or not a_EditMessage: return - def OnChange(): + async def OnChange(a_ItemID, a_ItemData, a_EditUserID): + await self.OnChangeField(a_Field, a_ItemID, a_ItemData, a_EditUserID) return self.OnChange() table_name = self.m_Table.GetName() @@ -381,7 +392,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_Prefix,\ table_name,\ key_name,\ - self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate),\ + self.ShowMessageTemplate(self.GetMessage(Messages.OPEN), GetViewItemInlineKeyboardTemplate, a_EnablePhoto = True),\ GetAccess,\ defaul_keyboard_func,\ access_mode = user_access.AccessMode.VIEW\ diff --git a/bot_modules/orders.py b/bot_modules/orders.py index a19209e..e534a34 100644 --- a/bot_modules/orders.py +++ b/bot_modules/orders.py @@ -45,7 +45,7 @@ table = bd_table.Table(table_name, [ bd_table.TableField(parent_id_field, bd_table.TableFieldDestiny.PARENT_ID, bd_table.TableFieldType.INT), ]) -init_access = f'{user_access.user_access_group_new}=va' +init_access = f'{user_access.user_access_group_new}=vea' # --------------------------------------------------------- # Сообщения и кнопки @@ -59,7 +59,7 @@ button_names = { ButtonNames.LIST_ALL: "📃 Список всех моих заказов", mod_table_operate.ButtonNames.ADD: "✅ Добавить заказ", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать мой заказ", - mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить фото оплаты моего заказа", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO_PAY): "☐ Загрузить чек по оплате моего заказа", mod_table_operate.EditButton(bd_table.TableFieldDestiny.PHOTO): "☐ Изменить изображение в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.NAME): "≂ Изменить название в моём заказе", mod_table_operate.EditButton(bd_table.TableFieldDestiny.DESC): "𝌴 Изменить описание в моём заказе", @@ -244,7 +244,7 @@ class ModuleOrders(mod_table_operate.TableOperateModule): a_Prefix,\ table_name,\ key_name,\ - self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.OPEN),GetViewItemInlineKeyboardTemplate),\ + self.ShowMessageTemplate(self.GetMessage(mod_table_operate.Messages.OPEN),GetViewItemInlineKeyboardTemplate, a_EnablePhoto = True),\ GetAccess,\ default_keyboard_func,\ access_mode = user_access.AccessMode.VIEW\ diff --git a/bot_sys/bot_subscribes.py b/bot_sys/bot_subscribes.py new file mode 100644 index 0000000..523fe94 --- /dev/null +++ b/bot_sys/bot_subscribes.py @@ -0,0 +1,43 @@ +#-*-coding utf-8-*- +# Общественное достояние, 2023, Алексей Безбородов (Alexei Bezborodov) + +# Работа с подписками + +from enum import Enum +from enum import auto + +# Тип поля в таблице +class SubscribeType(Enum): + ADD = auto() + ANY_ITEM_DEL = auto() + ANY_ITEM_EDIT = auto() + ITEM_DEL = auto() + ITEM_EDIT = auto() + +class BotSubscribes + def __init__(self): + self.Clear() + + def GetSubscribes(self): + return self.m_Subscribes + + def Clear(self): + self.m_Subscribes = {} + + def CheckSubscribe(self, a_UserID, a_ModuleName, a_Type, a_ItemID = -1): + s = self.GetSubscribes() + su = s.get(a_UserID, None) + if su: + sub_um = su.get(a_ModuleName, None) + if sub_um: + t = su.get(a_ItemID, None) + return t + return None + + def AddSubscribe(self, a_UserID, a_ModuleName, a_Type, a_ItemID = -1): + s = self.GetSubscribes() + if not s.get(a_UserID, None): + s[a_UserID] = {} + if not s[a_UserID].get(a_ModuleName, None): + s[a_UserID][a_ModuleName] = {} + s[a_UserID][a_ModuleName][a_ItemID] = a_Type diff --git a/template/bd_item_add.py b/template/bd_item_add.py index 373bac3..54c6960 100644 --- a/template/bd_item_add.py +++ b/template/bd_item_add.py @@ -90,7 +90,7 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa field_value = result item_data[a_FieldName] = field_value if a_Finish: - res, error = a_AddBDItemFunc(item_data, user_id) + res, error = await a_AddBDItemFunc(item_data, user_id) await state_func() if error: return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(error)) diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index 8b85a66..9e877e7 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -19,7 +19,7 @@ def StartEditBDItemTemplate(a_Bot, a_FSM, a_MessageFunc, a_TableName, a_KeyName, return bd_item_add.StartAddBDItemTemplate(a_Bot, a_FSM, a_FSM.item_field, a_MessageFunc, a_TableName, a_KeyName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = access_mode) def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, a_OnChangeFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): - def EditBDItemFunc(a_ItemData, a_UserID): + async def EditBDItemFunc(a_ItemData, a_UserID): item_id = a_ItemData[a_KeyName] field_value = a_ItemData[a_FieldName] res, error = bd_item.EditBDItemInTableTemplate(a_Bot, a_TableName, a_KeyName, a_FieldName)(item_id, field_value) @@ -28,7 +28,7 @@ def FinishEditBDItemTemplate(a_Bot, a_FSM, a_TableName, a_KeyName, a_FieldName, else: a_Bot.GetLog().Success(f'Пользователь {a_UserID} изменил поле в таблице {a_TableName} ключу {a_KeyName}={item_id}. Новое значение поля {a_FieldName}={field_value}.') - a_OnChangeFunc() + await a_OnChangeFunc(item_id, a_ItemData, a_UserID) return res, error return bd_item_add.FinishAddBDItemTemplate(a_Bot, a_FSM, EditBDItemFunc, a_TableName, a_KeyName, a_FieldName, a_MessageFunc, a_PostProcessFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode, field_type = field_type) -- 2.11.0