Prefill date selectors on leadership page with earliest/latest dates

This commit is contained in:
Peter Stockings
2026-02-24 20:09:18 +11:00
parent 93c6822439
commit 10256a1283
3 changed files with 46 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
from flask import Blueprint, render_template
from app.auth import login_required
from app.db import query
from app.db import query, query_one
from app import SYDNEY_TZ
from datetime import timezone
bp = Blueprint("leaderboard", __name__)
@@ -54,4 +56,25 @@ def index():
# Sort by % lost (descending)
ranked.sort(key=lambda x: x["pct_lost"], reverse=True)
return render_template("leaderboard.html", ranked=ranked)
# Get earliest and latest check-in dates for date pickers
date_range = query_one("""
SELECT
MIN(c.checked_in_at) AS earliest,
MAX(c.checked_in_at) AS latest
FROM checkins c
JOIN users u ON u.id = c.user_id
WHERE u.is_private = FALSE
""")
earliest = ""
latest = ""
if date_range and date_range["earliest"]:
e = date_range["earliest"]
l = date_range["latest"]
if e.tzinfo is None:
e = e.replace(tzinfo=timezone.utc)
if l.tzinfo is None:
l = l.replace(tzinfo=timezone.utc)
earliest = e.astimezone(SYDNEY_TZ).strftime("%Y-%m-%d")
latest = l.astimezone(SYDNEY_TZ).strftime("%Y-%m-%d")
return render_template("leaderboard.html", ranked=ranked, earliest=earliest, latest=latest)