refactoring

This commit is contained in:
Alexander Kalinovsky
2025-01-09 13:11:10 +01:00
parent 7793a0cb77
commit 3898a333fa
29 changed files with 1065 additions and 381 deletions

View File

@@ -21,7 +21,6 @@ router = Router()
async def string_editor(message: Message | CallbackQuery,
field_descriptor: EntityFieldDescriptor,
entity_descriptor: EntityDescriptor,
callback_data: ContextData,
current_value: Any,
edit_prompt: str,
@@ -31,14 +30,16 @@ async def string_editor(message: Message | CallbackQuery,
keyboard_builder = InlineKeyboardBuilder()
state_data: dict = kwargs["state_data"]
_edit_prompt = edit_prompt
type_ = field_descriptor.type_
type_origin = get_origin(type_)
if type_origin == UnionType:
type_ = get_args(type_)[0]
# type_ = field_descriptor.type_
# type_origin = get_origin(type_)
# if type_origin == UnionType:
# type_ = get_args(type_)[0]
if type_ == str and field_descriptor.localizable:
if field_descriptor.type_base == str and field_descriptor.localizable:
current_locale = list(LanguageBase.all_members.values())[locale_index]
context_data = ContextData(
@@ -51,9 +52,9 @@ async def string_editor(message: Message | CallbackQuery,
_edit_prompt = f"{edit_prompt}\n{(await Settings.get(
Settings.APP_STRINGS_STRING_EDITOR_LOCALE_TEMPLATE_P_NAME)).format(name = current_locale)}"
_current_value = get_local_text(current_value, current_locale)
_current_value = get_local_text(current_value, current_locale) if current_value else None
await state.update_data({
state_data.update({
"context_data": context_data.pack(),
"edit_prompt": edit_prompt,
"locale_index": str(locale_index),
@@ -70,7 +71,7 @@ async def string_editor(message: Message | CallbackQuery,
_current_value = serialize(current_value, field_descriptor)
await state.update_data({
state_data.update({
"context_data": context_data.pack()})
if _current_value:
@@ -79,16 +80,19 @@ async def string_editor(message: Message | CallbackQuery,
keyboard_builder.row(InlineKeyboardButton(text = _current_value_caption,
copy_text = CopyTextButton(text = _current_value)))
state_data = kwargs["state_data"]
await wrap_editor(keyboard_builder = keyboard_builder,
field_descriptor = field_descriptor,
entity_descriptor = entity_descriptor,
callback_data = callback_data,
state = state)
state_data = state_data)
await state.set_data(state_data)
send_message = get_send_message(message)
await send_message(text = _edit_prompt, reply_markup = keyboard_builder.as_markup())
async def context_command_fiter(*args, **kwargs):
print(args, kwargs)
return True
# async def context_command_fiter(*args, **kwargs):
# print(args, kwargs)
# return True