Show all events across all pages with page badges
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m1s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m1s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 /<slug>/ — full page with first page of entries
|
||||
GET /<slug>/entries — HTMX fragment for infinite scroll
|
||||
POST /<slug>/tickets/adjust — adjust ticket quantity, returns HX-Refresh
|
||||
POST /<slug>/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,
|
||||
)
|
||||
|
||||
2
shared
2
shared
Submodule shared updated: 6e438dbfdc...16e4d3aa57
@@ -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') %}
|
||||
<article class="rounded-xl bg-white shadow-sm border border-stone-200 p-4">
|
||||
<div class="flex flex-col sm:flex-row sm:items-start justify-between gap-3">
|
||||
{# Left: event info #}
|
||||
<div class="flex-1 min-w-0">
|
||||
{% 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 ~ '/' %}
|
||||
<a href="{{ entry_href }}" class="hover:text-emerald-700">
|
||||
<h2 class="text-lg font-semibold text-stone-900">{{ entry.name }}</h2>
|
||||
</a>
|
||||
|
||||
{% if entry.calendar_name %}
|
||||
<span class="inline-block mt-1 px-2 py-0.5 rounded-full text-xs font-medium bg-sky-100 text-sky-700">
|
||||
{{ entry.calendar_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap items-center gap-1.5 mt-1">
|
||||
{% if page_title and page_title != post.title %}
|
||||
<a href="{{ events_url('/' ~ page_slug ~ '/') }}"
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-800 hover:bg-amber-200">
|
||||
{{ page_title }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if entry.calendar_name %}
|
||||
<span class="inline-block px-2 py-0.5 rounded-full text-xs font-medium bg-sky-100 text-sky-700">
|
||||
{{ entry.calendar_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mt-1 text-sm text-stone-500">
|
||||
{{ entry.start_at.strftime('%H:%M') }}{% if entry.end_at %} – {{ entry.end_at.strftime('%H:%M') }}{% endif %}
|
||||
|
||||
@@ -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') %}
|
||||
<article class="rounded-xl bg-white shadow-sm border border-stone-200 overflow-hidden">
|
||||
{% 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 ~ '/' %}
|
||||
<div class="p-3">
|
||||
<a href="{{ entry_href }}" class="hover:text-emerald-700">
|
||||
<h2 class="text-base font-semibold text-stone-900 line-clamp-2">{{ entry.name }}</h2>
|
||||
</a>
|
||||
|
||||
{% if entry.calendar_name %}
|
||||
<span class="inline-block mt-1 px-2 py-0.5 rounded-full text-xs font-medium bg-sky-100 text-sky-700">
|
||||
{{ entry.calendar_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
<div class="flex flex-wrap items-center gap-1 mt-1">
|
||||
{% if page_title and page_title != post.title %}
|
||||
<a href="{{ events_url('/' ~ page_slug ~ '/') }}"
|
||||
class="inline-block px-2 py-0.5 rounded-full text-xs font-medium bg-amber-100 text-amber-800 hover:bg-amber-200">
|
||||
{{ page_title }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if entry.calendar_name %}
|
||||
<span class="inline-block px-2 py-0.5 rounded-full text-xs font-medium bg-sky-100 text-sky-700">
|
||||
{{ entry.calendar_name }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="mt-1 text-xs text-stone-500">
|
||||
<a href="{{ day_href }}" class="hover:text-stone-700">{{ entry.start_at.strftime('%a %-d %b') }}</a>
|
||||
|
||||
@@ -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') ~ '/') %}
|
||||
<div class="pt-2 pb-1">
|
||||
<a href="{{ date_href }}" class="hover:text-stone-700">
|
||||
<h3 class="text-sm font-semibold text-stone-500 uppercase tracking-wide">
|
||||
{{ entry_date }}
|
||||
</h3>
|
||||
</a>
|
||||
<h3 class="text-sm font-semibold text-stone-500 uppercase tracking-wide">
|
||||
{{ entry_date }}
|
||||
</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% include "_types/page_summary/_card.html" %}
|
||||
|
||||
Reference in New Issue
Block a user