You've already forked Travel-Agent
feat: Added notes creation, view and deletion, added route planning, added location list with current weather and nearby locations, code improvements and fixes
This commit is contained in:
+176
-1
@@ -58,9 +58,10 @@ def travels_keyboard(travels: list, page: int, pages: int, user_id: int):
|
||||
),
|
||||
)
|
||||
|
||||
total_pages = 1 if pages == 0 else pages
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=f"{page + 1}/{pages}",
|
||||
text=f"{page + 1}/{total_pages}",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
@@ -83,3 +84,177 @@ def travels_keyboard(travels: list, page: int, pages: int, user_id: int):
|
||||
builder.row(*navigation_row)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
def locations_keyboard(locations: list, page: int, pages: int, travel_id: int):
|
||||
builder = InlineKeyboardBuilder()
|
||||
rows = []
|
||||
|
||||
start_index = page * Config.PAGE_SIZE
|
||||
end_index = min((page + 1) * Config.PAGE_SIZE, len(locations))
|
||||
|
||||
for location in locations[start_index:end_index]:
|
||||
button_text = location.location
|
||||
|
||||
rows.append(
|
||||
InlineKeyboardButton(
|
||||
text=button_text,
|
||||
callback_data=f"travel_location_detail_{location.id}",
|
||||
),
|
||||
)
|
||||
|
||||
for _ in range(0, Config.PAGE_SIZE - len(rows)):
|
||||
rows.append(InlineKeyboardButton(text=" ", callback_data="pass"))
|
||||
|
||||
builder.row(*rows, width=2)
|
||||
|
||||
navigation_row = []
|
||||
|
||||
if page > 0:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_locations_{travel_id}_{page - 1}",
|
||||
),
|
||||
)
|
||||
else:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=" ",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
total_pages = 1 if pages == 0 else pages
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=f"{page + 1}/{total_pages}",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
if page < pages - 1:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text="➡️",
|
||||
callback_data=f"travel_locations_{travel_id}_{page + 1}",
|
||||
),
|
||||
)
|
||||
else:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=" ",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
builder.row(*navigation_row)
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_detail_{travel_id}",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
def notes_keyboard(notes, page: int, pages: int, travel_id: int):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
rows = []
|
||||
|
||||
start_index = page * Config.PAGE_SIZE
|
||||
end_index = min((page + 1) * Config.PAGE_SIZE, len(notes))
|
||||
|
||||
for note in notes[start_index:end_index]:
|
||||
if note.file_type == "photo":
|
||||
button_text = f"Photo ID: {note.id}"
|
||||
else:
|
||||
button_text = note.file_name
|
||||
|
||||
rows.append(
|
||||
InlineKeyboardButton(
|
||||
text=button_text,
|
||||
callback_data=f"travel_note_detail_{note.id}",
|
||||
),
|
||||
)
|
||||
|
||||
for _ in range(0, Config.PAGE_SIZE - len(rows)):
|
||||
rows.append(InlineKeyboardButton(text=" ", callback_data="pass"))
|
||||
|
||||
builder.row(*rows, width=2)
|
||||
|
||||
navigation_row = []
|
||||
|
||||
if page > 0:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_notes_page_{travel_id}_{page - 1}",
|
||||
),
|
||||
)
|
||||
else:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=" ",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
total_pages = 1 if pages == 0 else pages
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=f"{page + 1}/{total_pages}",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
if page < pages - 1:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text="➡️",
|
||||
callback_data=f"travel_notes_page_{travel_id}_{page + 1}",
|
||||
),
|
||||
)
|
||||
else:
|
||||
navigation_row.append(
|
||||
InlineKeyboardButton(
|
||||
text=" ",
|
||||
callback_data="pass",
|
||||
),
|
||||
)
|
||||
|
||||
builder.row(*navigation_row)
|
||||
|
||||
builder.row(
|
||||
InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_detail_{travel_id}",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
def sights_keyboard(sights: list):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
rows = []
|
||||
|
||||
for sight in sights:
|
||||
button_text = sight[0]
|
||||
|
||||
rows.append(
|
||||
InlineKeyboardButton(
|
||||
text=button_text,
|
||||
callback_data=f"travel_sight_detail_{sight[1]}",
|
||||
),
|
||||
)
|
||||
|
||||
for _ in range(0, 20 - len(rows)):
|
||||
rows.append(InlineKeyboardButton(text=" ", callback_data="pass"))
|
||||
|
||||
builder.row(*rows, width=2)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
__all__ = ("get",)
|
||||
|
||||
from aiogram import types
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
|
||||
def get(travel_id: int, location_id: int):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⏩ Get nearby sights",
|
||||
callback_data=f"travel_locationsights_{location_id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="☁️ Current weather",
|
||||
callback_data=f"travel_locationweather_{location_id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="❌ Delete location",
|
||||
callback_data=f"travel_locationdelete_{location_id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_locations_page_{travel_id}_0",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
def get_public(travel_id: int, location_id: int):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_locations_page_{travel_id}_0",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
@@ -23,8 +23,8 @@ def get():
|
||||
callback_data="menu_travels",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="🔵 Temp",
|
||||
callback_data="menu_temp",
|
||||
text="❓ Help",
|
||||
callback_data="menu_help",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
__all__ = ("get",)
|
||||
|
||||
from aiogram import types
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
|
||||
def get(travel_id: int, note):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⏩ View note",
|
||||
callback_data=f"travel_notesend_{note.id}",
|
||||
),
|
||||
)
|
||||
|
||||
if note.public:
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🔒 Make private",
|
||||
callback_data=f"travel_note_change_privacy_{note.id}",
|
||||
),
|
||||
)
|
||||
else:
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🔓 Make public",
|
||||
callback_data=f"travel_note_change_privacy_{note.id}",
|
||||
),
|
||||
)
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="❌ Delete note",
|
||||
callback_data=f"travel_notedelete_{note.id}",
|
||||
),
|
||||
)
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data=f"travel_detail_{travel_id}",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
+133
-10
@@ -3,54 +3,177 @@ __all__ = ("get",)
|
||||
from aiogram import types
|
||||
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
||||
|
||||
from app.models.travel import Travel
|
||||
from app.utils.geo import get_location_by_name
|
||||
from app.utils.map import get_url_map
|
||||
|
||||
|
||||
def get(travel: Travel):
|
||||
locations = Travel().get_sorted_locations(travel, asc=False)
|
||||
coordinats = []
|
||||
|
||||
for location in locations:
|
||||
geocode = get_location_by_name(location.location)
|
||||
coordinats.append(
|
||||
[geocode[1].raw.get("lat"), geocode[1].raw.get("lon")],
|
||||
)
|
||||
|
||||
def get(travel_id: int):
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="📝 Change title",
|
||||
callback_data=f"travel_change_{travel_id}_title",
|
||||
callback_data=f"travel_change_{travel.id}_title",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="ℹ️ Change description",
|
||||
callback_data=f"travel_change_{travel_id}_description",
|
||||
callback_data=f"travel_change_{travel.id}_description",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Locations",
|
||||
callback_data=f"travel_locations_{travel_id}",
|
||||
callback_data=f"travel_locations_page_{travel.id}_0",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="➕ Add location",
|
||||
callback_data=f"travel_add_location_{travel_id}",
|
||||
callback_data=f"travel_add_location_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="👤 Users",
|
||||
callback_data=f"travel_users_{travel_id}",
|
||||
callback_data=f"travel_users_page_{travel.id}_0",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="➕ Add user",
|
||||
callback_data=f"travel_add_user_{travel_id}",
|
||||
callback_data=f"travel_add_user_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="📝 Notes",
|
||||
callback_data=f"travel_notes_{travel_id}",
|
||||
callback_data=f"travel_notes_page_{travel.id}_0",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="➕ Add note",
|
||||
callback_data=f"travel_add_note_{travel_id}",
|
||||
callback_data=f"travel_add_note_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route by car",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="car",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route on foot",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="foot",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route by bike",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="bike",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="❌ Delete travel",
|
||||
callback_data=f"travel_delete_{travel_id}",
|
||||
callback_data=f"travel_delete_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="⬅️",
|
||||
callback_data="travels",
|
||||
),
|
||||
)
|
||||
|
||||
return builder.as_markup()
|
||||
|
||||
|
||||
def get_public(travel: Travel):
|
||||
locations = Travel().get_sorted_locations(travel, asc=False)
|
||||
coordinats = []
|
||||
|
||||
for location in locations:
|
||||
geocode = get_location_by_name(location.location)
|
||||
coordinats.append(
|
||||
[geocode[1].raw.get("lat"), geocode[1].raw.get("lon")],
|
||||
)
|
||||
|
||||
builder = InlineKeyboardBuilder()
|
||||
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Locations",
|
||||
callback_data=f"travel_locations_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="👤 Users",
|
||||
callback_data=f"travel_users_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="📝 Notes",
|
||||
callback_data=f"travel_notes_{travel.id}",
|
||||
),
|
||||
types.InlineKeyboardButton(
|
||||
text="➕ Add note",
|
||||
callback_data=f"travel_add_note_{travel.id}",
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route by car",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="car",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route on foot",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="foot",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
types.InlineKeyboardButton(
|
||||
text="🗺️ Route by bike",
|
||||
web_app=types.WebAppInfo(
|
||||
url=get_url_map(
|
||||
coordinats=coordinats,
|
||||
profile="bike",
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
builder.row(
|
||||
|
||||
Reference in New Issue
Block a user