diff --git a/agenda/busy.py b/agenda/busy.py index d6978d4..81d43ea 100644 --- a/agenda/busy.py +++ b/agenda/busy.py @@ -2,7 +2,7 @@ import itertools import typing -from datetime import date, datetime, timedelta +from datetime import date, timedelta import flask @@ -43,11 +43,11 @@ def busy_event(e: Event) -> bool: def get_busy_events( - today: date, config: flask.config.Config, trips: list[Trip] + start: date, config: flask.config.Config, trips: list[Trip] ) -> list[Event]: """Find busy events from a year ago to two years in the future.""" - last_year = today - timedelta(days=365) - next_year = today + timedelta(days=2 * 365) + last_year = start - timedelta(days=365) + next_year = start + timedelta(days=2 * 365) my_data = config["PERSONAL_DATA"] events = events_yaml.read(my_data, last_year, next_year, skip_trips=True) @@ -71,7 +71,7 @@ def get_busy_events( busy_events = [ e for e in sorted(events, key=lambda e: e.as_date) - if (e.as_date >= today or (e.end_date and e.end_as_date >= today)) + if (e.as_date >= start or (e.end_date and e.end_as_date >= start)) and e.as_date < next_year and busy_event(e) ] @@ -79,16 +79,15 @@ def get_busy_events( return busy_events -def weekends(busy_events: list[Event]) -> typing.Sequence[StrDict]: +def weekends(start: date, busy_events: list[Event]) -> typing.Sequence[StrDict]: """Next ten weekends.""" - today = datetime.today() - weekday = today.weekday() + weekday = start.weekday() # Calculate the difference to the next or previous Saturday if weekday == 6: # Sunday - start_date = (today - timedelta(days=1)).date() + start_date = start - timedelta(days=1) else: - start_date = (today + timedelta(days=(5 - weekday))).date() + start_date = start + timedelta(days=(5 - weekday)) weekends_info = [] for i in range(52): diff --git a/templates/weekends.html b/templates/weekends.html index f443ff6..eccd177 100644 --- a/templates/weekends.html +++ b/templates/weekends.html @@ -17,15 +17,21 @@ {% for weekend in items %} - - - {{ weekend.date.isocalendar().week }} + {% set week_number = weekend.date.isocalendar().week %} + {% if week_number == current_week_number %} + {% set extra_class = " bg-warning-subtle" %} + {% else %} + {% set extra_class = "" %} + {% endif %} + + + {{ week_number }} - + {{ weekend.date.strftime("%-d %b %Y") }} {% for day in "saturday", "sunday" %} - + {% if extra_class %}{% else %}{% endif %} {% if weekend[day] %} {% for event in weekend[day] %} {{ event.title }}{% if not loop.last %},{%endif %} diff --git a/web_view.py b/web_view.py index ebbbdf2..20fd71b 100755 --- a/web_view.py +++ b/web_view.py @@ -224,11 +224,17 @@ async def gaps_page() -> str: @app.route("/weekends") async def weekends() -> str: """List of available gaps.""" - now = datetime.now() + today = date.today() + + current_week_number = today.isocalendar().week + + start = date(today.year, 1, 1) trip_list = agenda.trip.build_trip_list() - busy_events = agenda.busy.get_busy_events(now.date(), app.config, trip_list) - weekends = agenda.busy.weekends(busy_events) - return flask.render_template("weekends.html", today=now.date(), items=weekends) + busy_events = agenda.busy.get_busy_events(start, app.config, trip_list) + weekends = agenda.busy.weekends(start, busy_events) + return flask.render_template( + "weekends.html", items=weekends, current_week_number=current_week_number + ) @app.route("/travel")