Files
rose-ash/orders/bp/fragments/routes.py
giles 8013317b41
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m14s
Phase 5: Page layouts as s-expressions — components, fragments, error pages
Add 9 new shared s-expression components (cart-mini, auth-menu,
account-nav-item, calendar-entry-nav, calendar-link-nav, market-link-nav,
post-card, base-shell, error-page) and wire them into all fragment route
handlers. 404/403 error pages now render entirely via s-expressions as a
full-page proof-of-concept, with Jinja fallback on failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 15:25:11 +00:00

42 lines
1.2 KiB
Python

"""Orders app fragment endpoints.
Fragments:
account-nav-item "orders" link for account dashboard
"""
from __future__ import annotations
from quart import Blueprint, Response, request
from shared.infrastructure.fragments import FRAGMENT_HEADER
def register():
bp = Blueprint("fragments", __name__, url_prefix="/internal/fragments")
async def _account_nav_item():
from shared.infrastructure.urls import orders_url
from shared.sexp.jinja_bridge import sexp as render_sexp
return render_sexp(
'(~account-nav-item :href href :label "orders")',
href=orders_url("/"),
)
_handlers = {
"account-nav-item": _account_nav_item,
}
@bp.before_request
async def _require_fragment_header():
if not request.headers.get(FRAGMENT_HEADER):
return Response("", status=403)
@bp.get("/<fragment_type>")
async def get_fragment(fragment_type: str):
handler = _handlers.get(fragment_type)
if handler is None:
return Response("", status=200, content_type="text/html")
html = await handler()
return Response(html, status=200, content_type="text/html")
return bp