add InlineButton to forms
This commit is contained in:
@@ -16,4 +16,5 @@ from .model.descriptors import (
|
||||
CommandCallbackContext as CommandCallbackContext,
|
||||
CommandButton as CommandButton,
|
||||
FieldEditButton as FieldEditButton,
|
||||
InlineButton as InlineButton,
|
||||
)
|
||||
|
||||
@@ -6,7 +6,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from logging import getLogger
|
||||
from sqlmodel.ext.asyncio.session import AsyncSession
|
||||
|
||||
from ....model.descriptors import FieldEditButton, CommandButton
|
||||
from ....model.descriptors import FieldEditButton, CommandButton, InlineButton
|
||||
from ....model.settings import Settings
|
||||
from ....model.user import UserBase
|
||||
from ....model import EntityPermission
|
||||
@@ -165,6 +165,13 @@ async def entity_item(
|
||||
)
|
||||
)
|
||||
|
||||
elif isinstance(button, InlineButton):
|
||||
|
||||
if isinstance(button.inline_button, InlineKeyboardButton):
|
||||
btn_row.append(button.inline_button)
|
||||
elif callable(button.inline_button):
|
||||
btn_row.append(button.inline_button(entity_item))
|
||||
|
||||
if btn_row:
|
||||
keyboard_builder.row(*btn_row)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from aiogram.types import Message, CallbackQuery
|
||||
from aiogram.types import Message, CallbackQuery, InlineKeyboardButton
|
||||
from aiogram.fsm.context import FSMContext
|
||||
from aiogram.utils.i18n import I18n
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
@@ -35,6 +35,12 @@ class CommandButton:
|
||||
visibility: Callable[[Any], bool] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class InlineButton:
|
||||
inline_button: InlineKeyboardButton | Callable[[Any], InlineKeyboardButton]
|
||||
visibility: Callable[[Any], bool] | None = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class Filter:
|
||||
field_name: str
|
||||
@@ -74,7 +80,7 @@ class EntityList:
|
||||
class EntityForm:
|
||||
item_repr: EntityItemCaptionCallable | None = None
|
||||
edit_field_sequence: list[str] = None
|
||||
form_buttons: list[list[FieldEditButton | CommandButton]] = None
|
||||
form_buttons: list[list[FieldEditButton | CommandButton | InlineButton]] = None
|
||||
show_edit_button: bool = True
|
||||
show_delete_button: bool = True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user