refactoring
This commit is contained in:
@@ -4,13 +4,16 @@ from aiogram.fsm.context import FSMContext
|
||||
from aiogram.types import Message, CallbackQuery, InlineKeyboardButton
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
from logging import getLogger
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from ....main import QBotApp
|
||||
from ....model.descriptors import EntityFieldDescriptor, EntityDescriptor
|
||||
from ..context import ContextData, CallbackCommand
|
||||
from ..common import get_send_message, get_field_descriptor, get_entity_descriptor
|
||||
from .common import wrap_editor
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from ....main import QBotApp
|
||||
|
||||
|
||||
logger = getLogger(__name__)
|
||||
router = Router()
|
||||
@@ -18,7 +21,6 @@ router = Router()
|
||||
|
||||
async def date_picker(message: Message | CallbackQuery,
|
||||
field_descriptor: EntityFieldDescriptor,
|
||||
entity_descriptor: EntityDescriptor,
|
||||
callback_data: ContextData,
|
||||
current_value: datetime,
|
||||
state: FSMContext,
|
||||
@@ -82,11 +84,14 @@ async def date_picker(message: Message | CallbackQuery,
|
||||
|
||||
keyboard_builder.row(*buttons)
|
||||
|
||||
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)
|
||||
|
||||
if edit_prompt:
|
||||
send_message = get_send_message(message)
|
||||
@@ -98,7 +103,7 @@ async def date_picker(message: Message | CallbackQuery,
|
||||
@router.callback_query(ContextData.filter(F.command == CallbackCommand.DATE_PICKER_YEAR))
|
||||
async def date_picker_year(query: CallbackQuery,
|
||||
callback_data: ContextData,
|
||||
app: QBotApp,
|
||||
app: "QBotApp",
|
||||
state: FSMContext,
|
||||
**kwargs):
|
||||
|
||||
@@ -142,11 +147,9 @@ async def date_picker_year(query: CallbackQuery,
|
||||
save_state = True).pack()))
|
||||
|
||||
field_descriptor = get_field_descriptor(app, callback_data)
|
||||
entity_descriptor = get_entity_descriptor(app, callback_data)
|
||||
|
||||
await wrap_editor(keyboard_builder = keyboard_builder,
|
||||
field_descriptor = field_descriptor,
|
||||
entity_descriptor = entity_descriptor,
|
||||
callback_data = callback_data,
|
||||
state = state)
|
||||
|
||||
@@ -154,14 +157,12 @@ async def date_picker_year(query: CallbackQuery,
|
||||
|
||||
|
||||
@router.callback_query(ContextData.filter(F.command == CallbackCommand.DATE_PICKER_MONTH))
|
||||
async def date_picker_month(query: CallbackQuery, callback_data: ContextData, app: QBotApp, **kwargs):
|
||||
|
||||
entity_descriptor = get_entity_descriptor(app, callback_data)
|
||||
async def date_picker_month(query: CallbackQuery, callback_data: ContextData, app: "QBotApp", **kwargs):
|
||||
|
||||
field_descriptor = get_field_descriptor(app, callback_data)
|
||||
|
||||
await date_picker(query.message,
|
||||
field_descriptor = field_descriptor,
|
||||
entity_descriptor = entity_descriptor,
|
||||
callback_data = callback_data,
|
||||
current_value = datetime.strptime(callback_data.data, "%Y-%m-%d"),
|
||||
**kwargs)
|
||||
Reference in New Issue
Block a user