add command params
This commit is contained in:
@@ -19,7 +19,7 @@ from ....utils.main import (
|
||||
get_entity_descriptor,
|
||||
)
|
||||
from ..context import ContextData, CallbackCommand, CommandContext
|
||||
from ..navigation import (
|
||||
from ....utils.navigation import (
|
||||
pop_navigation_context,
|
||||
save_navigation_context,
|
||||
)
|
||||
@@ -84,94 +84,89 @@ async def entity_item(
|
||||
callback_data.form_params or "default", entity_descriptor.default_form
|
||||
)
|
||||
|
||||
for edit_buttons_row in form.form_buttons:
|
||||
btn_row = []
|
||||
for button in edit_buttons_row:
|
||||
if form.form_buttons:
|
||||
for edit_buttons_row in form.form_buttons:
|
||||
btn_row = []
|
||||
for button in edit_buttons_row:
|
||||
if button.visibility and not button.visibility(entity_item):
|
||||
continue
|
||||
|
||||
if button.visibility and not button.visibility(entity_item):
|
||||
continue
|
||||
|
||||
if isinstance(button, FieldEditButton) and can_edit:
|
||||
|
||||
field_name = button.field_name
|
||||
btn_caption = button.caption
|
||||
if field_name in entity_descriptor.fields_descriptors:
|
||||
field_descriptor = entity_descriptor.fields_descriptors[
|
||||
field_name
|
||||
]
|
||||
field_value = getattr(entity_item, field_descriptor.field_name)
|
||||
if btn_caption:
|
||||
btn_text = get_callable_str(
|
||||
btn_caption, field_descriptor, entity_item, field_value
|
||||
)
|
||||
else:
|
||||
if field_descriptor.type_base is bool:
|
||||
btn_text = f"{'【✔︎】 ' if field_value else '【 】 '}{
|
||||
get_callable_str(
|
||||
field_descriptor.caption,
|
||||
field_descriptor,
|
||||
entity_item,
|
||||
field_value,
|
||||
)
|
||||
if field_descriptor.caption
|
||||
else field_name
|
||||
}"
|
||||
if isinstance(button, FieldEditButton) and can_edit:
|
||||
field_name = button.field_name
|
||||
btn_caption = button.caption
|
||||
if field_name in entity_descriptor.fields_descriptors:
|
||||
field_descriptor = entity_descriptor.fields_descriptors[
|
||||
field_name
|
||||
]
|
||||
field_value = getattr(entity_item, field_descriptor.field_name)
|
||||
if btn_caption:
|
||||
btn_text = get_callable_str(
|
||||
btn_caption, field_descriptor, entity_item, field_value
|
||||
)
|
||||
else:
|
||||
btn_text = (
|
||||
f"✏️ {
|
||||
if field_descriptor.type_base is bool:
|
||||
btn_text = f"{'【✔︎】 ' if field_value else '【 】 '}{
|
||||
get_callable_str(
|
||||
field_descriptor.caption,
|
||||
field_descriptor,
|
||||
entity_item,
|
||||
field_value,
|
||||
)
|
||||
if field_descriptor.caption
|
||||
else field_name
|
||||
}"
|
||||
if field_descriptor.caption
|
||||
else f"✏️ {field_name}"
|
||||
else:
|
||||
btn_text = (
|
||||
f"✏️ {
|
||||
get_callable_str(
|
||||
field_descriptor.caption,
|
||||
field_descriptor,
|
||||
entity_item,
|
||||
field_value,
|
||||
)
|
||||
}"
|
||||
if field_descriptor.caption
|
||||
else f"✏️ {field_name}"
|
||||
)
|
||||
btn_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=btn_text,
|
||||
callback_data=ContextData(
|
||||
command=CallbackCommand.FIELD_EDITOR,
|
||||
context=CommandContext.ENTITY_FIELD_EDIT,
|
||||
entity_name=entity_descriptor.name,
|
||||
entity_id=str(entity_item.id),
|
||||
field_name=field_name,
|
||||
).pack(),
|
||||
)
|
||||
btn_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=btn_text,
|
||||
callback_data=ContextData(
|
||||
command=CallbackCommand.FIELD_EDITOR,
|
||||
context=CommandContext.ENTITY_FIELD_EDIT,
|
||||
entity_name=entity_descriptor.name,
|
||||
entity_id=str(entity_item.id),
|
||||
field_name=field_name,
|
||||
).pack(),
|
||||
)
|
||||
)
|
||||
|
||||
elif isinstance(button, CommandButton):
|
||||
elif isinstance(button, CommandButton):
|
||||
btn_caption = button.caption
|
||||
|
||||
btn_caption = button.caption
|
||||
if btn_caption:
|
||||
btn_text = get_callable_str(
|
||||
btn_caption, entity_descriptor, entity_item
|
||||
)
|
||||
else:
|
||||
btn_text = button.command
|
||||
|
||||
if isinstance(button.context_data, ContextData):
|
||||
btn_cdata = button.context_data
|
||||
elif callable(button.context_data):
|
||||
btn_cdata = button.context_data(callback_data, entity_item)
|
||||
else:
|
||||
btn_cdata = ContextData(
|
||||
command=CallbackCommand.USER_COMMAND,
|
||||
user_command=button.command,
|
||||
data=str(entity_item.id),
|
||||
if isinstance(button.command, ContextData):
|
||||
btn_cdata = button.command
|
||||
elif callable(button.command):
|
||||
btn_cdata = button.command(callback_data, entity_item)
|
||||
elif isinstance(button.command, str):
|
||||
btn_cdata = ContextData(
|
||||
command=CallbackCommand.USER_COMMAND,
|
||||
user_command=button.command,
|
||||
)
|
||||
|
||||
btn_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=btn_text,
|
||||
callback_data=btn_cdata.pack(),
|
||||
)
|
||||
)
|
||||
|
||||
btn_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=btn_text,
|
||||
callback_data=btn_cdata.pack(),
|
||||
)
|
||||
)
|
||||
|
||||
if btn_row:
|
||||
keyboard_builder.row(*btn_row)
|
||||
if btn_row:
|
||||
keyboard_builder.row(*btn_row)
|
||||
|
||||
edit_delete_row = []
|
||||
if can_edit and form.show_edit_button:
|
||||
|
||||
Reference in New Issue
Block a user