Replace widget registry with fragment fetches (Phase 5)
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 42s

Account nav and page panels now fetched from events/cart fragments
instead of using shared widget registry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 13:58:10 +00:00
parent 3016724133
commit daea61a481
2 changed files with 21 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
"""Account pages blueprint. """Account pages blueprint.
Moved from federation/bp/auth — newsletters, widget pages (tickets, bookings). Moved from federation/bp/auth — newsletters, fragment pages (tickets, bookings).
Mounted at root /. Mounted at root /.
""" """
from __future__ import annotations from __future__ import annotations
@@ -17,8 +17,8 @@ from sqlalchemy import select
from shared.models import UserNewsletter from shared.models import UserNewsletter
from shared.models.ghost_membership_entities import GhostNewsletter from shared.models.ghost_membership_entities import GhostNewsletter
from shared.services.widget_registry import widgets
from shared.infrastructure.urls import login_url from shared.infrastructure.urls import login_url
from shared.infrastructure.fragments import fetch_fragment, fetch_fragments
oob = { oob = {
"oob_extends": "oob_elements.html", "oob_extends": "oob_elements.html",
@@ -36,8 +36,12 @@ def register(url_prefix="/"):
account_bp = Blueprint("account", __name__, url_prefix=url_prefix) account_bp = Blueprint("account", __name__, url_prefix=url_prefix)
@account_bp.context_processor @account_bp.context_processor
def context(): async def context():
return {"oob": oob, "account_nav_links": widgets.account_nav} events_nav, cart_nav = await fetch_fragments([
("events", "account-nav-item", {}),
("cart", "account-nav-item", {}),
])
return {"oob": oob, "account_nav_html": events_nav + cart_nav}
@account_bp.get("/") @account_bp.get("/")
async def account(): async def account():
@@ -128,33 +132,35 @@ def register(url_prefix="/"):
un=un, un=un,
) )
# Catch-all for widget pages — must be last # Catch-all for fragment-provided pages — must be last
@account_bp.get("/<slug>/") @account_bp.get("/<slug>/")
async def widget_page(slug): async def fragment_page(slug):
from shared.browser.app.utils.htmx import is_htmx_request from shared.browser.app.utils.htmx import is_htmx_request
from quart import abort from quart import abort
widget = widgets.account_page_by_slug(slug)
if not widget:
abort(404)
if not g.get("user"): if not g.get("user"):
return redirect(login_url(f"/{slug}/")) return redirect(login_url(f"/{slug}/"))
ctx = await widget.context_fn(g.s, user_id=g.user.id) fragment_html = await fetch_fragment(
w_oob = {**oob, "main": widget.template} "events", "account-page",
params={"slug": slug, "user_id": str(g.user.id)},
)
if not fragment_html:
abort(404)
w_oob = {**oob, "main": "_types/auth/_fragment_panel.html"}
if not is_htmx_request(): if not is_htmx_request():
html = await render_template( html = await render_template(
"_types/auth/index.html", "_types/auth/index.html",
oob=w_oob, oob=w_oob,
**ctx, page_fragment_html=fragment_html,
) )
else: else:
html = await render_template( html = await render_template(
"_types/auth/_oob_elements.html", "_types/auth/_oob_elements.html",
oob=w_oob, oob=w_oob,
**ctx, page_fragment_html=fragment_html,
) )
return await make_response(html) return await make_response(html)

2
shared

Submodule shared updated: d2e07e047e...65c4989d08