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
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:
@@ -1,7 +1,7 @@
|
||||
"""Badge helpers, OOB helpers, formatting utilities, list containers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.helpers import sx_call
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ def _list_container(ctx: dict) -> str:
|
||||
return getattr(styles, "list_container", "") if hasattr(styles, "list_container") else styles.get("list_container", "")
|
||||
|
||||
|
||||
async def _entry_state_badge_html(state: str) -> str:
|
||||
def _entry_state_badge_html(state: str) -> str:
|
||||
"""Render an entry state badge."""
|
||||
state_classes = {
|
||||
"confirmed": "bg-emerald-100 text-emerald-800",
|
||||
@@ -85,10 +85,10 @@ async def _entry_state_badge_html(state: str) -> str:
|
||||
}
|
||||
cls = state_classes.get(state, "bg-stone-100 text-stone-700")
|
||||
label = state.replace("_", " ").capitalize()
|
||||
return await render_to_sx("badge", cls=cls, label=label)
|
||||
return sx_call("badge", cls=cls, label=label)
|
||||
|
||||
|
||||
async def _ticket_state_badge_html(state: str) -> str:
|
||||
def _ticket_state_badge_html(state: str) -> str:
|
||||
"""Render a ticket state badge."""
|
||||
cls_map = {
|
||||
"confirmed": "bg-emerald-100 text-emerald-800",
|
||||
@@ -98,7 +98,7 @@ async def _ticket_state_badge_html(state: str) -> str:
|
||||
}
|
||||
cls = cls_map.get(state, "bg-stone-100 text-stone-700")
|
||||
label = (state or "").replace("_", " ").capitalize()
|
||||
return await render_to_sx("badge", cls=cls, label=label)
|
||||
return sx_call("badge", cls=cls, label=label)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -109,21 +109,21 @@ _LIST_SVG = None
|
||||
_TILE_SVG = None
|
||||
|
||||
|
||||
async def _get_list_svg():
|
||||
def _get_list_svg():
|
||||
global _LIST_SVG
|
||||
if _LIST_SVG is None:
|
||||
_LIST_SVG = await render_to_sx("list-svg")
|
||||
_LIST_SVG = sx_call("list-svg")
|
||||
return _LIST_SVG
|
||||
|
||||
|
||||
async def _get_tile_svg():
|
||||
def _get_tile_svg():
|
||||
global _TILE_SVG
|
||||
if _TILE_SVG is None:
|
||||
_TILE_SVG = await render_to_sx("tile-svg")
|
||||
_TILE_SVG = sx_call("tile-svg")
|
||||
return _TILE_SVG
|
||||
|
||||
|
||||
async def _view_toggle_html(ctx: dict, view: str) -> str:
|
||||
def _view_toggle_html(ctx: dict, view: str) -> str:
|
||||
"""Render the list/tile view toggle bar."""
|
||||
from shared.utils import route_prefix
|
||||
prefix = route_prefix()
|
||||
@@ -142,14 +142,14 @@ async def _view_toggle_html(ctx: dict, view: str) -> str:
|
||||
list_active = 'bg-stone-200 text-stone-800' if view != 'tile' else 'text-stone-400 hover:text-stone-600'
|
||||
tile_active = 'bg-stone-200 text-stone-800' if view == 'tile' else 'text-stone-400 hover:text-stone-600'
|
||||
|
||||
return await render_to_sx("view-toggle",
|
||||
return sx_call("view-toggle",
|
||||
list_href=list_href, tile_href=tile_href,
|
||||
hx_select=hx_select, list_cls=list_active,
|
||||
tile_cls=tile_active, storage_key="events_view",
|
||||
list_svg=SxExpr(await _get_list_svg()), tile_svg=SxExpr(await _get_tile_svg()))
|
||||
list_svg=SxExpr(_get_list_svg()), tile_svg=SxExpr(_get_tile_svg()))
|
||||
|
||||
|
||||
async def _cart_icon_oob(count: int) -> str:
|
||||
def _cart_icon_oob(count: int) -> str:
|
||||
"""Render the OOB cart icon/badge swap."""
|
||||
from quart import g
|
||||
|
||||
@@ -163,9 +163,9 @@ async def _cart_icon_oob(count: int) -> str:
|
||||
|
||||
if count == 0:
|
||||
blog_href = blog_url_fn("/") if blog_url_fn else "/"
|
||||
return await render_to_sx("events-cart-icon-logo",
|
||||
return sx_call("events-cart-icon-logo",
|
||||
blog_href=blog_href, logo=logo)
|
||||
|
||||
cart_href = cart_url_fn("/") if cart_url_fn else "/"
|
||||
return await render_to_sx("events-cart-icon-badge",
|
||||
return sx_call("events-cart-icon-badge",
|
||||
cart_href=cart_href, count=str(count))
|
||||
|
||||
Reference in New Issue
Block a user