add ruff format, ruff check, time_picker, project structure and imports reorganized
This commit is contained in:
93
bot/handlers/editors/wrapper.py
Normal file
93
bot/handlers/editors/wrapper.py
Normal file
@@ -0,0 +1,93 @@
|
||||
from aiogram.types import InlineKeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from ....model.settings import Settings
|
||||
from ....model.descriptors import EntityFieldDescriptor
|
||||
from ..context import ContextData, CallbackCommand, CommandContext
|
||||
from ..navigation import get_navigation_context, pop_navigation_context
|
||||
|
||||
|
||||
async def wrap_editor(
|
||||
keyboard_builder: InlineKeyboardBuilder,
|
||||
field_descriptor: EntityFieldDescriptor,
|
||||
callback_data: ContextData,
|
||||
state_data: dict,
|
||||
):
|
||||
if callback_data.context in [
|
||||
CommandContext.ENTITY_CREATE,
|
||||
CommandContext.ENTITY_EDIT,
|
||||
CommandContext.ENTITY_FIELD_EDIT,
|
||||
]:
|
||||
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
|
||||
)
|
||||
|
||||
stack, context = get_navigation_context(state_data=state_data)
|
||||
context = pop_navigation_context(stack)
|
||||
|
||||
if field_index > 0:
|
||||
btns.append(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_BACK_BTN)),
|
||||
callback_data=ContextData(
|
||||
command=CallbackCommand.FIELD_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=form.edit_field_sequence[field_index - 1],
|
||||
).pack(),
|
||||
)
|
||||
)
|
||||
|
||||
if field_descriptor.is_optional:
|
||||
btns.append(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_SKIP_BTN)),
|
||||
callback_data=ContextData(
|
||||
command=CallbackCommand.FIELD_EDITOR_CALLBACK,
|
||||
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,
|
||||
data="skip",
|
||||
).pack(),
|
||||
)
|
||||
)
|
||||
|
||||
keyboard_builder.row(*btns)
|
||||
|
||||
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(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_CANCEL_BTN)),
|
||||
callback_data=ContextData(
|
||||
command=CallbackCommand.FIELD_EDITOR_CALLBACK,
|
||||
context=callback_data.context,
|
||||
field_name=callback_data.field_name,
|
||||
form_params=callback_data.form_params,
|
||||
data="cancel",
|
||||
).pack(),
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user