diff --git a/bot_modules/projects.py b/bot_modules/projects.py index e210910..0c53e24 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -184,14 +184,8 @@ def GetStartProjectKeyboardButtons(a_Message, a_UserGroups): # --------------------------------------------------------- # Обработка сообщений -select_handler = 0 # стартовое сообщение async def ProjectsOpen(a_Message : types.message, state = None): - #user_id = str(a_Message.from_user.id) - #user_groups = groups.GetUserGroupData(user_id) - #await a_Message.answer(base_project_message, reply_markup = GetStartProjectKeyboardButtons(a_Message, user_groups)) - #await select_handler(a_Message) - #return None return simple_message.WorkFuncResult(base_project_message) def GetButtonNameAndKeyValueAndAccess(a_Item): @@ -262,8 +256,7 @@ def RegisterHandlers(dp : Dispatcher): # Список проектов dp.register_message_handler(simple_message.SimpleMessageTemplate(ProjectsOpen, defaul_keyboard_func, GetAccess), text = projects_button_name) - global select_handler - select_handler = bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func) + bd_item_view.FirstSelectAndShowBDItemRegisterHandlers(dp, list_project_button_name, table_name, key_name, ShowMessageTemplate(project_open_message), GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func) # Удаление проекта bd_item_delete.DeleteBDItemRegisterHandlers(dp, None, bd_item.GetCheckForTextFunc(del_project_button_name), table_name, key_name, None, ProjectPreDelete, ProjectPostDelete, GetButtonNameAndKeyValueAndAccess, select_project_message, GetAccess, defaul_keyboard_func) diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index 40bf62f..cfe9e33 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -104,7 +104,7 @@ task_create_photo_message = ''' Создание задачи. Шаг №3 Загрузите обложку для задачи (Фото): -Она будет отображаться в его описании. +Она будет отображаться в её описании. ''' task_success_create_message = '''✅ Задача успешно добавлена!''' @@ -264,21 +264,50 @@ def RegisterHandlers(dp : Dispatcher): defaul_keyboard_func = GetStartTaskKeyboardButtons def RegisterSelectParent(a_ButtonName, access_mode): a_PrefixBase = a_ButtonName - return bd_item_select.FirstSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = access_mode) + return bd_item_select.FirstSelectBDItemRegisterHandlers(dp, \ + a_PrefixBase, \ + a_ButtonName, \ + projects.table_name, \ + projects.key_name, \ + projects.GetButtonNameAndKeyValueAndAccess, \ + projects.select_project_message, \ + projects.GetAccess, access_mode = access_mode\ + ) # Стартовое сообщение dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name) # Список задач - a_Prefix, sel_handler = RegisterSelectParent(list_task_button_name, user_access.AccessMode.VIEW) - bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, a_Prefix, parent_id_field, table_name, key_name, ShowMessageTemplate(task_open_message), GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func, access_mode = user_access.AccessMode.VIEW) + a_Prefix = RegisterSelectParent(list_task_button_name, user_access.AccessMode.VIEW) + bd_item_view.LastSelectAndShowBDItemRegisterHandlers(dp, \ + a_Prefix, parent_id_field, \ + table_name, key_name, \ + ShowMessageTemplate(task_open_message), \ + GetButtonNameAndKeyValueAndAccess, \ + select_task_message, \ + GetAccess, \ + defaul_keyboard_func, \ + access_mode = user_access.AccessMode.VIEW\ + ) # Удаление задачи - a_Prefix, sel_handler = RegisterSelectParent(del_task_button_name, user_access.AccessMode.DELETE) - bd_item_delete.DeleteBDItemRegisterHandlers(dp, a_Prefix, bd_item.GetCheckForPrefixFunc(a_Prefix), table_name, key_name, parent_id_field, TaskPreDelete, TaskPostDelete, GetButtonNameAndKeyValueAndAccess, select_task_message, GetAccess, defaul_keyboard_func) + a_Prefix = RegisterSelectParent(del_task_button_name, user_access.AccessMode.DELETE) + bd_item_delete.DeleteBDItemRegisterHandlers(dp, \ + a_Prefix, \ + bd_item.GetCheckForPrefixFunc(a_Prefix), \ + table_name, \ + key_name, \ + parent_id_field, \ + TaskPreDelete, \ + TaskPostDelete, \ + GetButtonNameAndKeyValueAndAccess, \ + select_task_message, \ + GetAccess, \ + defaul_keyboard_func\ + ) # Добавление задачи - a_Prefix, sel_handler = RegisterSelectParent(add_task_button_name, user_access.AccessMode.ADD) + a_Prefix = RegisterSelectParent(add_task_button_name, user_access.AccessMode.ADD) bd_item_add.AddBDItem3RegisterHandlers(dp, \ bd_item.GetCheckForPrefixFunc(a_Prefix), \ FSMCreateTask, \ @@ -301,15 +330,31 @@ def RegisterHandlers(dp : Dispatcher): GetStartTaskKeyboardButtons\ ) + def RegisterEdit(a_ButtonName, a_FSM, a_EditMessage, a_FieldName, a_FieldType, a_AccessMode = user_access.AccessMode.EDIT): + a_Prefix = RegisterSelectParent(a_ButtonName, a_AccessMode) + bd_item_edit.EditBDItemRegisterHandlers(dp, \ + a_Prefix, \ + a_FSM, \ + bd_item.GetCheckForPrefixFunc(a_Prefix), \ + task_select_to_edit_message, \ + ShowMessageTemplate(a_EditMessage), \ + ShowMessageTemplate(task_success_edit_message), \ + table_name, \ + key_name, \ + parent_id_field, \ + a_FieldName, \ + GetButtonNameAndKeyValueAndAccess, \ + GetAccess, \ + edit_keyboard_func, \ + access_mode = a_AccessMode, \ + field_type = a_FieldType\ + ) + # Редактирование задачи edit_keyboard_func = GetEditTaskKeyboardButtons dp.register_message_handler(simple_message.InfoMessageTemplate(task_start_edit_message, edit_keyboard_func, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_task_button_name) - a_Prefix, sel_handler = RegisterSelectParent(edit_task_photo_button_name, user_access.AccessMode.EDIT) - bd_item_edit.EditBDItemRegisterHandlers(dp, a_Prefix, FSMEditPhotoItem, bd_item.GetCheckForPrefixFunc(a_Prefix), task_select_to_edit_message, ShowMessageTemplate(task_edit_photo_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, parent_id_field, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo) - a_Prefix, sel_handler = RegisterSelectParent(edit_task_name_button_name, user_access.AccessMode.EDIT) - bd_item_edit.EditBDItemRegisterHandlers(dp, a_Prefix, FSMEditNameItem, bd_item.GetCheckForPrefixFunc(a_Prefix), task_select_to_edit_message, ShowMessageTemplate(task_edit_name_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, parent_id_field, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) - a_Prefix, sel_handler = RegisterSelectParent(edit_task_desc_button_name, user_access.AccessMode.EDIT) - bd_item_edit.EditBDItemRegisterHandlers(dp, a_Prefix, FSMEditDeskItem, bd_item.GetCheckForPrefixFunc(a_Prefix), task_select_to_edit_message, ShowMessageTemplate(task_edit_desc_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, parent_id_field, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) - a_Prefix, sel_handler = RegisterSelectParent(edit_task_access_button_name, user_access.AccessMode.EDIT) - bd_item_edit.EditBDItemRegisterHandlers(dp, a_Prefix, FSMEditAccessItem, bd_item.GetCheckForPrefixFunc(a_Prefix), task_select_to_edit_message, ShowMessageTemplate(task_edit_access_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, parent_id_field, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) + RegisterEdit(edit_task_photo_button_name, FSMEditPhotoItem, task_edit_photo_message, photo_field, bd_item.FieldType.photo) + RegisterEdit(edit_task_name_button_name, FSMEditNameItem, task_edit_name_message, name_field, bd_item.FieldType.text) + RegisterEdit(edit_task_desc_button_name, FSMEditDeskItem, task_edit_desc_message, desc_field, bd_item.FieldType.text) + RegisterEdit(edit_task_access_button_name, FSMEditAccessItem, task_edit_access_message, access_field, bd_item.FieldType.text) diff --git a/template/bd_item_select.py b/template/bd_item_select.py index de0c8d4..97b8e79 100644 --- a/template/bd_item_select.py +++ b/template/bd_item_select.py @@ -40,7 +40,7 @@ def FirstSelectBDItemRegisterHandlers(dp, a_PrefixBase, a_ButtonName, a_TableNam sel_handler = SelectDBItemTemplate(a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode = access_mode) dp.register_message_handler(sel_handler, text = a_ButtonName) - return a_Prefix, sel_handler + return a_Prefix def NextSelectBDItemRegisterHandlers(dp, 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}:') @@ -48,4 +48,4 @@ def NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ParentIDFieldName, a_Ta sel_handler = SelectDBItemTemplate(a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode = access_mode) dp.register_callback_query_handler(sel_handler, bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) - return a_Prefix, sel_handler + return a_Prefix diff --git a/template/bd_item_view.py b/template/bd_item_view.py index d302a36..6e896be 100644 --- a/template/bd_item_view.py +++ b/template/bd_item_view.py @@ -16,10 +16,9 @@ def ShowBDItemRegisterHandlers(dp, a_PrevPrefix, a_TableName : str, a_KeyName, a dp.register_callback_query_handler(ShowBDItemTemplate(a_TableName, a_KeyName, a_ShowItemWorkFunc, a_PrevPrefix, a_AccessFunc, a_ButtonFunc, access_mode = access_mode), bd_item.GetCheckForPrefixFunc(a_PrevPrefix)) def FirstSelectAndShowBDItemRegisterHandlers(dp, 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, sel_handler = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, '', a_ButtonName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) + a_Prefix = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, '', a_ButtonName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) ShowBDItemRegisterHandlers(dp, a_Prefix, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode) - return sel_handler def LastSelectAndShowBDItemRegisterHandlers(dp, 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, sel_handler = bd_item_select.NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ParentIDFieldName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) + a_Prefix = bd_item_select.NextSelectBDItemRegisterHandlers(dp, a_PrevPrefix, a_ParentIDFieldName, a_TableName, a_KeyName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, access_mode = access_mode) ShowBDItemRegisterHandlers(dp, a_Prefix, a_TableName, a_KeyName, a_ShowItemWorkFunc, a_AccessFunc, a_ButtonFunc, access_mode = access_mode)