Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_next_public_holiday() -> Optional[dict]:
return {"name": name, "date": dt}


def get_upcoming_holidays() -> dict[str, date]:
def get_upcoming_holidays() -> dict[date, str]:
"""
Get all holidays for the current year and the next year
Returned as a dict of {date: name}
Expand Down
8 changes: 6 additions & 2 deletions app/templates/frames/holidays/upcoming.html.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<h4>Upcoming Holidays</h4>
<ul>
{% for dt, name in upcoming_holidays.items() %}
<li>{{ name }} <small>({{ dt }})</small></li>
{% for hol in upcoming_holidays %}
{% if not hol.public and hol.duration != 1.0 %}
<li>{{ hol.name }} - {{ hol.duration }} days <small>({{ hol.date }})</small></li>
{% else %}
<li>{{ hol.name }} <small>({{ hol.date }})</small></li>
{% endif %}
{% endfor %}
</ul>
9 changes: 9 additions & 0 deletions app/viewmodels.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from dataclasses import dataclass


Expand All @@ -8,3 +9,11 @@ class TimeStats:
remaining_this_week: str
remaining_today: str
overtime: str


@dataclass
class Holiday:
name: str
date: datetime.date
public: bool
duration: float
39 changes: 38 additions & 1 deletion app/views/holidays.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from app.controllers.user.util import login_required
from app.lib.blocks import render
from app.lib.logger import get_logger
from app.viewmodels import Holiday

v = Blueprint("holidays", __name__)
logger = get_logger(__name__)
Expand All @@ -13,16 +14,52 @@
@v.get("/holidays/upcoming")
@login_required
def upcoming_holidays():
import arrow

from app.models import Leave

_settings = settings.fetch()

if not _settings.holiday_location:
flash("Please set a holiday location to view the holidays list", "warning")
return redirect(url_for("settings.general_settings"))

# TODO:
# This isn't quite right
# One list is the list of all public holidays and the other is the list the user has actually taken off
# We should:
# 1. Show these lists separately
# 2. If a user has taken a public holiday we should pull the name of that holiday into the leave list
upcoming_holidays: list[Holiday] = []

upcoming_public_holidays = holidays.get_upcoming_holidays()
for date, name in upcoming_public_holidays.items():
upcoming_holidays.append(
Holiday(
name=name,
date=date,
public=True,
duration=1,
)
)

upcoming_al = Leave.since(arrow.utcnow().int_timestamp)
for leave in upcoming_al:
upcoming_holidays.append(
Holiday(
name=leave.note or "Annual Leave",
date=arrow.get(leave.start).date(),
public=bool(leave.public_holiday),
duration=leave.duration,
)
)

upcoming_holidays = sorted(upcoming_holidays, key=lambda x: x.date)

return render(
"pages/holidays.html.j2",
page="upcoming",
upcoming_holidays=holidays.get_upcoming_holidays(),
upcoming_holidays=upcoming_holidays,
)


Expand Down