Adjust weekend page high pithing

Don't highlight a week number when showing weekends for different year.

Example: https://edwardbetts.com/agenda/weekends?year=2100&week=1

Closes: #198
This commit is contained in:
Edward Betts 2025-07-15 17:48:44 +02:00
parent 7f12282c42
commit f499015466
2 changed files with 18 additions and 8 deletions

View file

@ -16,9 +16,12 @@
</thead>
<tbody>
{% set current_isocalendar = today.isocalendar() %}
{% for weekend in items %}
{% set week_number = weekend.date.isocalendar().week %}
{% if week_number == current_week_number %}
{% set iso_week_year = weekend.date.isocalendar().year %}
{% if week_number == current_week_number and iso_week_year == current_isocalendar.year %}
{% set extra_class = " bg-warning-subtle" %}
{% else %}
{% set extra_class = "" %}

View file

@ -28,6 +28,7 @@ import agenda.trip
import agenda.trip_schengen
import agenda.utils
from agenda import calendar, format_list_with_ampersand, travel, uk_tz
from agenda.schengen import get_country_flag
from agenda.types import StrDict, Trip
app = flask.Flask(__name__)
@ -40,7 +41,6 @@ agenda.error_mail.setup_error_mail(app)
@app.template_filter("country_flag")
def country_flag_filter(country_code: str) -> str:
"""Convert country code to emoji flag."""
from agenda.schengen import get_country_flag
return get_country_flag(country_code)
@ -247,13 +247,17 @@ async def weekends() -> str:
week = int(week_str)
year = int(year_str) if year_str else today.year
if week < 1 or week > 53:
return flask.abort(400, description="Week number must be between 1 and 53.")
return flask.abort(
400, description="Week number must be between 1 and 53."
)
# Calculate the date of the first day of the given week
jan_1 = date(year, 1, 1)
week_1_start = jan_1 - timedelta(days=jan_1.weekday())
start = week_1_start + timedelta(weeks=week - 1)
except ValueError:
return flask.abort(400, description="Invalid week or year format. Use integers.")
return flask.abort(
400, description="Invalid week or year format. Use integers."
)
else:
start = date(today.year, 1, 1)
@ -263,7 +267,10 @@ async def weekends() -> str:
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
"weekends.html",
items=weekends,
current_week_number=current_week_number,
today=today,
)
@ -415,11 +422,11 @@ def get_trip_list(
for trip in agenda.trip.build_trip_list(route_distances=route_distances)
if flask.g.user.is_authenticated or not trip.private
]
# Add Schengen compliance information to each trip
for trip in trips:
agenda.trip_schengen.add_schengen_compliance_to_trip(trip)
return trips
@ -556,7 +563,7 @@ def trip_page(start: str) -> str:
prev_trip, trip, next_trip = get_prev_current_and_next_trip(start, trip_list)
if not trip:
flask.abort(404)
# Add Schengen compliance information
trip = agenda.trip_schengen.add_schengen_compliance_to_trip(trip)