Merge branch 'master' into dev
Some checks reported errors
continuous-integration/drone/push Build was killed
Some checks reported errors
continuous-integration/drone/push Build was killed
# Conflicts: # drone.yaml
This commit is contained in:
@@ -4,6 +4,7 @@ from aiogram.fsm.state import State, StatesGroup
|
||||
class SearchForm(StatesGroup):
|
||||
search_option = State()
|
||||
data_to_search = State()
|
||||
sent_messages = State()
|
||||
search_result = State()
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine, session
|
||||
|
||||
|
||||
DATABASE_URL = (f"postgresql+asyncpg://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@"
|
||||
f"{os.getenv('DB_HOST')}/{os.getenv('DATABASE')}")
|
||||
|
||||
engine = create_async_engine(DATABASE_URL, echo=True)
|
||||
async_session_ = async_sessionmaker(bind=engine, expire_on_commit=False)
|
||||
|
||||
@@ -132,14 +132,6 @@ async def search_by_item(message: Message, state: FSMContext):
|
||||
async def show_order(callback: CallbackQuery, state: FSMContext, bot: Bot):
|
||||
order_id = int(re.search(r"(\d+)", callback.data).group())
|
||||
|
||||
try:
|
||||
async with async_session_() as local_session:
|
||||
result = await local_session.execute(select(Order).filter(Order.id == order_id))
|
||||
order = result.scalars().first()
|
||||
|
||||
except Exception as err:
|
||||
logger.warning(err)
|
||||
|
||||
order = next(filter(lambda item: order_id == item.id, await state.get_value("search_result")), None)
|
||||
|
||||
if order:
|
||||
@@ -154,7 +146,7 @@ async def show_order(callback: CallbackQuery, state: FSMContext, bot: Bot):
|
||||
(f"{clbk}_{order.id}", text) for clbk, text in order_operation_base.items()))
|
||||
)
|
||||
|
||||
for message in SearchForm.sent_messages:
|
||||
for message in await state.get_value("sent_messages"):
|
||||
await bot.delete_message(chat_id=callback.message.chat.id, message_id=message.message_id)
|
||||
await state.clear()
|
||||
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import os
|
||||
import asyncio
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv(".env")
|
||||
|
||||
from aiogram import Dispatcher, Bot
|
||||
from handlers import *
|
||||
from keyboards import set_main_menu
|
||||
from middlewares import SessionMiddleware
|
||||
|
||||
load_dotenv(".env")
|
||||
bot = Bot(token=os.getenv("TOKEN"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user