chore: Added __init__ files, added fallback for callbacks, refactoring & improvements

This commit is contained in:
ITQ
2024-05-19 16:24:19 +03:00
parent b51c135b14
commit 4bc3025ab4
12 changed files with 291 additions and 138 deletions
+3
View File
@@ -0,0 +1,3 @@
__all__ = ("fallback", "location", "menu", "profile", "travel", "notes")
from app.callbacks import fallback, location, menu, notes, profile, travel
+17
View File
@@ -0,0 +1,17 @@
__all__ = ("router",)
from aiogram import Router
from aiogram.filters import StateFilter
from aiogram.types import CallbackQuery
router = Router(name="fallback_callback")
@router.callback_query(~StateFilter(None))
async def in_state_callback(callback: CallbackQuery):
await callback.answer("Fallback text in state", show_alert=True)
@router.callback_query()
async def fallback_callback(callback: CallbackQuery):
await callback.answer("Fallback text", show_alert=True)
+29 -7
View File
@@ -17,7 +17,7 @@ from app.states.travel import (
)
router = Router(name="menu_callback")
router = Router(name="notes_callback")
@router.callback_query(
@@ -110,12 +110,26 @@ async def create_note_file_id(message: Message, state: FSMContext):
data["author_id"] = message.from_user.id
session.add(Note(**data))
note = Note(**data)
session.add(note)
session.commit()
if not note or note == []:
return
if note.file_type == "photo":
file_name = f"Photo ID: {note.id}"
elif note.file_type == "video":
file_name = f"Video ID: {note.id}"
elif note.file_type == "voice":
file_name = f"Voice ID: {note.id}"
else:
file_name = note.file_name
await message.answer(
messages.NOTE_ADDED.format(file_name=data["file_name"]),
messages.NOTE_ADDED.format(file_name=file_name),
)
await state.clear()
@@ -299,13 +313,21 @@ async def travel_notedelete_callback(
note = Note().get_note_queryset_by_id(note_id)
note_first = note.first()
file_name = note_first.file_name
travel = note_first.travel
if not note or note == []:
return
note_first = note.first()
travel = note_first.travel
if note_first.file_type == "photo":
file_name = f"Photo ID: {note_first.id}"
elif note_first.file_type == "video":
file_name = f"Video ID: {note_first.id}"
elif note_first.file_type == "voice":
file_name = f"Voice ID: {note_first.id}"
else:
file_name = note_first.file_name
note.delete()
session.commit()
+34 -1
View File
@@ -11,6 +11,7 @@ from app.config import Config
from app.filters.user import Registered, RegisteredCallback
from app.keyboards.builders import travels_keyboard
from app.keyboards.travel import get as travel_get
from app.keyboards.routes import get as routes_get
from app.models.travel import Travel
from app.models.user import User
from app.states.travel import (
@@ -19,7 +20,7 @@ from app.states.travel import (
from app.utils.states import delete_message_from_state, handle_validation_error
router = Router(name="menu_callback")
router = Router(name="travel_callback")
@router.callback_query(
@@ -301,3 +302,35 @@ async def delete_travel_callback(
)
await callback.answer()
@router.callback_query(
F.data.startswith("travel_routes"),
RegisteredCallback(),
StateFilter(None),
)
async def travel_routes_callback(
callback: CallbackQuery,
):
if (
callback.message is None
or callback.data is None
or not isinstance(callback.message, Message)
):
return
travel_id = int(callback.data.replace("travel_routes_", ""))
travel = Travel().get_travel_by_id(travel_id)
if not travel:
await callback.answer()
return
await callback.message.edit_text(
travel.get_travel_text(),
reply_markup=routes_get(travel),
)
await callback.answer()