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