|
|
@ -16,8 +16,6 @@ cancel_message = ''' |
|
|
|
🚫 Добавление отменено |
|
|
|
🚫 Добавление отменено |
|
|
|
''' |
|
|
|
''' |
|
|
|
|
|
|
|
|
|
|
|
parent_id_field_name = 'parent_id' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, a_ButtonFunc, a_FinishButtonFunc, access_mode = user_access.AccessMode.ADD): |
|
|
|
def StartAddBDItemTemplate(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 : types.CallbackQuery, state : FSMContext): |
|
|
|
async def StartAddBDItem(a_CallbackQuery : types.CallbackQuery, state : FSMContext): |
|
|
|
user_id = str(a_CallbackQuery.from_user.id) |
|
|
|
user_id = str(a_CallbackQuery.from_user.id) |
|
|
@ -28,19 +26,18 @@ def StartAddBDItemTemplate(a_FSM, a_FSMStart, a_MessageFunc, a_ParentTableName, |
|
|
|
|
|
|
|
|
|
|
|
await a_FSMStart.set() |
|
|
|
await a_FSMStart.set() |
|
|
|
async with state.proxy() as item_data: |
|
|
|
async with state.proxy() as item_data: |
|
|
|
item_data[parent_id_field_name] = parent_id |
|
|
|
if a_ParentKeyFieldName: |
|
|
|
|
|
|
|
item_data[a_ParentKeyFieldName] = parent_id |
|
|
|
|
|
|
|
|
|
|
|
if parent_id: |
|
|
|
if parent_id: |
|
|
|
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery) |
|
|
|
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_CallbackQuery) |
|
|
|
else: |
|
|
|
else: |
|
|
|
res_of_work_func = await a_MessageFunc(a_CallbackQuery) |
|
|
|
res_of_work_func = await a_MessageFunc(a_CallbackQuery, None) |
|
|
|
|
|
|
|
|
|
|
|
if not check is None: |
|
|
|
if not check is None: |
|
|
|
await state.finish() |
|
|
|
await state.finish() |
|
|
|
check.keyboard_func = a_FinishButtonFunc |
|
|
|
check.keyboard_func = a_FinishButtonFunc |
|
|
|
return check |
|
|
|
return check |
|
|
|
if parent_id: |
|
|
|
|
|
|
|
await a_FSM.next() |
|
|
|
|
|
|
|
return res_of_work_func |
|
|
|
return res_of_work_func |
|
|
|
return simple_message.SimpleMessageTemplate(StartAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) |
|
|
|
return simple_message.SimpleMessageTemplate(StartAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) |
|
|
|
|
|
|
|
|
|
|
@ -65,13 +62,15 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P |
|
|
|
async with state.proxy() as item_data: |
|
|
|
async with state.proxy() as item_data: |
|
|
|
if a_Message.text == bd_item.canсel_button_name: |
|
|
|
if a_Message.text == bd_item.canсel_button_name: |
|
|
|
await state.finish() |
|
|
|
await state.finish() |
|
|
|
return simple_message.WorkFuncResult(cancel_message, keyborad_func = a_FinishButtonFunc) |
|
|
|
return simple_message.WorkFuncResult(cancel_message, keyboard_func = a_FinishButtonFunc) |
|
|
|
|
|
|
|
|
|
|
|
parent_id = item_data[parent_id_field_name] |
|
|
|
parent_id = None |
|
|
|
|
|
|
|
if a_ParentKeyFieldName: |
|
|
|
|
|
|
|
parent_id = item_data[a_ParentKeyFieldName] |
|
|
|
if parent_id: |
|
|
|
if parent_id: |
|
|
|
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message) |
|
|
|
check, res_of_work_func = await bd_item.CheckAccessBDItemTemplate(a_ParentTableName, a_ParentKeyFieldName, parent_id, a_MessageFunc, access_mode)(a_Message) |
|
|
|
else: |
|
|
|
else: |
|
|
|
res_of_work_func = await a_MessageFunc(a_Message) |
|
|
|
res_of_work_func = await a_MessageFunc(a_Message, None) |
|
|
|
|
|
|
|
|
|
|
|
if not check is None: |
|
|
|
if not check is None: |
|
|
|
await state_func() |
|
|
|
await state_func() |
|
|
@ -84,7 +83,7 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P |
|
|
|
else: |
|
|
|
else: |
|
|
|
if a_Message.photo == None or len(a_Message.photo) == 0: |
|
|
|
if a_Message.photo == None or len(a_Message.photo) == 0: |
|
|
|
await state.finish() |
|
|
|
await state.finish() |
|
|
|
return simple_message.WorkFuncResult(error_photo_type_message, keyborad_func = a_FinishButtonFunc) |
|
|
|
return simple_message.WorkFuncResult(error_photo_type_message, keyboard_func = a_FinishButtonFunc) |
|
|
|
field_value = a_Message.photo[0].file_id |
|
|
|
field_value = a_Message.photo[0].file_id |
|
|
|
else: |
|
|
|
else: |
|
|
|
field_value = a_Message.text |
|
|
|
field_value = a_Message.text |
|
|
@ -98,14 +97,14 @@ def FinishOrNextAddBDItemTemplate(a_FSM, a_AddBDItemFunc, a_ParentTableName, a_P |
|
|
|
|
|
|
|
|
|
|
|
return simple_message.SimpleMessageTemplate(FinishAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) |
|
|
|
return simple_message.SimpleMessageTemplate(FinishAddBDItem, a_ButtonFunc, a_AccessFunc, access_mode) |
|
|
|
|
|
|
|
|
|
|
|
def AddBDItem3RegisterHandlers(dp, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_AddBDItemFunc, a_AddNameMessageFunc, a_AddDescMessageFunc, a_AddPhotoMessageFunc, a_FinishMessageFunc, a_ParentTableName : str, a_ParentKeyFieldName, a_NameField, a_DescField, a_PhotoField, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD): |
|
|
|
def AddBDItem3RegisterHandlers(dp, a_StartCheckFunc, a_FSM, a_FSMName, a_FSMDesc, a_FSMPhoto, a_AddBDItemFunc, a_AddNameMessageFunc, a_AddDescMessageFunc, a_AddPhotoMessageFunc, a_FinishMessageFunc, a_ParentPrefix, a_ParentTableName : str, a_ParentKeyFieldName, a_NameField, a_DescField, a_PhotoField, a_GetButtonNameAndKeyValueAndAccessFunc, a_AccessFunc, a_ButtonFunc, access_mode = user_access.AccessMode.ADD): |
|
|
|
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) |
|
|
|
keyboard_cancel = bd_item.GetCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) |
|
|
|
keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) |
|
|
|
keyboard_skip_and_cancel = bd_item.GetSkipAndCancelKeyboardButtonsTemplate(a_AccessFunc, access_mode) |
|
|
|
a_Prefix = f'add_{a_ParentTableName}_{a_ParentKeyFieldName}_{a_NameField}_{a_DescField}_{a_PhotoField}:' |
|
|
|
reg_func = dp.register_message_handler |
|
|
|
if a_ParentTableName: |
|
|
|
if a_ParentTableName: |
|
|
|
dp.register_callback_query_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) |
|
|
|
reg_func = dp.register_callback_query_handler |
|
|
|
else: |
|
|
|
reg_func(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_ParentPrefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) |
|
|
|
dp.register_message_handler(StartAddBDItemTemplate(a_FSM, a_FSMName, a_AddNameMessageFunc, a_ParentTableName, a_ParentKeyFieldName, a_Prefix, a_AccessFunc, keyboard_cancel, a_ButtonFunc, access_mode), a_StartCheckFunc) |
|
|
|
|
|
|
|
dp.register_message_handler(NextAddBDItemTemplate(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) |
|
|
|
dp.register_message_handler(NextAddBDItemTemplate(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) |
|
|
|
dp.register_message_handler(NextAddBDItemTemplate(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) |
|
|
|
dp.register_message_handler(NextAddBDItemTemplate(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) |
|
|
|
dp.register_message_handler(FinishAddBDItemTemplate(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) |
|
|
|
dp.register_message_handler(FinishAddBDItemTemplate(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) |
|
|
|