Rebrand sexp → sx across web platform (173 files)

Rename all sexp directories, files, identifiers, and references to sx.
artdag/ excluded (separate media processing DSL).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 11:06:57 +00:00
parent 17cebe07e7
commit e8bc228c7f
174 changed files with 3126 additions and 2952 deletions

View File

@@ -1,6 +1,6 @@
from __future__ import annotations
import path_setup # noqa: F401 # adds shared/ to sys.path
import sexp.sexp_components as sexp_components # noqa: F401 # ensure Hypercorn --reload watches this file
import sx.sx_components as sx_components # noqa: F401 # ensure Hypercorn --reload watches this file
from pathlib import Path
from types import SimpleNamespace
@@ -71,7 +71,7 @@ def create_app() -> "Quart":
])
# Load orders-specific s-expression components
from sexp.sexp_components import load_orders_components
from sx.sx_components import load_orders_components
load_orders_components()
app.register_blueprint(register_fragments())

View File

@@ -14,9 +14,9 @@ def register():
async def _account_nav_item():
from shared.infrastructure.urls import orders_url
from shared.sexp.helpers import sexp_call
from shared.sx.helpers import sx_call
return sexp_call("account-nav-item",
return sx_call("account-nav-item",
href=orders_url("/"),
label="orders")
@@ -33,8 +33,8 @@ def register():
async def get_fragment(fragment_type: str):
handler = _handlers.get(fragment_type)
if handler is None:
return Response("", status=200, content_type="text/sexp")
return Response("", status=200, content_type="text/sx")
src = await handler()
return Response(src, status=200, content_type="text/sexp")
return Response(src, status=200, content_type="text/sx")
return bp

View File

@@ -9,7 +9,7 @@ from shared.browser.app.payments.sumup import create_checkout as sumup_create_ch
from shared.config import config
from shared.infrastructure.cart_identity import current_cart_identity
from shared.sexp.page import get_template_context
from shared.sx.page import get_template_context
from services.check_sumup_status import check_sumup_status
from shared.browser.app.utils.htmx import is_htmx_request
@@ -48,7 +48,7 @@ def register() -> Blueprint:
if not order:
return await make_response("Order not found", 404)
from sexp.sexp_components import render_order_page, render_order_oob
from sx.sx_components import render_order_page, render_order_oob
ctx = await get_template_context()
calendar_entries = ctx.get("calendar_entries")
@@ -57,9 +57,9 @@ def register() -> Blueprint:
html = await render_order_page(ctx, order, calendar_entries, url_for)
return await make_response(html)
else:
from shared.sexp.helpers import sexp_response
sexp_src = await render_order_oob(ctx, order, calendar_entries, url_for)
return sexp_response(sexp_src)
from shared.sx.helpers import sx_response
sx_src = await render_order_oob(ctx, order, calendar_entries, url_for)
return sx_response(sx_src)
@bp.get("/pay/")
async def order_pay(order_id: int):
@@ -100,8 +100,8 @@ def register() -> Blueprint:
await g.s.flush()
if not hosted_url:
from shared.sexp.page import get_template_context
from sexp.sexp_components import render_checkout_error_page
from shared.sx.page import get_template_context
from sx.sx_components import render_checkout_error_page
tctx = await get_template_context()
html = await render_checkout_error_page(tctx, error="No hosted checkout URL returned from SumUp when trying to reopen payment.", order=order)
return await make_response(html, 500)

View File

@@ -116,8 +116,8 @@ def register(url_prefix: str) -> Blueprint:
result = await g.s.execute(stmt)
orders = result.scalars().all()
from shared.sexp.page import get_template_context
from sexp.sexp_components import (
from shared.sx.page import get_template_context
from sx.sx_components import (
render_orders_page,
render_orders_rows,
render_orders_oob,
@@ -133,19 +133,19 @@ def register(url_prefix: str) -> Blueprint:
)
resp = await make_response(html)
elif page > 1:
# Sexp wire format — client renders order rows
from shared.sexp.helpers import sexp_response
sexp_src = await render_orders_rows(
# Sx wire format — client renders order rows
from shared.sx.helpers import sx_response
sx_src = await render_orders_rows(
ctx, orders, page, total_pages, url_for, qs_fn,
)
resp = sexp_response(sexp_src)
resp = sx_response(sx_src)
else:
from shared.sexp.helpers import sexp_response
sexp_src = await render_orders_oob(
from shared.sx.helpers import sx_response
sx_src = await render_orders_oob(
ctx, orders, page, total_pages, search, total_count,
url_for, qs_fn,
)
resp = sexp_response(sexp_src)
resp = sx_response(sx_src)
resp.headers["Hx-Push-Url"] = _current_url_without_page()
return _vary(resp)

View File

@@ -10,27 +10,27 @@ from __future__ import annotations
import os
from typing import Any
from shared.sexp.jinja_bridge import load_service_components
from shared.sexp.helpers import (
call_url, root_header_sexp,
full_page_sexp, header_child_sexp, oob_page_sexp,
sexp_call, SexpExpr,
search_mobile_sexp, search_desktop_sexp,
from shared.sx.jinja_bridge import load_service_components
from shared.sx.helpers import (
call_url, root_header_sx,
full_page_sx, header_child_sx, oob_page_sx,
sx_call, SxExpr,
search_mobile_sx, search_desktop_sx,
)
from shared.infrastructure.urls import market_product_url, cart_url
# Load orders-specific .sexpr components at import time
# Load orders-specific .sx components at import time
load_service_components(os.path.dirname(os.path.dirname(__file__)))
# ---------------------------------------------------------------------------
# Header helpers (shared auth + orders-specific) — sexp-native
# Header helpers (shared auth + orders-specific) — sx-native
# ---------------------------------------------------------------------------
def _auth_nav_sexp(ctx: dict) -> str:
"""Auth section desktop nav items as sexp."""
def _auth_nav_sx(ctx: dict) -> str:
"""Auth section desktop nav items as sx."""
parts = [
sexp_call("nav-link",
sx_call("nav-link",
href=call_url(ctx, "account_url", "/newsletters/"),
label="newsletters",
select_colours=ctx.get("select_colours", ""),
@@ -42,21 +42,21 @@ def _auth_nav_sexp(ctx: dict) -> str:
return "(<> " + " ".join(parts) + ")"
def _auth_header_sexp(ctx: dict, *, oob: bool = False) -> str:
"""Build the account section header row as sexp."""
return sexp_call(
def _auth_header_sx(ctx: dict, *, oob: bool = False) -> str:
"""Build the account section header row as sx."""
return sx_call(
"menu-row-sx",
id="auth-row", level=1, colour="sky",
link_href=call_url(ctx, "account_url", "/"),
link_label="account", icon="fa-solid fa-user",
nav=SexpExpr(_auth_nav_sexp(ctx)),
nav=SxExpr(_auth_nav_sx(ctx)),
child_id="auth-header-child", oob=oob,
)
def _orders_header_sexp(ctx: dict, list_url: str) -> str:
"""Build the orders section header row as sexp."""
return sexp_call(
def _orders_header_sx(ctx: dict, list_url: str) -> str:
"""Build the orders section header row as sx."""
return sx_call(
"menu-row-sx",
id="orders-row", level=2, colour="sky",
link_href=list_url, link_label="Orders", icon="fa fa-gbp",
@@ -94,7 +94,7 @@ def _order_row_data(order: Any, detail_url: str) -> dict:
def _orders_rows_sexp(orders: list, page: int, total_pages: int,
def _orders_rows_sx(orders: list, page: int, total_pages: int,
url_for_fn: Any, qs_fn: Any) -> str:
"""S-expression wire format for order rows (client renders)."""
from shared.utils import route_prefix
@@ -103,38 +103,38 @@ def _orders_rows_sexp(orders: list, page: int, total_pages: int,
parts = []
for o in orders:
d = _order_row_data(o, pfx + url_for_fn("orders.order.order_detail", order_id=o.id))
parts.append(sexp_call("orders-row-desktop",
parts.append(sx_call("orders-row-desktop",
oid=d["oid"], created=d["created"],
desc=d["desc"], total=d["total"],
pill=d["pill_desktop"], status=d["status"],
url=d["url"]))
parts.append(sexp_call("orders-row-mobile",
parts.append(sx_call("orders-row-mobile",
oid=d["oid"], created=d["created"],
total=d["total"], pill=d["pill_mobile"],
status=d["status"], url=d["url"]))
if page < total_pages:
next_url = pfx + url_for_fn("orders.list_orders") + qs_fn(page=page + 1)
parts.append(sexp_call("infinite-scroll",
parts.append(sx_call("infinite-scroll",
url=next_url, page=page,
total_pages=total_pages,
id_prefix="orders", colspan=5))
else:
parts.append(sexp_call("orders-end-row"))
parts.append(sx_call("orders-end-row"))
return "(<> " + " ".join(parts) + ")"
def _orders_main_panel_sexp(orders: list, rows_sexp: str) -> str:
"""Main panel with table or empty state (sexp)."""
def _orders_main_panel_sx(orders: list, rows_sx: str) -> str:
"""Main panel with table or empty state (sx)."""
if not orders:
return sexp_call("orders-empty-state")
return sexp_call("orders-table", rows=SexpExpr(rows_sexp))
return sx_call("orders-empty-state")
return sx_call("orders-table", rows=SxExpr(rows_sx))
def _orders_summary_sexp(ctx: dict) -> str:
"""Filter section for orders list (sexp)."""
return sexp_call("orders-summary", search_mobile=SexpExpr(search_mobile_sexp(ctx)))
def _orders_summary_sx(ctx: dict) -> str:
"""Filter section for orders list (sx)."""
return sx_call("orders-summary", search_mobile=SxExpr(search_mobile_sx(ctx)))
@@ -146,31 +146,31 @@ async def render_orders_page(ctx: dict, orders: list, page: int,
total_pages: int, search: str | None,
search_count: int, url_for_fn: Any,
qs_fn: Any) -> str:
"""Full page: orders list (sexp wire format)."""
"""Full page: orders list (sx wire format)."""
from shared.utils import route_prefix
ctx["search"] = search
ctx["search_count"] = search_count
list_url = route_prefix() + url_for_fn("orders.list_orders")
rows = _orders_rows_sexp(orders, page, total_pages, url_for_fn, qs_fn)
main = _orders_main_panel_sexp(orders, rows)
rows = _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
main = _orders_main_panel_sx(orders, rows)
hdr = root_header_sexp(ctx)
inner = "(<> " + _auth_header_sexp(ctx) + " " + _orders_header_sexp(ctx, list_url) + ")"
hdr = "(<> " + hdr + " " + header_child_sexp(inner) + ")"
hdr = root_header_sx(ctx)
inner = "(<> " + _auth_header_sx(ctx) + " " + _orders_header_sx(ctx, list_url) + ")"
hdr = "(<> " + hdr + " " + header_child_sx(inner) + ")"
return full_page_sexp(ctx, header_rows=hdr,
filter=_orders_summary_sexp(ctx),
aside=search_desktop_sexp(ctx),
return full_page_sx(ctx, header_rows=hdr,
filter=_orders_summary_sx(ctx),
aside=search_desktop_sx(ctx),
content=main)
async def render_orders_rows(ctx: dict, orders: list, page: int,
total_pages: int, url_for_fn: Any,
qs_fn: Any) -> str:
"""Pagination: just the table rows (sexp wire format)."""
return _orders_rows_sexp(orders, page, total_pages, url_for_fn, qs_fn)
"""Pagination: just the table rows (sx wire format)."""
return _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
@@ -178,25 +178,25 @@ async def render_orders_oob(ctx: dict, orders: list, page: int,
total_pages: int, search: str | None,
search_count: int, url_for_fn: Any,
qs_fn: Any) -> str:
"""OOB response for HTMX navigation to orders list (sexp)."""
"""OOB response for HTMX navigation to orders list (sx)."""
from shared.utils import route_prefix
ctx["search"] = search
ctx["search_count"] = search_count
list_url = route_prefix() + url_for_fn("orders.list_orders")
rows = _orders_rows_sexp(orders, page, total_pages, url_for_fn, qs_fn)
main = _orders_main_panel_sexp(orders, rows)
rows = _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
main = _orders_main_panel_sx(orders, rows)
auth_hdr = _auth_header_sexp(ctx, oob=True)
auth_child_oob = sexp_call("orders-auth-header-child-oob",
inner=SexpExpr(_orders_header_sexp(ctx, list_url)))
root_hdr = root_header_sexp(ctx, oob=True)
auth_hdr = _auth_header_sx(ctx, oob=True)
auth_child_oob = sx_call("orders-auth-header-child-oob",
inner=SxExpr(_orders_header_sx(ctx, list_url)))
root_hdr = root_header_sx(ctx, oob=True)
oobs = "(<> " + auth_hdr + " " + auth_child_oob + " " + root_hdr + ")"
return oob_page_sexp(oobs=oobs,
filter=_orders_summary_sexp(ctx),
aside=search_desktop_sexp(ctx),
return oob_page_sx(oobs=oobs,
filter=_orders_summary_sx(ctx),
aside=search_desktop_sx(ctx),
content=main)
@@ -204,36 +204,36 @@ async def render_orders_oob(ctx: dict, orders: list, page: int,
# Single order detail
# ---------------------------------------------------------------------------
def _order_items_sexp(order: Any) -> str:
"""Render order items list as sexp."""
def _order_items_sx(order: Any) -> str:
"""Render order items list as sx."""
if not order or not order.items:
return ""
items = []
for item in order.items:
prod_url = market_product_url(item.product_slug)
if item.product_image:
img = sexp_call(
img = sx_call(
"orders-item-image",
src=item.product_image, alt=item.product_title or "Product image",
)
else:
img = sexp_call("orders-item-no-image")
img = sx_call("orders-item-no-image")
items.append(sexp_call(
items.append(sx_call(
"orders-item-row",
href=prod_url, img=SexpExpr(img),
href=prod_url, img=SxExpr(img),
title=item.product_title or "Unknown product",
pid=str(item.product_id),
qty=str(item.quantity),
price=f"{item.currency or order.currency or 'GBP'} {item.unit_price or 0:.2f}",
))
items_sexp = "(<> " + " ".join(items) + ")"
return sexp_call("orders-items-section", items=SexpExpr(items_sexp))
items_sx = "(<> " + " ".join(items) + ")"
return sx_call("orders-items-section", items=SxExpr(items_sx))
def _calendar_items_sexp(calendar_entries: list | None) -> str:
"""Render calendar bookings for an order as sexp."""
def _calendar_items_sx(calendar_entries: list | None) -> str:
"""Render calendar bookings for an order as sx."""
if not calendar_entries:
return ""
items = []
@@ -248,7 +248,7 @@ def _calendar_items_sexp(calendar_entries: list | None) -> 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')}"
items.append(sexp_call(
items.append(sx_call(
"orders-calendar-item",
name=e.name,
pill=f"inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium {pill}",
@@ -256,52 +256,52 @@ def _calendar_items_sexp(calendar_entries: list | None) -> str:
cost=f"\u00a3{e.cost or 0:.2f}",
))
items_sexp = "(<> " + " ".join(items) + ")"
return sexp_call("orders-calendar-section", items=SexpExpr(items_sexp))
items_sx = "(<> " + " ".join(items) + ")"
return sx_call("orders-calendar-section", items=SxExpr(items_sx))
def _order_main_sexp(order: Any, calendar_entries: list | None) -> str:
"""Main panel for single order detail (sexp)."""
summary = sexp_call(
def _order_main_sx(order: Any, calendar_entries: list | None) -> str:
"""Main panel for single order detail (sx)."""
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, currency=order.currency,
total_amount=f"{order.total_amount:.2f}" if order.total_amount else None,
)
items = _order_items_sexp(order)
calendar = _calendar_items_sexp(calendar_entries)
return sexp_call(
items = _order_items_sx(order)
calendar = _calendar_items_sx(calendar_entries)
return sx_call(
"orders-detail-panel",
summary=SexpExpr(summary),
items=SexpExpr(items) if items else None,
calendar=SexpExpr(calendar) if calendar else None,
summary=SxExpr(summary),
items=SxExpr(items) if items else None,
calendar=SxExpr(calendar) if calendar else None,
)
def _order_filter_sexp(order: Any, list_url: str, recheck_url: str,
def _order_filter_sx(order: Any, list_url: str, recheck_url: str,
pay_url: str, csrf_token: str) -> str:
"""Filter section for single order detail (sexp)."""
"""Filter section for single order detail (sx)."""
created = order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else "\u2014"
status = order.status or "pending"
pay = ""
if status != "paid":
pay = sexp_call("orders-checkout-error-pay-btn", url=pay_url)
pay = sx_call("orders-checkout-error-pay-btn", url=pay_url)
return sexp_call(
return sx_call(
"orders-detail-filter",
created=created, status=status,
list_url=list_url, recheck_url=recheck_url,
csrf=csrf_token,
pay=SexpExpr(pay) if pay else None,
pay=SxExpr(pay) if pay else None,
)
async def render_order_page(ctx: dict, order: Any,
calendar_entries: list | None,
url_for_fn: Any) -> str:
"""Full page: single order detail (sexp wire format)."""
"""Full page: single order detail (sx wire format)."""
from shared.utils import route_prefix
from shared.browser.app.csrf import generate_csrf_token
@@ -311,31 +311,31 @@ async def render_order_page(ctx: dict, order: Any,
recheck_url = pfx + url_for_fn("orders.order.order_recheck", order_id=order.id)
pay_url = pfx + url_for_fn("orders.order.order_pay", order_id=order.id)
main = _order_main_sexp(order, calendar_entries)
filt = _order_filter_sexp(order, list_url, recheck_url, pay_url, generate_csrf_token())
main = _order_main_sx(order, calendar_entries)
filt = _order_filter_sx(order, list_url, recheck_url, pay_url, generate_csrf_token())
# Header stack: root -> auth -> orders -> order
hdr = root_header_sexp(ctx)
order_row = sexp_call(
hdr = root_header_sx(ctx)
order_row = sx_call(
"menu-row-sx",
id="order-row", level=3, colour="sky", link_href=detail_url,
link_label="Order", icon="fa fa-gbp",
)
detail_header = sexp_call(
detail_header = sx_call(
"orders-detail-header-stack",
auth=SexpExpr(_auth_header_sexp(ctx)),
orders=SexpExpr(_orders_header_sexp(ctx, list_url)),
order=SexpExpr(order_row),
auth=SxExpr(_auth_header_sx(ctx)),
orders=SxExpr(_orders_header_sx(ctx, list_url)),
order=SxExpr(order_row),
)
hdr = "(<> " + hdr + " " + detail_header + ")"
return full_page_sexp(ctx, header_rows=hdr, filter=filt, content=main)
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=main)
async def render_order_oob(ctx: dict, order: Any,
calendar_entries: list | None,
url_for_fn: Any) -> str:
"""OOB response for single order detail (sexp)."""
"""OOB response for single order detail (sx)."""
from shared.utils import route_prefix
from shared.browser.app.csrf import generate_csrf_token
@@ -345,49 +345,49 @@ async def render_order_oob(ctx: dict, order: Any,
recheck_url = pfx + url_for_fn("orders.order.order_recheck", order_id=order.id)
pay_url = pfx + url_for_fn("orders.order.order_pay", order_id=order.id)
main = _order_main_sexp(order, calendar_entries)
filt = _order_filter_sexp(order, list_url, recheck_url, pay_url, generate_csrf_token())
main = _order_main_sx(order, calendar_entries)
filt = _order_filter_sx(order, list_url, recheck_url, pay_url, generate_csrf_token())
order_row_oob = sexp_call(
order_row_oob = sx_call(
"menu-row-sx",
id="order-row", level=3, colour="sky", link_href=detail_url,
link_label="Order", icon="fa fa-gbp", oob=True,
)
header_child_oob = sexp_call("orders-header-child-oob",
inner=SexpExpr(order_row_oob))
root_hdr = root_header_sexp(ctx, oob=True)
header_child_oob = sx_call("orders-header-child-oob",
inner=SxExpr(order_row_oob))
root_hdr = root_header_sx(ctx, oob=True)
oobs = "(<> " + header_child_oob + " " + root_hdr + ")"
return oob_page_sexp(oobs=oobs, filter=filt, content=main)
return oob_page_sx(oobs=oobs, filter=filt, content=main)
# ---------------------------------------------------------------------------
# Public API: Checkout error
# ---------------------------------------------------------------------------
def _checkout_error_filter_sexp() -> str:
return sexp_call("orders-checkout-error-header")
def _checkout_error_filter_sx() -> str:
return sx_call("orders-checkout-error-header")
def _checkout_error_content_sexp(error: str | None, order: Any | None) -> str:
def _checkout_error_content_sx(error: str | None, order: Any | None) -> str:
err_msg = error or "Unexpected error while creating the hosted checkout session."
order_sexp = ""
order_sx = ""
if order:
order_sexp = sexp_call("orders-checkout-error-order-id", oid=f"#{order.id}")
order_sx = sx_call("orders-checkout-error-order-id", oid=f"#{order.id}")
back_url = cart_url("/")
return sexp_call(
return sx_call(
"orders-checkout-error-content",
msg=err_msg,
order=SexpExpr(order_sexp) if order_sexp else None,
order=SxExpr(order_sx) if order_sx else None,
back_url=back_url,
)
async def render_checkout_error_page(ctx: dict, error: str | None = None, order: Any | None = None) -> str:
"""Full page: checkout error (sexp wire format)."""
hdr = root_header_sexp(ctx)
inner = _auth_header_sexp(ctx)
hdr = "(<> " + hdr + " " + header_child_sexp(inner) + ")"
filt = _checkout_error_filter_sexp()
content = _checkout_error_content_sexp(error, order)
return full_page_sexp(ctx, header_rows=hdr, filter=filt, content=content)
"""Full page: checkout error (sx wire format)."""
hdr = root_header_sx(ctx)
inner = _auth_header_sx(ctx)
hdr = "(<> " + hdr + " " + header_child_sx(inner) + ")"
filt = _checkout_error_filter_sx()
content = _checkout_error_content_sx(error, order)
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)

View File

@@ -1,9 +1,9 @@
"""Unit tests for orders sexp component helpers."""
"""Unit tests for orders sx component helpers."""
from __future__ import annotations
import pytest
from orders.sexp.sexp_components import _status_pill_cls
from orders.sx.sx_components import _status_pill_cls
class TestStatusPillCls: