fix: filtering capabilities, feat: improve enum i18n
This commit is contained in:
@@ -2,6 +2,11 @@ from .main import QBotApp as QBotApp, Config as Config
|
||||
from .router import Router as Router
|
||||
from .model.bot_entity import BotEntity as BotEntity
|
||||
from .model.bot_enum import BotEnum as BotEnum, EnumMember as EnumMember
|
||||
from .bot.handlers.context import (
|
||||
ContextData as ContextData,
|
||||
CallbackCommand as CallbackCommand,
|
||||
CommandContext as CommandContext,
|
||||
)
|
||||
from .model.descriptors import (
|
||||
Entity as Entity,
|
||||
EntityField as EntityField,
|
||||
@@ -9,4 +14,6 @@ from .model.descriptors import (
|
||||
EntityList as EntityList,
|
||||
EntityPermission as EntityPermission,
|
||||
CommandCallbackContext as CommandCallbackContext,
|
||||
CommandButton as CommandButton,
|
||||
FieldEditButton as FieldEditButton,
|
||||
)
|
||||
|
||||
@@ -10,13 +10,20 @@ def add_filter_controls(
|
||||
keyboard_builder: InlineKeyboardBuilder,
|
||||
entity_descriptor: EntityDescriptor,
|
||||
filter: str = None,
|
||||
filtering_fields: list[str] = None,
|
||||
page: int = 1,
|
||||
):
|
||||
field_name_descriptor = entity_descriptor.fields_descriptors["name"]
|
||||
if field_name_descriptor.caption:
|
||||
caption = get_callable_str(field_name_descriptor.caption, field_name_descriptor)
|
||||
else:
|
||||
caption = field_name_descriptor.name
|
||||
caption = ", ".join(
|
||||
[
|
||||
get_callable_str(
|
||||
entity_descriptor.fields_descriptors[field_name].caption,
|
||||
entity_descriptor,
|
||||
)
|
||||
if entity_descriptor.fields_descriptors[field_name].caption
|
||||
else field_name
|
||||
for field_name in filtering_fields
|
||||
]
|
||||
)
|
||||
|
||||
keyboard_builder.row(
|
||||
InlineKeyboardButton(
|
||||
|
||||
@@ -263,6 +263,7 @@ async def render_entity_picker(
|
||||
keyboard_builder=keyboard_builder,
|
||||
entity_descriptor=type_.bot_entity_descriptor,
|
||||
filter=entity_filter,
|
||||
filtering_fields=form_list.filtering_fields,
|
||||
)
|
||||
|
||||
if is_list:
|
||||
|
||||
@@ -200,13 +200,14 @@ async def process_field_edit_callback(message: Message | CallbackQuery, **kwargs
|
||||
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 prev_form_list.static_filters:
|
||||
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
|
||||
@@ -298,6 +299,9 @@ async def process_field_edit_callback(message: Message | CallbackQuery, **kwargs
|
||||
|
||||
state_data.update(state_data)
|
||||
|
||||
clear_state(state_data=state_data)
|
||||
return await route_callback(message=message, back=False, **kwargs)
|
||||
|
||||
elif callback_data.context in [
|
||||
CommandContext.ENTITY_EDIT,
|
||||
CommandContext.ENTITY_FIELD_EDIT,
|
||||
|
||||
@@ -232,6 +232,7 @@ async def entity_list(
|
||||
keyboard_builder=keyboard_builder,
|
||||
entity_descriptor=entity_descriptor,
|
||||
filter=entity_filter,
|
||||
filtering_fields=form_list.filtering_fields,
|
||||
)
|
||||
|
||||
context = pop_navigation_context(navigation_stack)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from aiogram.utils.i18n import I18n
|
||||
from pydantic_core.core_schema import str_schema
|
||||
from sqlalchemy.types import TypeDecorator, String
|
||||
from typing import Any, Self, overload
|
||||
@@ -133,7 +134,11 @@ class EnumMember(object):
|
||||
if lang and lang in self.loc_obj.keys():
|
||||
return self.loc_obj[lang]
|
||||
else:
|
||||
return self.loc_obj[list(self.loc_obj.keys())[0]]
|
||||
i18n = I18n.get_current()
|
||||
if i18n:
|
||||
return self.loc_obj[i18n.current_locale]
|
||||
else:
|
||||
return self.loc_obj[list(self.loc_obj.keys())[0]]
|
||||
|
||||
return self.value
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ class EntityList:
|
||||
show_add_new_button: bool = True
|
||||
item_form: str | None = None
|
||||
pagination: bool = True
|
||||
static_filters: list[Filter] | Any = None
|
||||
static_filters: list[Filter] = None
|
||||
filtering: bool = False
|
||||
filtering_fields: list[str] = None
|
||||
order_by: str | Any | None = None
|
||||
|
||||
@@ -18,6 +18,8 @@ def save_navigation_context(
|
||||
stack
|
||||
and navigation_context
|
||||
and navigation_context.command == callback_data.command
|
||||
and navigation_context.entity_name == callback_data.entity_name
|
||||
and navigation_context.entity_id == callback_data.entity_id
|
||||
and navigation_context.command != CallbackCommand.USER_COMMAND
|
||||
):
|
||||
navigation_context = callback_data
|
||||
|
||||
Reference in New Issue
Block a user