Phase 4: add container-nav/cards fragment handlers, use market fragment
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m4s

Events provides container-nav (calendar entries + links) and
container-cards (batch entries for blog listing) as fragments.
Day and entry routes fetch market container-nav via fragment instead
of widget registry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 13:33:25 +00:00
parent de80c393e4
commit 503f7ca7d8
7 changed files with 165 additions and 47 deletions

View File

@@ -27,7 +27,7 @@ from datetime import datetime, timezone
import math
import logging
from shared.services.widget_registry import widgets
from shared.infrastructure.fragments import fetch_fragment
from ..ticket_types.routes import register as register_ticket_types
@@ -222,25 +222,17 @@ def register():
ticket_type_id=tt.id,
)
# Widget-driven container nav (market links, etc.)
container_nav_loaded = []
# Fetch container nav from market (skip calendar — we're on a calendar page)
container_nav_html = ""
post_data = getattr(g, "post_data", None)
if post_data:
post_id = post_data["post"]["id"]
post_slug = post_data["post"]["slug"]
for w in widgets.container_nav:
if w.domain.startswith("calendar"):
continue # skip — we're already on a calendar page
try:
wctx = await w.context_fn(
g.s, container_type="page", container_id=post_id,
post_slug=post_slug,
)
has_data = any(v for v in wctx.values() if isinstance(v, list) and v)
if has_data:
container_nav_loaded.append({"widget": w, "ctx": wctx})
except Exception:
pass
container_nav_html = await fetch_fragment("market", "container-nav", params={
"container_type": "page",
"container_id": str(post_id),
"post_slug": post_slug,
})
return {
"entry": calendar_entry,
@@ -249,7 +241,7 @@ def register():
"ticket_sold_count": ticket_sold_count,
"user_ticket_count": user_ticket_count,
"user_ticket_counts_by_type": user_ticket_counts_by_type,
"container_nav_widgets": container_nav_loaded,
"container_nav_html": container_nav_html,
}
@bp.get("/")
@require_admin

View File

@@ -11,7 +11,7 @@ from bp.calendar_entries.routes import register as register_calendar_entries
from .admin.routes import register as register_admin
from shared.browser.app.redis_cacher import cache_page
from shared.services.widget_registry import widgets
from shared.infrastructure.fragments import fetch_fragment
from models.calendars import CalendarSlot # add this import
@@ -78,25 +78,17 @@ def register():
result = await g.s.execute(stmt)
day_slots = list(result.scalars())
# Widget-driven container nav (market links, etc.)
container_nav_loaded = []
# Fetch container nav from market (skip calendar — we're on a calendar page)
container_nav_html = ""
post_data = getattr(g, "post_data", None)
if post_data:
post_id = post_data["post"]["id"]
post_slug = post_data["post"]["slug"]
for w in widgets.container_nav:
if w.domain.startswith("calendar"):
continue # skip — we're already on a calendar page
try:
wctx = await w.context_fn(
g.s, container_type="page", container_id=post_id,
post_slug=post_slug,
)
has_data = any(v for v in wctx.values() if isinstance(v, list) and v)
if has_data:
container_nav_loaded.append({"widget": w, "ctx": wctx})
except Exception:
pass
container_nav_html = await fetch_fragment("market", "container-nav", params={
"container_type": "page",
"container_id": str(post_id),
"post_slug": post_slug,
})
return {
"qsession": qsession,
@@ -108,7 +100,7 @@ def register():
"user_entries": visible.user_entries,
"confirmed_entries": visible.confirmed_entries,
"day_slots": day_slots,
"container_nav_widgets": container_nav_loaded,
"container_nav_html": container_nav_html,
}
@@ -142,23 +134,21 @@ def register():
@bp.get("/w/<widget_domain>/")
async def widget_paginate(widget_domain: str, **kwargs):
"""Generic paginated widget endpoint for infinite scroll."""
"""Proxies paginated widget requests to the appropriate fragment provider."""
page = int(request.args.get("page", 1))
post_data = getattr(g, "post_data", None)
if not post_data:
abort(404)
post_id = post_data["post"]["id"]
post_slug = post_data["post"]["slug"]
for w in widgets.container_nav:
if w.domain == widget_domain:
ctx = await w.context_fn(
g.s, container_type="page", container_id=post_id,
post_slug=post_slug, page=page,
)
html = await render_template(
w.template, ctx=ctx, post=post_data["post"],
)
return await make_response(html)
if widget_domain == "market":
html = await fetch_fragment("market", "container-nav", params={
"container_type": "page",
"container_id": str(post_id),
"post_slug": post_slug,
})
return await make_response(html or "")
abort(404)
return bp

View File

