fix: default values in subordinate entities based on static_filtering, add: button visibility callbacks in entities' forms
This commit is contained in:
@@ -54,6 +54,9 @@ async def time_picker(
|
||||
):
|
||||
keyboard_builder = InlineKeyboardBuilder()
|
||||
|
||||
if not current_value:
|
||||
current_value = time(0, 0)
|
||||
|
||||
for i in range(12):
|
||||
keyboard_builder.row(
|
||||
InlineKeyboardButton(
|
||||
|
||||
@@ -167,6 +167,36 @@ async def process_field_edit_callback(message: Message | CallbackQuery, **kwargs
|
||||
|
||||
entity_data = state_data.get("entity_data", {})
|
||||
|
||||
if callback_data.context == CommandContext.ENTITY_CREATE:
|
||||
stack = state_data.get("navigation_stack", [])
|
||||
prev_callback_data = ContextData.unpack(stack[-1]) if stack else None
|
||||
if (
|
||||
prev_callback_data
|
||||
and prev_callback_data.command == CallbackCommand.ENTITY_LIST
|
||||
and prev_callback_data.entity_name == entity_descriptor.name
|
||||
):
|
||||
prev_form_name = (
|
||||
prev_callback_data.form_params.split("&")[0]
|
||||
if prev_callback_data.form_params
|
||||
else "default"
|
||||
)
|
||||
prev_form_params = (
|
||||
prev_callback_data.form_params.split("&")[1:]
|
||||
if prev_callback_data.form_params
|
||||
else []
|
||||
)
|
||||
prev_form_list = entity_descriptor.lists.get(
|
||||
prev_form_name or "default", entity_descriptor.default_list
|
||||
)
|
||||
|
||||
for filt in prev_form_list.static_filters:
|
||||
if filt.value_type == "const":
|
||||
entity_data[filt.field_name] = filt.value
|
||||
elif len(prev_form_params) > filt.param_index:
|
||||
entity_data[filt.field_name] = prev_form_params[
|
||||
filt.param_index
|
||||
]
|
||||
|
||||
if (
|
||||
callback_data.context
|
||||
in [CommandContext.ENTITY_CREATE, CommandContext.ENTITY_EDIT]
|
||||
|
||||
Reference in New Issue
Block a user