add command params
This commit is contained in:
@@ -2,14 +2,14 @@ from aiogram.types import InlineKeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from ....model.settings import Settings
|
||||
from ....model.descriptors import EntityFieldDescriptor
|
||||
from ....model.descriptors import FieldDescriptor
|
||||
from ..context import ContextData, CallbackCommand, CommandContext
|
||||
from ..navigation import get_navigation_context, pop_navigation_context
|
||||
from ....utils.navigation import get_navigation_context, pop_navigation_context
|
||||
|
||||
|
||||
async def wrap_editor(
|
||||
keyboard_builder: InlineKeyboardBuilder,
|
||||
field_descriptor: EntityFieldDescriptor,
|
||||
field_descriptor: FieldDescriptor,
|
||||
callback_data: ContextData,
|
||||
state_data: dict,
|
||||
):
|
||||
@@ -17,28 +17,37 @@ async def wrap_editor(
|
||||
CommandContext.ENTITY_CREATE,
|
||||
CommandContext.ENTITY_EDIT,
|
||||
CommandContext.ENTITY_FIELD_EDIT,
|
||||
CommandContext.COMMAND_FORM,
|
||||
]:
|
||||
form_name = (
|
||||
callback_data.form_params.split("&")[0]
|
||||
if callback_data.form_params
|
||||
else "default"
|
||||
)
|
||||
form = field_descriptor.entity_descriptor.forms.get(
|
||||
form_name, field_descriptor.entity_descriptor.default_form
|
||||
)
|
||||
|
||||
btns = []
|
||||
field_index = (
|
||||
form.edit_field_sequence.index(field_descriptor.name)
|
||||
if callback_data.context
|
||||
in [CommandContext.ENTITY_CREATE, CommandContext.ENTITY_EDIT]
|
||||
else 0
|
||||
)
|
||||
show_back = True
|
||||
show_cancel = True
|
||||
if callback_data.context == CommandContext.COMMAND_FORM:
|
||||
field_sequence = list(field_descriptor.command.param_form.keys())
|
||||
field_index = field_sequence.index(callback_data.field_name)
|
||||
show_back = field_descriptor.command.show_back_in_param_form
|
||||
show_cancel = field_descriptor.command.show_cancel_in_param_form
|
||||
else:
|
||||
form_name = (
|
||||
callback_data.form_params.split("&")[0]
|
||||
if callback_data.form_params
|
||||
else "default"
|
||||
)
|
||||
form = field_descriptor.entity_descriptor.forms.get(
|
||||
form_name, field_descriptor.entity_descriptor.default_form
|
||||
)
|
||||
field_sequence = form.edit_field_sequence
|
||||
field_index = (
|
||||
field_sequence.index(field_descriptor.name)
|
||||
if callback_data.context
|
||||
in [CommandContext.ENTITY_CREATE, CommandContext.ENTITY_EDIT]
|
||||
else 0
|
||||
)
|
||||
|
||||
stack, context = get_navigation_context(state_data=state_data)
|
||||
context = pop_navigation_context(stack)
|
||||
|
||||
if field_index > 0:
|
||||
if field_index > 0 and show_back:
|
||||
btns.append(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_BACK_BTN)),
|
||||
@@ -48,7 +57,8 @@ async def wrap_editor(
|
||||
entity_name=callback_data.entity_name,
|
||||
entity_id=callback_data.entity_id,
|
||||
form_params=callback_data.form_params,
|
||||
field_name=form.edit_field_sequence[field_index - 1],
|
||||
user_command=callback_data.user_command,
|
||||
field_name=field_sequence[field_index - 1],
|
||||
).pack(),
|
||||
)
|
||||
)
|
||||
@@ -62,8 +72,9 @@ async def wrap_editor(
|
||||
context=callback_data.context,
|
||||
entity_name=callback_data.entity_name,
|
||||
entity_id=callback_data.entity_id,
|
||||
form_params=callback_data.form_params,
|
||||
field_name=callback_data.field_name,
|
||||
form_params=callback_data.form_params,
|
||||
user_command=callback_data.user_command,
|
||||
data="skip",
|
||||
).pack(),
|
||||
)
|
||||
@@ -71,12 +82,13 @@ async def wrap_editor(
|
||||
|
||||
keyboard_builder.row(*btns)
|
||||
|
||||
keyboard_builder.row(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_CANCEL_BTN)),
|
||||
callback_data=context.pack(),
|
||||
if show_cancel:
|
||||
keyboard_builder.row(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_CANCEL_BTN)),
|
||||
callback_data=context.pack(),
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
elif callback_data.context == CommandContext.SETTING_EDIT:
|
||||
keyboard_builder.row(
|
||||
|
||||
Reference in New Issue
Block a user