Skip to content

Commit

Permalink
feat: render schedule from svg
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisfabrics committed Nov 17, 2024
1 parent eccd94c commit 2df5606
Show file tree
Hide file tree
Showing 8 changed files with 971 additions and 131 deletions.
104 changes: 102 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ sqlalchemy = "^2.0.23"
uvicorn = "^0.31.0"
babel = "^2.16.0"
fluent-runtime = "^0.4.0"
cairosvg = "^2.7.1"

[tool.ruff]
line-length = 120
Expand Down
3 changes: 2 additions & 1 deletion src/api/bookings/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ async def get_my_bookings(verified: VerifiedDepWithUserID) -> list[ViewBooking]:
)
async def form_schedule(
start_of_week: datetime.date | None = Query(default_factory=_get_start_of_week, example=_get_start_of_week()),
from_user_id: int | None = None,
) -> Response:
image_bytes = await booking_repository.form_schedule(start_of_week)
image_bytes = await booking_repository.form_schedule(start_of_week, from_user_id)
return Response(content=image_bytes, media_type="image/png")


Expand Down
4 changes: 2 additions & 2 deletions src/bot/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ async def delete_booking(self, booking_id: int, telegram_id: int) -> bool:
response = await client.delete(f"/bookings/{booking_id}")
return True if response.status_code == 200 else False

async def get_image_schedule(self, start_of_week: datetime.date) -> bytes | None:
params = {"start_of_week": start_of_week.isoformat()}
async def get_image_schedule(self, start_of_week: datetime.date, from_user_id: int) -> bytes | None:
params = {"start_of_week": start_of_week.isoformat(), "from_user_id": from_user_id}
async with self._create_client() as client:
response = await client.get("/bookings/form_schedule", params=params)
if response.status_code == 200:
Expand Down
5 changes: 5 additions & 0 deletions src/bot/routers/booking/widgets/time_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ async def _render_keyboard(self, data: dict, manager: DialogManager) -> list[lis
keyboard_builer.button(text="🔴", url=f"https://t.me/{booked_by_alias}")
elif available and not blocked:
keyboard_builer.button(text=time_text, callback_data=time_callback_data)
else:
keyboard_builer.button(
text=" ",
callback_data=self._item_callback_data("None"),
)
else:
keyboard_builer.button(
text=" ",
Expand Down
4 changes: 2 additions & 2 deletions src/bot/routers/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_image_schedule_kb() -> types.InlineKeyboardMarkup:
)
async def get_image_schedule(message: types.Message):
start_of_week = get_start_of_week()
image_bytes = await api_client.get_image_schedule(start_of_week)
image_bytes = await api_client.get_image_schedule(start_of_week, message.from_user.id)
photo = BufferedInputFile(image_bytes, "schedule.png")
await message.answer(_("Sending image for the current week..."))
await message.answer_photo(photo=photo)
Expand Down Expand Up @@ -70,7 +70,7 @@ async def get_image_schedule_for_current_week(callback: types.CallbackQuery):
choice = callback.data
chat_id = callback.from_user.id
start_of_week = get_start_of_week(choice == "schedule:current_week")
image_bytes = await api_client.get_image_schedule(start_of_week)
image_bytes = await api_client.get_image_schedule(start_of_week, callback.from_user.id)
photo = BufferedInputFile(image_bytes, "schedule.png")
if choice == "schedule:current_week":
await callback.message.answer(_("Sending image for the current week..."))
Expand Down
Loading

0 comments on commit 2df5606

Please sign in to comment.