@@ -6,9 +6,10 @@ by other coop apps via the fragment client.
from __future__ import annotations
from quart import Blueprint, Response, request
from quart import Blueprint, Response, g, render_template, request
from shared.infrastructure.fragments import FRAGMENT_HEADER
from shared.services.registry import services
def register():
@@ -29,6 +30,70 @@ def register():
html = await handler()
return Response(html, status=200, content_type="text/html")
# --- container-nav fragment: calendar entries + calendar links -----------
async def _container_nav_handler():
container_type = request.args.get("container_type", "page")
container_id = int(request.args.get("container_id", 0))
post_slug = request.args.get("post_slug", "")
paginate_url_base = request.args.get("paginate_url", "")
page = int(request.args.get("page", 1))
exclude = request.args.get("exclude", "")
excludes = [e.strip() for e in exclude.split(",") if e.strip()]
html_parts = []
# Calendar entries nav
if not any(e.startswith("calendar") for e in excludes):
entries, has_more = await services.calendar.associated_entries(
g.s, container_type, container_id, page,
)
if entries:
html_parts.append(await render_template(
"fragments/container_nav_entries.html",
entries=entries, has_more=has_more,
page=page, post_slug=post_slug,
paginate_url_base=paginate_url_base,
))
# Calendar links nav
if not any(e.startswith("calendar") for e in excludes):
calendars = await services.calendar.calendars_for_container(
g.s, container_type, container_id,
)
if calendars:
html_parts.append(await render_template(
"fragments/container_nav_calendars.html",
calendars=calendars, post_slug=post_slug,
))
return "\n".join(html_parts)
_handlers["container-nav"] = _container_nav_handler
# --- container-cards fragment: entries for blog listing cards ------------
async def _container_cards_handler():
post_ids_raw = request.args.get("post_ids", "")
post_slugs_raw = request.args.get("post_slugs", "")
post_ids = [int(x) for x in post_ids_raw.split(",") if x.strip()]
post_slugs = [x.strip() for x in post_slugs_raw.split(",") if x.strip()]
if not post_ids:
return ""
# Build post_id -> slug mapping
slug_map = {}
for i, pid in enumerate(post_ids):
slug_map[pid] = post_slugs[i] if i < len(post_slugs) else ""
batch = await services.calendar.confirmed_entries_for_posts(g.s, post_ids)
return await render_template(
"fragments/container_cards_entries.html",
batch=batch, post_ids=post_ids, slug_map=slug_map,
)
_handlers["container-cards"] = _container_cards_handler
bp._fragment_handlers = _handlers
return bp

2
shared

Submodule shared updated: ab674ada31...d2e07e047e

View File

@@ -0,0 +1,33 @@
{# Calendar entries for blog listing cards — served as fragment from events app.
Each post's entries are delimited by comment markers so the consumer can
extract per-post HTML via simple string splitting. #}
{% for post_id in post_ids %}
<!-- card-widget:{{ post_id }} -->
{% set widget_entries = batch.get(post_id, []) %}
{% if widget_entries %}
<div class="mt-4 mb-2">
<h3 class="text-sm font-semibold text-stone-700 mb-2 px-2">Events:</h3>
<div class="overflow-x-auto scrollbar-hide" style="scroll-behavior: smooth;">
<div class="flex gap-2 px-2">
{% for entry in widget_entries %}
{% set _post_slug = slug_map.get(post_id, '') %}
{% set _entry_path = '/' + _post_slug + '/calendars/' + entry.calendar_slug + '/' + entry.start_at.year|string + '/' + entry.start_at.month|string + '/' + entry.start_at.day|string + '/entries/' + entry.id|string + '/' %}
<a
href="{{ events_url(_entry_path) }}"
class="flex flex-col gap-1 px-3 py-2 bg-stone-50 hover:bg-stone-100 rounded border border-stone-200 transition text-sm whitespace-nowrap flex-shrink-0 min-w-[180px]">
<div class="font-medium text-stone-900 truncate">{{ entry.name }}</div>
<div class="text-xs text-stone-600">
{{ entry.start_at.strftime('%a, %b %d') }}
</div>
<div class="text-xs text-stone-500">
{{ entry.start_at.strftime('%H:%M') }}
{% if entry.end_at %} {{ entry.end_at.strftime('%H:%M') }}{% endif %}
</div>
</a>
{% endfor %}
</div>
</div>
</div>
{% endif %}
<!-- /card-widget:{{ post_id }} -->
{% endfor %}

View File

@@ -0,0 +1,10 @@
{# Calendar links nav — served as fragment from events app #}
{% for calendar in calendars %}
{% set local_href=events_url('/' + post_slug + '/calendars/' + calendar.slug + '/') %}
<a
href="{{ local_href }}"
class="{{styles.nav_button_less_pad}}">
<i class="fa fa-calendar" aria-hidden="true"></i>
<div>{{calendar.name}}</div>
</a>
{% endfor %}

View File

@@ -0,0 +1,28 @@
{# Calendar entries nav — served as fragment from events app #}
{% for entry in entries %}
{% set _entry_path = '/' + post_slug + '/calendars/' + entry.calendar_slug + '/' + entry.start_at.year|string + '/' + entry.start_at.month|string + '/' + entry.start_at.day|string + '/entries/' + entry.id|string + '/' %}
<a
href="{{ events_url(_entry_path) }}"
class="{{styles.nav_button_less_pad}}"
>
<div class="w-8 h-8 rounded bg-stone-200 flex-shrink-0"></div>
<div class="flex-1 min-w-0">
<div class="font-medium truncate">{{ entry.name }}</div>
<div class="text-xs text-stone-600 truncate">
{{ entry.start_at.strftime('%b %d, %Y at %H:%M') }}
{% if entry.end_at %} {{ entry.end_at.strftime('%H:%M') }}{% endif %}
</div>
</div>
</a>
{% endfor %}
{# Infinite scroll sentinel — URL points back to the consumer app #}
{% if has_more and paginate_url_base %}
<div id="entries-load-sentinel-{{ page }}"
hx-get="{{ paginate_url_base }}?page={{ page + 1 }}"
hx-trigger="intersect once"
hx-swap="beforebegin"
_="on htmx:afterRequest trigger scroll on #associated-entries-container"
class="flex-shrink-0 w-1">
</div>
{% endif %}