fsm bugfixes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from aiogram.types import Message, CallbackQuery
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -25,11 +26,13 @@ async def route_callback(message: Message | CallbackQuery, back: bool = True, **
|
||||
import quickbot.bot.handlers.user_handlers.main as user_handler
|
||||
|
||||
state_data = kwargs["state_data"]
|
||||
state: FSMContext = kwargs["state"]
|
||||
stack, context = get_navigation_context(state_data)
|
||||
if back:
|
||||
context = pop_navigation_context(stack)
|
||||
stack = save_navigation_context(callback_data=context, state_data=state_data)
|
||||
kwargs.update({"callback_data": context, "navigation_stack": stack})
|
||||
await state.set_data(state_data)
|
||||
if context:
|
||||
if context.command == CallbackCommand.MENU_ENTRY_MAIN:
|
||||
await menu_main.main_menu(message, **kwargs)
|
||||
|
||||
@@ -121,9 +121,7 @@ async def render_entity_picker(
|
||||
enum_items = (await field_descriptor.options(entity, context)) or []
|
||||
else:
|
||||
enum_items = field_descriptor.options(entity, context) or []
|
||||
enum_items = enum_items[
|
||||
page_size * (page - 1) : page_size * page
|
||||
]
|
||||
enum_items = enum_items[page_size * (page - 1) : page_size * page]
|
||||
else:
|
||||
enum_items = list(type_.all_members.values())[
|
||||
page_size * (page - 1) : page_size * page
|
||||
|
||||
@@ -55,7 +55,7 @@ async def field_editor(message: Message | CallbackQuery, **kwargs):
|
||||
db_session: AsyncSession = kwargs["db_session"]
|
||||
user: UserBase = kwargs["user"]
|
||||
app: "QBotApp" = kwargs["app"]
|
||||
# state: FSMContext = kwargs["state"]
|
||||
state: FSMContext = kwargs["state"]
|
||||
|
||||
state_data: dict = kwargs["state_data"]
|
||||
entity_data = state_data.get("entity_data")
|
||||
@@ -173,6 +173,7 @@ async def field_editor(message: Message | CallbackQuery, **kwargs):
|
||||
|
||||
stack, context_data = get_navigation_context(state_data=state_data)
|
||||
kwargs.update({"callback_data": context_data})
|
||||
await state.set_data(state_data)
|
||||
|
||||
return await entity_item(
|
||||
query=message, navigation_stack=stack, **kwargs
|
||||
|
||||
@@ -187,6 +187,8 @@ async def process_field_edit_callback(message: Message | CallbackQuery, **kwargs
|
||||
text=(await Settings.get(Settings.APP_STRINGS_FORBIDDEN))
|
||||
)
|
||||
|
||||
clear_state(state_data=state_data)
|
||||
|
||||
return await route_callback(message=message, back=True, **kwargs)
|
||||
|
||||
elif callback_data.context in [
|
||||
@@ -359,14 +361,14 @@ async def process_field_edit_callback(message: Message | CallbackQuery, **kwargs
|
||||
|
||||
can_create = True
|
||||
|
||||
if entity_descriptor.before_update_save:
|
||||
if iscoroutinefunction(entity_descriptor.before_update_save):
|
||||
can_create = await entity_descriptor.before_update_save(
|
||||
if entity_descriptor.before_create_save:
|
||||
if iscoroutinefunction(entity_descriptor.before_create_save):
|
||||
can_create = await entity_descriptor.before_create_save(
|
||||
new_entity,
|
||||
context,
|
||||
)
|
||||
else:
|
||||
can_create = entity_descriptor.before_update_save(
|
||||
can_create = entity_descriptor.before_create_save(
|
||||
new_entity,
|
||||
context,
|
||||
)
|
||||
|
||||
@@ -76,7 +76,10 @@ async def wrap_editor(
|
||||
)
|
||||
)
|
||||
|
||||
if field_descriptor.is_optional and field_descriptor.show_skip_in_editor == "Auto":
|
||||
if (
|
||||
field_descriptor.is_optional
|
||||
and field_descriptor.show_skip_in_editor == "Auto"
|
||||
):
|
||||
btns.append(
|
||||
InlineKeyboardButton(
|
||||
text=(await Settings.get(Settings.APP_STRINGS_SKIP_BTN)),
|
||||
|
||||
@@ -51,6 +51,7 @@ async def entity_item_callback(query: CallbackQuery, **kwargs):
|
||||
|
||||
clear_state(state_data=state_data)
|
||||
stack = save_navigation_context(callback_data=callback_data, state_data=state_data)
|
||||
await state.set_data(state_data)
|
||||
|
||||
await entity_item(query=query, navigation_stack=stack, **kwargs)
|
||||
|
||||
@@ -72,9 +73,9 @@ async def entity_item(
|
||||
|
||||
entity_item = await entity_type.get(session=db_session, id=callback_data.entity_id)
|
||||
|
||||
state: FSMContext = kwargs["state"]
|
||||
# state: FSMContext = kwargs["state"]
|
||||
state_data = kwargs["state_data"]
|
||||
await state.set_data(state_data)
|
||||
# await state.set_data(state_data)
|
||||
|
||||
if not entity_item and query:
|
||||
return await query.answer(
|
||||
@@ -104,7 +105,7 @@ async def entity_item(
|
||||
app_state=kwargs["app_state"],
|
||||
user=user,
|
||||
message=query,
|
||||
default_handler=item_repr
|
||||
default_handler=item_repr,
|
||||
)
|
||||
|
||||
if form.before_open:
|
||||
@@ -352,8 +353,7 @@ async def item_repr(entity_item: BotEntity, context: BotContext[UserBase]):
|
||||
|
||||
for own_field in entity_descriptor.ownership_fields.items():
|
||||
if (
|
||||
own_field[1].rstrip("_id")
|
||||
== field_descriptor.field_name.rstrip("_id")
|
||||
own_field[1].rstrip("_id") == field_descriptor.field_name.rstrip("_id")
|
||||
and own_field[0] in user.roles
|
||||
and EntityPermission.READ_ALL not in user_permissions
|
||||
):
|
||||
|
||||
@@ -51,6 +51,7 @@ async def entity_list_callback(query: CallbackQuery, **kwargs):
|
||||
|
||||
clear_state(state_data=state_data)
|
||||
stack = save_navigation_context(callback_data=callback_data, state_data=state_data)
|
||||
await state.set_data(state_data)
|
||||
|
||||
await entity_list(message=query, navigation_stack=stack, **kwargs)
|
||||
|
||||
@@ -273,9 +274,9 @@ async def entity_list(
|
||||
)
|
||||
}"
|
||||
|
||||
state: FSMContext = kwargs["state"]
|
||||
state_data = kwargs["state_data"]
|
||||
await state.set_data(state_data)
|
||||
# state: FSMContext = kwargs["state"]
|
||||
# state_data = kwargs["state_data"]
|
||||
# await state.set_data(state_data)
|
||||
|
||||
send_message = get_send_message(message)
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ async def default_start_handler[UserType: UserBase](
|
||||
state: FSMContext,
|
||||
**kwargs,
|
||||
) -> tuple[UserType, bool]:
|
||||
|
||||
User = app.user_class
|
||||
|
||||
user = await User.get(session=db_session, id=message.from_user.id)
|
||||
|
||||
@@ -215,6 +215,7 @@ class QBotApp(Generic[UserType, ConfigType], FastAPI):
|
||||
stack = save_navigation_context(
|
||||
callback_data=callback_data, state_data=state_data
|
||||
)
|
||||
await state.set_data(state_data)
|
||||
|
||||
if not db_session:
|
||||
db_session = await get_db()
|
||||
|
||||
Reference in New Issue
Block a user