From dad53fd1b513abf3493a73d098a6c98690a575c8 Mon Sep 17 00:00:00 2001 From: giles Date: Sun, 22 Feb 2026 23:05:11 +0000 Subject: [PATCH] Show all events across all pages with page badges Page summary now loads all upcoming events globally, not just the current page's. Each card shows an amber page badge when the event belongs to a different page. Links use the correct page slug. Co-Authored-By: Claude Opus 4.6 --- bp/page/routes.py | 33 +++++++++++++------ shared | 2 +- templates/_types/page_summary/_card.html | 23 +++++++++---- templates/_types/page_summary/_card_tile.html | 23 +++++++++---- templates/_types/page_summary/_cards.html | 9 ++--- 5 files changed, 61 insertions(+), 29 deletions(-) diff --git a/bp/page/routes.py b/bp/page/routes.py index cbcee8d..5be7143 100644 --- a/bp/page/routes.py +++ b/bp/page/routes.py @@ -1,11 +1,11 @@ """ Page summary blueprint — shows upcoming events across all calendars -for a container (e.g. the village hall). +for all pages. Routes: GET // — full page with first page of entries GET //entries — HTMX fragment for infinite scroll - POST //tickets/adjust — adjust ticket quantity, returns HX-Refresh + POST //tickets/adjust — adjust ticket quantity inline """ from __future__ import annotations @@ -19,10 +19,10 @@ from shared.services.registry import services def register() -> Blueprint: bp = Blueprint("page_summary", __name__) - async def _load_entries(post_id, page, per_page=20): - """Load upcoming entries + pending ticket counts for current user.""" + async def _load_entries(page, per_page=20): + """Load all upcoming entries + pending ticket counts + page titles.""" entries, has_more = await services.calendar.upcoming_entries_for_container( - g.s, "page", post_id, page=page, per_page=per_page, + g.s, page=page, per_page=per_page, ) # Pending ticket counts keyed by entry_id @@ -36,20 +36,33 @@ def register() -> Blueprint: if t.entry_id is not None: pending_tickets[t.entry_id] = pending_tickets.get(t.entry_id, 0) + 1 - return entries, has_more, pending_tickets + # Batch-load page info for container_ids + page_info = {} # {post_id: {title, slug}} + if entries: + post_ids = list({ + e.calendar_container_id + for e in entries + if e.calendar_container_type == "page" and e.calendar_container_id + }) + if post_ids: + posts = await services.blog.get_posts_by_ids(g.s, post_ids) + for p in posts: + page_info[p.id] = {"title": p.title, "slug": p.slug} + + return entries, has_more, pending_tickets, page_info @bp.get("/") async def index(): - post = g.post_data["post"] view = request.args.get("view", "list") page = int(request.args.get("page", 1)) - entries, has_more, pending_tickets = await _load_entries(post["id"], page) + entries, has_more, pending_tickets, page_info = await _load_entries(page) ctx = dict( entries=entries, has_more=has_more, pending_tickets=pending_tickets, + page_info=page_info, page=page, view=view, ) @@ -63,17 +76,17 @@ def register() -> Blueprint: @bp.get("/entries") async def entries_fragment(): - post = g.post_data["post"] view = request.args.get("view", "list") page = int(request.args.get("page", 1)) - entries, has_more, pending_tickets = await _load_entries(post["id"], page) + entries, has_more, pending_tickets, page_info = await _load_entries(page) html = await render_template( "_types/page_summary/_cards.html", entries=entries, has_more=has_more, pending_tickets=pending_tickets, + page_info=page_info, page=page, view=view, ) diff --git a/shared b/shared index 6e438db..16e4d3a 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 6e438dbfdc03768ca75b45040883fd8c998aecce +Subproject commit 16e4d3aa57c6cc37921a3c3fe0954f8c854ed051 diff --git a/templates/_types/page_summary/_card.html b/templates/_types/page_summary/_card.html index dfee007..27f12cb 100644 --- a/templates/_types/page_summary/_card.html +++ b/templates/_types/page_summary/_card.html @@ -1,19 +1,30 @@ {# List card for page summary — one entry #} +{% set pi = page_info.get(entry.calendar_container_id, {}) %} +{% set page_slug = pi.get('slug', post.slug) %} +{% set page_title = pi.get('title') %}
{# Left: event info #}
- {% set day_href = events_url('/' ~ post.slug ~ '/calendars/' ~ entry.calendar_slug ~ '/day/' ~ entry.start_at.strftime('%Y/%-m/%-d') ~ '/') %} + {% set day_href = events_url('/' ~ page_slug ~ '/calendars/' ~ entry.calendar_slug ~ '/day/' ~ entry.start_at.strftime('%Y/%-m/%-d') ~ '/') %} {% set entry_href = day_href ~ 'entries/' ~ entry.id ~ '/' %}

{{ entry.name }}

- {% if entry.calendar_name %} - - {{ entry.calendar_name }} - - {% endif %} +
+ {% if page_title and page_title != post.title %} + + {{ page_title }} + + {% endif %} + {% if entry.calendar_name %} + + {{ entry.calendar_name }} + + {% endif %} +
{{ entry.start_at.strftime('%H:%M') }}{% if entry.end_at %} – {{ entry.end_at.strftime('%H:%M') }}{% endif %} diff --git a/templates/_types/page_summary/_card_tile.html b/templates/_types/page_summary/_card_tile.html index dd82390..7d13cca 100644 --- a/templates/_types/page_summary/_card_tile.html +++ b/templates/_types/page_summary/_card_tile.html @@ -1,17 +1,28 @@ {# Tile card for page summary — compact event tile #} +{% set pi = page_info.get(entry.calendar_container_id, {}) %} +{% set page_slug = pi.get('slug', post.slug) %} +{% set page_title = pi.get('title') %}
- {% set day_href = events_url('/' ~ post.slug ~ '/calendars/' ~ entry.calendar_slug ~ '/day/' ~ entry.start_at.strftime('%Y/%-m/%-d') ~ '/') %} + {% set day_href = events_url('/' ~ page_slug ~ '/calendars/' ~ entry.calendar_slug ~ '/day/' ~ entry.start_at.strftime('%Y/%-m/%-d') ~ '/') %} {% set entry_href = day_href ~ 'entries/' ~ entry.id ~ '/' %}

{{ entry.name }}

- {% if entry.calendar_name %} - - {{ entry.calendar_name }} - - {% endif %} +
+ {% if page_title and page_title != post.title %} + + {{ page_title }} + + {% endif %} + {% if entry.calendar_name %} + + {{ entry.calendar_name }} + + {% endif %} +
{{ entry.start_at.strftime('%a %-d %b') }} diff --git a/templates/_types/page_summary/_cards.html b/templates/_types/page_summary/_cards.html index a197731..b6958ab 100644 --- a/templates/_types/page_summary/_cards.html +++ b/templates/_types/page_summary/_cards.html @@ -5,13 +5,10 @@ {# Date header when date changes (list view only) #} {% set entry_date = entry.start_at.strftime('%A %-d %B %Y') %} {% if loop.first or entry_date != entries[loop.index0 - 1].start_at.strftime('%A %-d %B %Y') %} - {% set date_href = events_url('/' ~ post.slug ~ '/calendars/' ~ entry.calendar_slug ~ '/day/' ~ entry.start_at.strftime('%Y/%-m/%-d') ~ '/') %}
- -

- {{ entry_date }} -

-
+

+ {{ entry_date }} +

{% endif %} {% include "_types/page_summary/_card.html" %}