diff --git a/bot_modules/access.py b/bot_modules/access.py index bc76ed7..1f23ed9 100644 --- a/bot_modules/access.py +++ b/bot_modules/access.py @@ -184,5 +184,5 @@ def RegisterHandlers(dp : Dispatcher): sql_request.RequestToBDRegisterHandlers(dp, sql_request_button_name, request_start_message, FSMRequestToBDAccess, defaul_keyboard_func, user_access.AccessMode.ACCEES_EDIT, GetAccess) edit_keyboard_func = defaul_keyboard_func - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_moduleaccess_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, moduleaccess_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDefaultAccessItem, edit_moduleaccess_default_access_button_name, moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_default_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, mod_default_access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditAccessItem, bd_item.GetCheckForTextFunc(edit_moduleaccess_access_button_name), moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, None, moduleaccess_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditDefaultAccessItem, bd_item.GetCheckForTextFunc(edit_moduleaccess_default_access_button_name), moduleaccess_select_to_edit_message, ShowMessageTemplate(moduleaccess_edit_default_access_message), ShowMessageTemplate(moduleaccess_success_edit_message), table_name, mod_name_field, None, mod_default_access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) diff --git a/bot_modules/projects.py b/bot_modules/projects.py index 86ec948..e210910 100644 --- a/bot_modules/projects.py +++ b/bot_modules/projects.py @@ -291,7 +291,7 @@ def RegisterHandlers(dp : Dispatcher): edit_keyboard_func = GetEditProjectKeyboardButtons # Редактирование проекта dp.register_message_handler(simple_message.InfoMessageTemplate(project_start_edit_message, edit_keyboard_func, GetAccess, access_mode = user_access.AccessMode.EDIT), text = edit_project_button_name) - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditPhotoItem, edit_project_photo_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_photo_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo) - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_project_name_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_name_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_project_desc_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_desc_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) - bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_project_access_button_name, project_select_to_edit_message, ShowMessageTemplate(project_edit_access_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditPhotoItem, bd_item.GetCheckForTextFunc(edit_project_photo_button_name), project_select_to_edit_message, ShowMessageTemplate(project_edit_photo_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, None, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditNameItem, bd_item.GetCheckForTextFunc(edit_project_name_button_name), project_select_to_edit_message, ShowMessageTemplate(project_edit_name_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, None, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditDeskItem, bd_item.GetCheckForTextFunc(edit_project_desc_button_name), project_select_to_edit_message, ShowMessageTemplate(project_edit_desc_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, None, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) + bd_item_edit.EditBDItemRegisterHandlers(dp, None, FSMEditAccessItem, bd_item.GetCheckForTextFunc(edit_project_access_button_name), project_select_to_edit_message, ShowMessageTemplate(project_edit_access_message), ShowMessageTemplate(project_success_edit_message), table_name, key_name, None, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) diff --git a/bot_modules/tasks.py b/bot_modules/tasks.py index c508baf..40bf62f 100644 --- a/bot_modules/tasks.py +++ b/bot_modules/tasks.py @@ -262,19 +262,23 @@ def GetModuleButtons(): # Обработка кнопок 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) + # Стартовое сообщение dp.register_message_handler(simple_message.SimpleMessageTemplate(TasksOpen, defaul_keyboard_func, GetAccess), text = tasks_button_name) # Список задач - a_Prefix, sel_handler = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, 'view_task', list_task_button_name, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = user_access.AccessMode.VIEW) + 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, sel_handler = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, 'del_task', del_task_button_name, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = 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(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 = bd_item_select.FirstSelectBDItemRegisterHandlers(dp, 'add_task', add_task_button_name, projects.table_name, projects.key_name, projects.GetButtonNameAndKeyValueAndAccess, projects.select_project_message, projects.GetAccess, access_mode = user_access.AccessMode.VIEW) + a_Prefix, sel_handler = RegisterSelectParent(add_task_button_name, user_access.AccessMode.ADD) bd_item_add.AddBDItem3RegisterHandlers(dp, \ bd_item.GetCheckForPrefixFunc(a_Prefix), \ FSMCreateTask, \ @@ -297,11 +301,15 @@ def RegisterHandlers(dp : Dispatcher): GetStartTaskKeyboardButtons\ ) - # Редактирование задачи -# 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) -# bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditPhotoItem, edit_task_photo_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_photo_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, photo_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.photo) -# bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditNameItem, edit_task_name_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_name_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, name_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) -# bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditDeskItem, edit_task_desc_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_desc_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, desc_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text) -# bd_item_edit.EditBDItemRegisterHandlers(dp, FSMEditAccessItem, edit_task_access_button_name, task_select_to_edit_message, ShowMessageTemplate(task_edit_access_message), ShowMessageTemplate(task_success_edit_message), table_name, key_name, access_field, GetButtonNameAndKeyValueAndAccess, GetAccess, edit_keyboard_func, access_mode = user_access.AccessMode.ACCEES_EDIT, field_type = bd_item.FieldType.text) + # Редактирование задачи + 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) diff --git a/template/bd_item_edit.py b/template/bd_item_edit.py index e2923f5..99e3e44 100644 --- a/template/bd_item_edit.py +++ b/template/bd_item_edit.py @@ -35,11 +35,15 @@ def FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_Messa return bd_item_add.FinishAddBDItemTemplate(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(dp, a_FSM, a_ButtonName, a_StartMessage, a_EditMessageFunc, a_FinishMessageFunc, a_TableName : str, a_KeyName, a_FieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): +def EditBDItemRegisterHandlers(dp, 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, access_mode = user_access.AccessMode.EDIT, field_type = bd_item.FieldType.text): + reg_func = dp.register_message_handler + if a_ParentIDFieldName: + reg_func = dp.register_callback_query_handler + keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) a_Prefix = bd_item.HashPrefix(f'edit_{a_TableName}_{a_KeyName}_{a_FieldName}:') - sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, None, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, None, a_Prefix, access_mode) - dp.register_message_handler(sel_handler, text = a_ButtonName) + sel_handler = bd_item_select.SelectDBItemTemplate(a_TableName, a_ParentIDFieldName, a_GetButtonNameAndKeyValueAndAccessFunc, a_StartMessage, a_AccessFunc, a_PrevPrefix, a_Prefix, access_mode) + reg_func(sel_handler, a_StartCheckFunc) dp.register_callback_query_handler(StartEditBDItemTemplate(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: dp.register_message_handler(FinishEditBDItemTemplate(a_FSM, a_TableName, a_KeyName, a_FieldName, a_FinishMessageFunc, a_AccessFunc, a_ButtonFunc, access_mode, field_type = field_type), content_types = ['photo', 'text'], state = a_FSM.item_field)