Remove render_to_sx from public API: enforce sx_call for all service code
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m44s

Replace ~250 render_to_sx calls across all services with sync sx_call,
converting many async functions to sync where no other awaits remained.
Make render_to_sx/render_to_sx_with_env private (_render_to_sx).
Add (post-header-ctx) IO primitive and shared post/post-admin defmacros.
Convert built-in post/post-admin layouts from Python to register_sx_layout
with .sx defcomps. Remove dead post_admin_mobile_nav_sx.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-04 19:30:45 +00:00
parent 57e0d0c341
commit 959e63d440
61 changed files with 1352 additions and 1208 deletions

View File

@@ -15,17 +15,17 @@ async def _render_checkout_return(ctx: dict, order=None, status: str = "",
calendar_entries=None, order_tickets=None) -> str:
"""Render checkout return page — replaces sx_components helper."""
from shared.sx.helpers import (
render_to_sx, root_header_sx, header_child_sx, full_page_sx, call_url,
sx_call, root_header_sx, header_child_sx, full_page_sx, call_url,
)
from shared.sx.parser import SxExpr
from shared.infrastructure.urls import market_product_url
filt = await render_to_sx("checkout-return-header", status=status)
filt = sx_call("checkout-return-header", status=status)
if not order:
content = await render_to_sx("checkout-return-missing")
content = sx_call("checkout-return-missing")
else:
summary = await render_to_sx("order-summary-card",
summary = sx_call("order-summary-card",
order_id=order.id,
created_at=order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else None,
description=order.description, status=order.status,
@@ -39,19 +39,19 @@ async def _render_checkout_return(ctx: dict, order=None, status: str = "",
for item in order.items:
product_url = market_product_url(item.product_slug)
if item.product_image:
img = await render_to_sx("order-item-image",
img = sx_call("order-item-image",
src=item.product_image,
alt=item.product_title or "Product image")
else:
img = await render_to_sx("order-item-no-image")
item_parts.append(await render_to_sx("order-item-row",
img = sx_call("order-item-no-image")
item_parts.append(sx_call("order-item-row",
href=product_url, img=SxExpr(img),
title=item.product_title or "Unknown product",
pid=f"Product ID: {item.product_id}",
qty=f"Qty: {item.quantity}",
price=f"{item.currency or order.currency or 'GBP'} {item.unit_price or 0:.2f}",
))
items = await render_to_sx("order-items-panel",
items = sx_call("order-items-panel",
items=SxExpr("(<> " + " ".join(item_parts) + ")"))
calendar = ""
@@ -68,13 +68,13 @@ async def _render_checkout_return(ctx: dict, order=None, status: str = "",
ds = e.start_at.strftime("%-d %b %Y, %H:%M") if e.start_at else ""
if e.end_at:
ds += f" \u2013 {e.end_at.strftime('%-d %b %Y, %H:%M')}"
cal_parts.append(await render_to_sx("order-calendar-entry",
cal_parts.append(sx_call("order-calendar-entry",
name=e.name,
pill=f"inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium {pill}",
status=st.capitalize(), date_str=ds,
cost=f"\u00a3{e.cost or 0:.2f}",
))
calendar = await render_to_sx("order-calendar-section",
calendar = sx_call("order-calendar-section",
items=SxExpr("(<> " + " ".join(cal_parts) + ")"))
tickets = ""
@@ -92,23 +92,23 @@ async def _render_checkout_return(ctx: dict, order=None, status: str = "",
ds = tk.entry_start_at.strftime("%-d %b %Y, %H:%M") if tk.entry_start_at else ""
if tk.entry_end_at:
ds += f" \u2013 {tk.entry_end_at.strftime('%-d %b %Y, %H:%M')}"
tk_parts.append(await render_to_sx("checkout-return-ticket",
tk_parts.append(sx_call("checkout-return-ticket",
name=tk.entry_name, pill=pill_cls,
state=st.replace("_", " ").capitalize(),
type_name=tk.ticket_type_name or None,
date_str=ds, code=tk.code,
price=f"\u00a3{tk.price or 0:.2f}",
))
tickets = await render_to_sx("checkout-return-tickets",
tickets = sx_call("checkout-return-tickets",
items=SxExpr("(<> " + " ".join(tk_parts) + ")"))
status_msg = ""
if order.status == "failed":
status_msg = await render_to_sx("checkout-return-failed", order_id=order.id)
status_msg = sx_call("checkout-return-failed", order_id=order.id)
elif order.status == "paid":
status_msg = await render_to_sx("checkout-return-paid")
status_msg = sx_call("checkout-return-paid")
content = await render_to_sx("checkout-return-content",
content = sx_call("checkout-return-content",
summary=SxExpr(summary),
items=SxExpr(items) if items else None,
calendar=SxExpr(calendar) if calendar else None,
@@ -117,7 +117,7 @@ async def _render_checkout_return(ctx: dict, order=None, status: str = "",
)
account_url = call_url(ctx, "account_url", "")
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
auth_hdr = sx_call("auth-header-row", account_url=account_url)
hdr = "(<> " + await root_header_sx(ctx) + " " + await header_child_sx(auth_hdr) + ")"
return await full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)

View File

@@ -70,16 +70,16 @@ def register() -> Blueprint:
if not hosted_url:
from shared.sx.page import get_template_context
from shared.sx.helpers import render_to_sx, root_header_sx, header_child_sx, full_page_sx, call_url
from shared.sx.helpers import sx_call, root_header_sx, header_child_sx, full_page_sx, call_url
from shared.sx.parser import SxExpr
from shared.infrastructure.urls import cart_url
tctx = await get_template_context()
account_url = call_url(tctx, "account_url", "")
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
auth_hdr = sx_call("auth-header-row", account_url=account_url)
hdr = "(<> " + await root_header_sx(tctx) + " " + await header_child_sx(auth_hdr) + ")"
filt = await render_to_sx("checkout-error-header")
order_sx = await render_to_sx("checkout-error-order-id", oid=f"#{order.id}")
content = await render_to_sx(
filt = sx_call("checkout-error-header")
order_sx = sx_call("checkout-error-order-id", oid=f"#{order.id}")
content = sx_call(
"checkout-error-content",
msg="No hosted checkout URL returned from SumUp when trying to reopen payment.",
order=SxExpr(order_sx),

View File

@@ -73,7 +73,7 @@ def register(url_prefix: str) -> Blueprint:
result = await g.s.execute(stmt)
orders = result.scalars().all()
from shared.sx.helpers import sx_response, render_to_sx
from shared.sx.helpers import sx_response, sx_call
from shared.utils import route_prefix
pfx = route_prefix()
@@ -95,16 +95,16 @@ def register(url_prefix: str) -> Blueprint:
# Build just the rows fragment (not full table) for infinite scroll
parts = []
for od in order_dicts:
parts.append(await render_to_sx("order-row-pair",
parts.append(sx_call("order-row-pair",
order=od,
detail_url_prefix=detail_prefix))
if page < total_pages:
parts.append(await render_to_sx("infinite-scroll",
parts.append(sx_call("infinite-scroll",
url=rows_url + qs_fn(page=page + 1),
page=page, total_pages=total_pages,
id_prefix="orders", colspan=5))
else:
parts.append(await render_to_sx("order-end-row"))
parts.append(sx_call("order-end-row"))
sx_src = "(<> " + " ".join(parts) + ")"
resp = sx_response(sx_src)