From d7ea8ecd756f4c62e24f4ac4c02cf18cc7191d3a Mon Sep 17 00:00:00 2001 From: Alexei Date: Fri, 13 Oct 2023 20:54:52 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D1=82=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BE=D0=B3=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F=20=D0=B4=D0=BE=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auth_docs/test_doc.odt | 51 ++++++++++++++++++++++++++-------------- bot_modules/authorize.py | 38 ++++++++++++++++++------------ bot_modules/mod_table_operate.py | 48 +++++++++++++++++++++++++++++++------ bot_modules/subscribes.py | 7 ------ bot_sys/bd_table.py | 7 ++++++ template/bd_item.py | 2 +- template/bd_item_add.py | 4 ++-- 7 files changed, 107 insertions(+), 50 deletions(-) diff --git a/auth_docs/test_doc.odt b/auth_docs/test_doc.odt index 6047b4a..abc5c88 100644 --- a/auth_docs/test_doc.odt +++ b/auth_docs/test_doc.odt @@ -1,7 +1,7 @@ - 2023-10-08T23:17:27.894126099PT46S2LibreOffice/7.3.6.2$Linux_X86_64 LibreOffice_project/30$Build-2 + 2023-10-13T15:56:51.616305329PT1M19S4LibreOffice/7.3.6.2$Linux_X86_64 LibreOffice_project/30$Build-2 0 @@ -13,8 +13,8 @@ view2 - 22826 - 5909 + 18221 + 3475 0 0 35586 @@ -88,7 +88,7 @@ true true - 820887 + 918403 true false @@ -149,7 +149,7 @@ - + @@ -184,52 +184,52 @@ - + - + - + - + - + - + - + - + - + - + @@ -240,16 +240,22 @@ + + + - + + + + - + @@ -260,13 +266,22 @@ - bd_table.TableFieldDestiny.USER_NAME: user_access.AccessMode.NONE, + + + bd_table.TableFieldDestiny.USER_NAME: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_FAMILY_NAME: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_MIDDLE_NAME: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_BIRTHDAY: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_ADDRESS: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_CONTACTS: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.USER_CONFIRM: user_access.AccessMode.NONE, + bd_table.TableFieldDestiny.ACCESS: user_access.AccessMode.NONE, diff --git a/bot_modules/authorize.py b/bot_modules/authorize.py index e2f515e..e7250d4 100644 --- a/bot_modules/authorize.py +++ b/bot_modules/authorize.py @@ -5,7 +5,7 @@ from bot_sys import bot_bd, keyboard, user_access, bd_table, bot_subscribes, config from bot_modules import mod_table_operate, mod_simple_message -from template import docs_message +from template import docs_message, bd_item from enum import Enum from enum import auto @@ -69,16 +69,19 @@ button_names = { mod_table_operate.ButtonNames.ADD: "📨 Заявка на вступление", ButtonNames.LIST_AUTH_DOCS: "📨 Регистрационные документы", mod_table_operate.ButtonNames.EDIT: "🛠 Редактировать свои данные", - bd_table.TableFieldDestiny.USER_ID): "☐ Изменить id пользователя", - bd_table.TableFieldDestiny.USER_NAME): "☐ Изменить имя пользователя", - bd_table.TableFieldDestiny.USER_FAMILY_NAME): "☐ Изменить фамилию пользователя", - bd_table.TableFieldDestiny.USER_MIDDLE_NAME): "☐ Изменить отчество пользователя", - bd_table.TableFieldDestiny.USER_BIRTHDAY): "☐ Изменить дату рождения пользователя", - bd_table.TableFieldDestiny.USER_ADDRESS): "☐ Изменить адрес пользователя", - bd_table.TableFieldDestiny.USER_CONTACTS): "☐ Изменить контакты пользователя", - bd_table.TableFieldDestiny.USER_CONFIRM): "☐ Изменить подтверждение пользователя", -# bd_table.TableFieldDestiny.USER_ID): "☐ Изменить id пользователя", - bd_table.TableFieldDestiny.ACCESS): "✋ Доступ к авторизации пользователя", mod_table_operate.ButtonNames.DEL: "❌ Удалить авторизацию пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_ID): "☐ Изменить id пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_NAME): "☐ Изменить имя пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_FAMILY_NAME): "☐ Изменить фамилию пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_MIDDLE_NAME): "☐ Изменить отчество пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_BIRTHDAY): "☐ Изменить дату рождения пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_ADDRESS): "☐ Изменить адрес пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_CONTACTS): "☐ Изменить контакты пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_CONFIRM): "☐ Изменить подтверждение пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.USER_ID): "☐ Изменить id пользователя", + mod_table_operate.EditButton(bd_table.TableFieldDestiny.ACCESS): "✋ Доступ к авторизации пользователя", + mod_table_operate.ButtonNames.DEL: "❌ Удалить авторизацию пользователя", + mod_table_operate.EnumButton(ConfirmStatus.YES): "Да, все данные верны", + mod_table_operate.EnumButton(ConfirmStatus.NO): "Нет, данные не верны", } class Messages(Enum): @@ -145,7 +148,7 @@ messages = { Введите свои контакты: ''', - mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.USER_CONFIRM): ''' + mod_table_operate.CreateMessage(bd_table.TableFieldDestiny.USER_CONFIRM): f''' Авторизация. Шаг №7 Имя: #{user_name_field} @@ -233,12 +236,12 @@ messages_subscribes = { messages.update(messages_subscribes) -messages_order_status = { +messages_confirm_status = { mod_table_operate.EnumMessageForView(ConfirmStatus.YES): f'''Да, все данные верны''', mod_table_operate.EnumMessageForView(ConfirmStatus.NO): f'''Нет, данные не верны''', } -messages.update(messages_order_status) +messages.update(messages_confirm_status) class ModuleAuthorize(mod_table_operate.TableOperateModule): def __init__(self, a_ParentModName, a_ChildModName, a_ChildModuleNameList, a_EditModuleNameList, a_Bot, a_ModuleAgregator, a_BotMessages, a_BotButtons, a_BotSubscribes, a_Log): @@ -301,7 +304,7 @@ class ModuleAuthorize(mod_table_operate.TableOperateModule): button_name = self.GetButton(ButtonNames.LIST_AUTH_DOCS) if button_name: self.m_Bot.RegisterMessageHandler( - docs_message.BackupFileTemplate( + docs_message.DocFilesTemplate( self.m_Bot, GetFilesFunc, self.GetMessage(Messages.LIST_AUTH_DOCS), @@ -314,6 +317,11 @@ class ModuleAuthorize(mod_table_operate.TableOperateModule): bd_item.GetCheckForTextFunc(button_name) ) + def AddBDItemFunc(self, a_ItemData, a_UserID): + a_ItemData[user_id_field] = a_UserID + #a_ItemData[address_field] = '' + return super().AddBDItemFunc(a_ItemData, a_UserID) + def GetReplaceDictFunc(a_Bot, a_user_id): item = GetAuthorizeItem(self.m_Bot, user_id) if not item: diff --git a/bot_modules/mod_table_operate.py b/bot_modules/mod_table_operate.py index e927b0d..2fc8a8d 100644 --- a/bot_modules/mod_table_operate.py +++ b/bot_modules/mod_table_operate.py @@ -185,12 +185,32 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): a_Msg.UpdatePhotoID(','.join(photos)) return a_Msg + def UpdateMessageByDict(self, a_Msg, a_Lang, a_ItemDict, a_EnablePhoto = False): + a_Msg.UpdateDesc(self.m_Table.ReplaceAllFieldTagsByDict(a_Msg.GetDesc(), a_ItemDict)) + photos = [] + 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: + if f.m_Name in a_ItemDict: + photos += [str(a_ItemDict[f.m_Name])] + if a_EnablePhoto: + a_Msg.UpdatePhotoID(','.join(photos)) + return a_Msg + def ShowMessageTemplate(self, a_Message, Inline_keyboard_template_func = None, a_EnablePhoto = False): - async def ShowMessage(a_CallbackQuery, a_Item): + async def ShowMessage(a_CallbackQuery, a_Item, a_ItemDict): msg = a_Message.StaticCopy() # TODO: добавить поддержку языков в a_MessageName Inline_keyboard_func = None item_access = None + if a_ItemDict: + lang = str(a_CallbackQuery.from_user.language_code) + msg = msg.GetMessageForLang(lang).StaticCopy() + msg = self.UpdateMessageByDict(msg, lang, a_ItemDict, a_EnablePhoto = a_EnablePhoto) if a_Item: if len(a_Item) < self.m_Table.GetFieldsCount() - 1: # Для проектов это нужно. Там на 1 меньше поле. TODO разделить отправку сообщений item_access и Inline_keyboard_func return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND)) @@ -207,7 +227,7 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): async def PreDelete(self, a_CallbackQuery, a_Item): if len(a_Item) < self.m_Table.GetFieldsCount(): - return simple_message.WorkFuncResult(error_find_proj_message) + return simple_message.WorkFuncResult(self.GetMessage(Messages.ERROR_FIND)) access = a_Item[self.m_Table.GetFieldIDByDestiny(bd_table.TableFieldDestiny.ACCESS)] return simple_message.WorkFuncResult(self.GetMessage(Messages.SUCCESS_DELETE), None, item_access = access) @@ -312,12 +332,12 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): return a_Prefix - def AdditionalKeyboardForEditTemplate(self, a_Field): + def AdditionalKeyboardForEditTemplate(self, a_Field, user_access = user_access.AccessMode.EDIT): 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()),] + cur_buttons += [keyboard.ButtonWithAccess(self.GetButton(EnumButton(s)), user_access, self.GetAccess()),] return keyboard.MakeButtons(self.m_Bot, cur_buttons, a_UserGroups) return KeyboardButtons return None @@ -386,9 +406,23 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): ) def GetAddFields(self): + good_destiny = ( + bd_table.TableFieldDestiny.NAME, + bd_table.TableFieldDestiny.DESC, + bd_table.TableFieldDestiny.PHOTO, + bd_table.TableFieldDestiny.SUBSCRIBE_TYPE, + bd_table.TableFieldDestiny.ITEM_ID, + bd_table.TableFieldDestiny.USER_NAME, + bd_table.TableFieldDestiny.USER_FAMILY_NAME, + bd_table.TableFieldDestiny.USER_MIDDLE_NAME, + bd_table.TableFieldDestiny.USER_BIRTHDAY, + bd_table.TableFieldDestiny.USER_ADDRESS, + bd_table.TableFieldDestiny.USER_CONTACTS, + bd_table.TableFieldDestiny.USER_CONFIRM, + ) fields = [] for f in self.m_Table.GetFields(): - if f.m_Destiny in (bd_table.TableFieldDestiny.NAME, bd_table.TableFieldDestiny.DESC, bd_table.TableFieldDestiny.PHOTO, bd_table.TableFieldDestiny.SUBSCRIBE_TYPE, bd_table.TableFieldDestiny.ITEM_ID, ): + if f.m_Destiny in good_destiny: fields += [f] return fields @@ -422,13 +456,13 @@ class TableOperateModule(mod_simple_message.SimpleMessageModule): f_id = 0 f = fields[f_id] - keyboard = bd_item.MixKeyboardFuncTemplate(self.AdditionalKeyboardForEditTemplate(f), GetKeyboard(f)) + keyboard = bd_item.MixKeyboardFuncTemplate(self.AdditionalKeyboardForEditTemplate(f, user_access.AccessMode.ADD), GetKeyboard(f)) reg_func(bd_item_add.StartAddBDItemTemplate(self.m_Bot, fsm, getattr(fsm, f'item{f_id}'), self.ShowMessageTemplate(self.GetMessage(CreateMessage(f.m_Destiny))), a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard, a_ButtonFunc, access_mode), a_StartCheckFunc) for i in range(len(fields) - 1): f = fields[i] next_f = fields[i + 1] - keyboard = bd_item.MixKeyboardFuncTemplate(self.AdditionalKeyboardForEditTemplate(next_f), GetKeyboard(next_f)) + keyboard = bd_item.MixKeyboardFuncTemplate(self.AdditionalKeyboardForEditTemplate(next_f, user_access.AccessMode.ADD), GetKeyboard(next_f)) self.m_Bot.RegisterMessageHandler(bd_item_add.NextAddBDItemTemplate(self.m_Bot, fsm, None, a_ParentTableName, a_ParentKeyFieldName, f.m_Name, self.ShowMessageTemplate(self.GetMessage(CreateMessage(next_f.m_Destiny))), None, a_AccessFunc, keyboard, a_ButtonFunc, access_mode, field_type = GetFieldType(f)), content_types = GetContentTypes(f), state = getattr(fsm, f'item{i}')) f_id = len(fields) - 1 diff --git a/bot_modules/subscribes.py b/bot_modules/subscribes.py index 84c2715..a807b8d 100644 --- a/bot_modules/subscribes.py +++ b/bot_modules/subscribes.py @@ -154,13 +154,6 @@ messages_subs_type_status = { messages.update(messages_subs_type_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} != ?' - 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) diff --git a/bot_sys/bd_table.py b/bot_sys/bd_table.py index b5b98d6..2af2e98 100644 --- a/bot_sys/bd_table.py +++ b/bot_sys/bd_table.py @@ -111,6 +111,13 @@ class Table: result = result.replace(f'#{f.m_Name}', str(a_BDItem[i])) return result + def ReplaceAllFieldTagsByDict(self, a_String, a_BDItemDict): + result = a_String + for f in self.m_Fields: + if f.m_Name in a_BDItemDict: + result = result.replace(f'#{f.m_Name}', str(a_BDItemDict[f.m_Name])) + return result + class Status(Enum): NEW = auto() FINISH = auto() diff --git a/template/bd_item.py b/template/bd_item.py index 5a08a84..8cc9783 100644 --- a/template/bd_item.py +++ b/template/bd_item.py @@ -100,7 +100,7 @@ def CheckAccessBDItemTemplate(a_Bot, a_TableName, a_KeyName, a_KeyValue, a_WorkF a_Bot.GetLog().Error(msg) return simple_message.WorkFuncResult(bot_messages.MakeBotMessage(msg)), None - result_work_func = await a_WorkFunc(a_CallbackQuery, item[0]) + result_work_func = await a_WorkFunc(a_CallbackQuery, item[0], None) if result_work_func is None or result_work_func.m_BotMessage is None: return result_work_func, result_work_func diff --git a/template/bd_item_add.py b/template/bd_item_add.py index 54c6960..e52ae4c 100644 --- a/template/bd_item_add.py +++ b/template/bd_item_add.py @@ -30,7 +30,7 @@ def StartAddBDItemTemplate(a_Bot, a_FSM, a_FSMStart, a_MessageFunc, a_ParentTabl if parent_id: check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_Bot, a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery) else: - res_of_work_func = await a_MessageFunc(a_CallbackQuery, None) + res_of_work_func = await a_MessageFunc(a_CallbackQuery, None, item_data) if not check is None: await state.finish() @@ -68,7 +68,7 @@ def FinishOrNextAddBDItemTemplate(a_Bot, a_FSM, a_AddBDItemFunc, a_ParentTableNa if parent_id: check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_Bot, a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message) else: - res_of_work_func = await a_MessageFunc(a_Message, None) + res_of_work_func = await a_MessageFunc(a_Message, None, item_data) if not check is None: await state_func()