Phase 6: Replace render_template() with s-expression rendering in all GET routes
Migrate ~52 GET route handlers across all 7 services from Jinja render_template() to s-expression component rendering. Each service gets a sexp_components.py with page/oob/cards render functions. - Add per-service sexp_components.py (account, blog, cart, events, federation, market, orders) with full page, OOB, and pagination card rendering - Add shared/sexp/helpers.py with call_url, root_header_html, full_page, oob_page utilities - Update all GET routes to use get_template_context() + render fns - Fix get_template_context() to inject Jinja globals (URL helpers) - Add qs_filter to base_context for sexp filter URL building - Mount sexp_components.py in docker-compose.dev.yml for all services - Import sexp_components in app.py for Hypercorn --reload watching - Fix route_prefix import (shared.utils not shared.infrastructure.urls) - Fix federation choose-username missing actor in context - Fix market page_markets missing post in context Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,18 +14,16 @@ def register(url_prefix: str) -> Blueprint:
|
||||
@bp.get("/")
|
||||
async def overview():
|
||||
from quart import g
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import render_overview_page, render_overview_oob
|
||||
|
||||
page_groups = await get_cart_grouped_by_page(g.s)
|
||||
ctx = await get_template_context()
|
||||
|
||||
if not is_htmx_request():
|
||||
html = await render_template(
|
||||
"_types/cart/overview/index.html",
|
||||
page_groups=page_groups,
|
||||
)
|
||||
html = await render_overview_page(ctx, page_groups)
|
||||
else:
|
||||
html = await render_template(
|
||||
"_types/cart/overview/_oob_elements.html",
|
||||
page_groups=page_groups,
|
||||
)
|
||||
html = await render_overview_oob(ctx, page_groups)
|
||||
return await make_response(html)
|
||||
|
||||
return bp
|
||||
|
||||
@@ -40,10 +40,20 @@ def register(url_prefix: str) -> Blueprint:
|
||||
ticket_total=ticket_total,
|
||||
)
|
||||
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import render_page_cart_page, render_page_cart_oob
|
||||
|
||||
ctx = await get_template_context()
|
||||
if not is_htmx_request():
|
||||
html = await render_template("_types/cart/page/index.html", **tpl_ctx)
|
||||
html = await render_page_cart_page(
|
||||
ctx, post, cart, cal_entries, page_tickets,
|
||||
ticket_groups, total, calendar_total, ticket_total,
|
||||
)
|
||||
else:
|
||||
html = await render_template("_types/cart/page/_oob_elements.html", **tpl_ctx)
|
||||
html = await render_page_cart_oob(
|
||||
ctx, post, cart, cal_entries, page_tickets,
|
||||
ticket_groups, total, calendar_total, ticket_total,
|
||||
)
|
||||
return await make_response(html)
|
||||
|
||||
@bp.post("/checkout/")
|
||||
|
||||
@@ -55,12 +55,16 @@ def register() -> Blueprint:
|
||||
order = result.scalar_one_or_none()
|
||||
if not order:
|
||||
return await make_response("Order not found", 404)
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import render_order_page, render_order_oob
|
||||
|
||||
ctx = await get_template_context()
|
||||
calendar_entries = ctx.get("calendar_entries")
|
||||
|
||||
if not is_htmx_request():
|
||||
# Normal browser request: full page with layout
|
||||
html = await render_template("_types/order/index.html", order=order,)
|
||||
html = await render_order_page(ctx, order, calendar_entries, url_for)
|
||||
else:
|
||||
# HTMX navigation (page 1): main panel + OOB elements
|
||||
html = await render_template("_types/order/_oob_elements.html", order=order,)
|
||||
html = await render_order_oob(ctx, order, calendar_entries, url_for)
|
||||
|
||||
return await make_response(html)
|
||||
|
||||
|
||||
@@ -136,24 +136,30 @@ def register(url_prefix: str) -> Blueprint:
|
||||
result = await g.s.execute(stmt)
|
||||
orders = result.scalars().all()
|
||||
|
||||
context = {
|
||||
"orders": orders,
|
||||
"page": page,
|
||||
"total_pages": total_pages,
|
||||
"search": search,
|
||||
"search_count": total_count, # For search display
|
||||
}
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import (
|
||||
render_orders_page,
|
||||
render_orders_rows,
|
||||
render_orders_oob,
|
||||
)
|
||||
|
||||
ctx = await get_template_context()
|
||||
qs_fn = makeqs_factory()
|
||||
|
||||
# Determine which template to use based on request type and pagination
|
||||
if not is_htmx_request():
|
||||
# Normal browser request: full page with layout
|
||||
html = await render_template("_types/orders/index.html", **context)
|
||||
html = await render_orders_page(
|
||||
ctx, orders, page, total_pages, search, total_count,
|
||||
url_for, qs_fn,
|
||||
)
|
||||
elif page > 1:
|
||||
# HTMX pagination: just table rows + sentinel
|
||||
html = await render_template("_types/orders/_rows.html", **context)
|
||||
html = await render_orders_rows(
|
||||
ctx, orders, page, total_pages, url_for, qs_fn,
|
||||
)
|
||||
else:
|
||||
# HTMX navigation (page 1): main panel + OOB elements
|
||||
html = await render_template("_types/orders/_oob_elements.html", **context)
|
||||
html = await render_orders_oob(
|
||||
ctx, orders, page, total_pages, search, total_count,
|
||||
url_for, qs_fn,
|
||||
)
|
||||
|
||||
resp = await make_response(html)
|
||||
resp.headers["Hx-Push-Url"] = _current_url_without_page()
|
||||
|
||||
Reference in New Issue
Block a user