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:
ITQ
2024-03-26 07:49:50 +03:00
parent 65719a61ef
commit 88dfe1704d
24 changed files with 1571 additions and 301 deletions
+176 -1
View File
@@ -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()