Replace sx_call() with render_to_sx() across all services
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m6s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m6s
Python no longer generates s-expression strings. All SX rendering now goes through render_to_sx() which builds AST from native Python values and evaluates via async_eval_to_sx() — no SX string literals in Python. - Add render_to_sx()/render_to_html() infrastructure in shared/sx/helpers.py - Add (abort status msg) IO primitive in shared/sx/primitives_io.py - Convert all 9 services: ~650 sx_call() invocations replaced - Convert shared helpers (root_header_sx, full_page_sx, etc.) to async - Fix likes service import bug (likes.models → models) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,7 @@ from typing import Any
|
||||
|
||||
from shared.sx.jinja_bridge import load_service_components
|
||||
from shared.sx.helpers import (
|
||||
call_url, sx_call, SxExpr,
|
||||
call_url, render_to_sx,
|
||||
root_header_sx, full_page_sx, header_child_sx,
|
||||
)
|
||||
from shared.infrastructure.urls import market_product_url, cart_url
|
||||
@@ -29,24 +29,24 @@ load_service_components(os.path.dirname(os.path.dirname(__file__)),
|
||||
async def render_checkout_error_page(ctx: dict, error: str | None = None, order: Any | None = None) -> str:
|
||||
"""Full page: checkout error (sx wire format)."""
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
auth_hdr = sx_call("auth-header-row", account_url=account_url)
|
||||
hdr = root_header_sx(ctx)
|
||||
hdr = "(<> " + hdr + " " + header_child_sx(auth_hdr) + ")"
|
||||
filt = sx_call("checkout-error-header")
|
||||
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
|
||||
hdr = await root_header_sx(ctx)
|
||||
hdr = "(<> " + hdr + " " + await header_child_sx(auth_hdr) + ")"
|
||||
filt = await render_to_sx("checkout-error-header")
|
||||
|
||||
err_msg = error or "Unexpected error while creating the hosted checkout session."
|
||||
order_sx = ""
|
||||
if order:
|
||||
order_sx = sx_call("checkout-error-order-id", oid=f"#{order.id}")
|
||||
back_url = cart_url("/")
|
||||
content = sx_call(
|
||||
order_sx = await render_to_sx("checkout-error-order-id", oid=f"#{order.id}")
|
||||
from shared.sx.parser import SxExpr
|
||||
content = await render_to_sx(
|
||||
"checkout-error-content",
|
||||
msg=err_msg,
|
||||
order=SxExpr(order_sx) if order_sx else None,
|
||||
back_url=back_url,
|
||||
back_url=cart_url("/"),
|
||||
)
|
||||
|
||||
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
return await full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -58,12 +58,12 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
calendar_entries: list | None = None,
|
||||
order_tickets: list | None = None) -> str:
|
||||
"""Full page: checkout return after SumUp payment (sx wire format)."""
|
||||
from shared.sx.parser import serialize
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
filt = sx_call("checkout-return-header", status=status)
|
||||
filt = await render_to_sx("checkout-return-header", status=status)
|
||||
|
||||
if not order:
|
||||
content = sx_call("checkout-return-missing")
|
||||
content = await render_to_sx("checkout-return-missing")
|
||||
else:
|
||||
# Serialize order data for defcomp
|
||||
order_dict = {
|
||||
@@ -87,7 +87,7 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
],
|
||||
}
|
||||
|
||||
summary = sx_call("order-summary-card",
|
||||
summary = await render_to_sx("order-summary-card",
|
||||
order_id=order.id,
|
||||
created_at=order_dict["created_at_formatted"],
|
||||
description=order.description, status=order.status,
|
||||
@@ -101,19 +101,19 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
item_parts = []
|
||||
for item_d in order_dict["items"]:
|
||||
if item_d["product_image"]:
|
||||
img = sx_call("order-item-image",
|
||||
img = await render_to_sx("order-item-image",
|
||||
src=item_d["product_image"],
|
||||
alt=item_d["product_title"] or "Product image")
|
||||
else:
|
||||
img = sx_call("order-item-no-image")
|
||||
item_parts.append(sx_call("order-item-row",
|
||||
img = await render_to_sx("order-item-no-image")
|
||||
item_parts.append(await render_to_sx("order-item-row",
|
||||
href=item_d["product_url"], img=SxExpr(img),
|
||||
title=item_d["product_title"] or "Unknown product",
|
||||
pid=f"Product ID: {item_d['product_id']}",
|
||||
qty=f"Qty: {item_d['quantity']}",
|
||||
price=f"{item_d['currency'] or order.currency or 'GBP'} {item_d['unit_price_formatted']}",
|
||||
))
|
||||
items = sx_call("order-items-panel",
|
||||
items = await render_to_sx("order-items-panel",
|
||||
items=SxExpr("(<> " + " ".join(item_parts) + ")"))
|
||||
|
||||
# Calendar entries
|
||||
@@ -131,13 +131,13 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
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(sx_call("order-calendar-entry",
|
||||
cal_parts.append(await render_to_sx("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 = sx_call("order-calendar-section",
|
||||
calendar = await render_to_sx("order-calendar-section",
|
||||
items=SxExpr("(<> " + " ".join(cal_parts) + ")"))
|
||||
|
||||
# Tickets
|
||||
@@ -156,24 +156,24 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
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(sx_call("checkout-return-ticket",
|
||||
tk_parts.append(await render_to_sx("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 = sx_call("checkout-return-tickets",
|
||||
tickets = await render_to_sx("checkout-return-tickets",
|
||||
items=SxExpr("(<> " + " ".join(tk_parts) + ")"))
|
||||
|
||||
# Status message
|
||||
status_msg = ""
|
||||
if order.status == "failed":
|
||||
status_msg = sx_call("checkout-return-failed", order_id=order.id)
|
||||
status_msg = await render_to_sx("checkout-return-failed", order_id=order.id)
|
||||
elif order.status == "paid":
|
||||
status_msg = sx_call("checkout-return-paid")
|
||||
status_msg = await render_to_sx("checkout-return-paid")
|
||||
|
||||
content = sx_call("checkout-return-content",
|
||||
content = await render_to_sx("checkout-return-content",
|
||||
summary=SxExpr(summary),
|
||||
items=SxExpr(items) if items else None,
|
||||
calendar=SxExpr(calendar) if calendar else None,
|
||||
@@ -182,8 +182,8 @@ async def render_checkout_return_page(ctx: dict, order: Any | None,
|
||||
)
|
||||
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
auth_hdr = sx_call("auth-header-row", account_url=account_url)
|
||||
hdr = root_header_sx(ctx)
|
||||
hdr = "(<> " + hdr + " " + header_child_sx(auth_hdr) + ")"
|
||||
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
|
||||
hdr = await root_header_sx(ctx)
|
||||
hdr = "(<> " + hdr + " " + await header_child_sx(auth_hdr) + ")"
|
||||
|
||||
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
return await full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
|
||||
Reference in New Issue
Block a user