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:
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from shared.sx.parser import SxExpr
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.helpers import sx_call
|
||||
|
||||
from .utils import _set_prices, _price_str
|
||||
from .filters import _MOBILE_SENTINEL_HS, _DESKTOP_SENTINEL_HS
|
||||
@@ -14,7 +14,7 @@ from .filters import _MOBILE_SENTINEL_HS, _DESKTOP_SENTINEL_HS
|
||||
# Product card (browse grid item)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _product_card_sx(p: dict, ctx: dict) -> str:
|
||||
def _product_card_sx(p: dict, ctx: dict) -> str:
|
||||
"""Build a single product card for browse grid as sx call."""
|
||||
from quart import url_for
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -98,10 +98,10 @@ async def _product_card_sx(p: dict, ctx: dict) -> str:
|
||||
kwargs["search_mid"] = search_mid
|
||||
kwargs["search_post"] = search_post
|
||||
|
||||
return await render_to_sx("market-product-card", **kwargs)
|
||||
return sx_call("market-product-card", **kwargs)
|
||||
|
||||
|
||||
async def _product_cards_sx(ctx: dict) -> str:
|
||||
def _product_cards_sx(ctx: dict) -> str:
|
||||
"""S-expression wire format for product cards (client renders)."""
|
||||
from shared.utils import route_prefix
|
||||
|
||||
@@ -114,7 +114,7 @@ async def _product_cards_sx(ctx: dict) -> str:
|
||||
|
||||
parts = []
|
||||
for p in products:
|
||||
parts.append(await _product_card_sx(p, ctx))
|
||||
parts.append(_product_card_sx(p, ctx))
|
||||
|
||||
if page < total_pages:
|
||||
if callable(qs_fn):
|
||||
@@ -122,25 +122,25 @@ async def _product_cards_sx(ctx: dict) -> str:
|
||||
else:
|
||||
next_qs = f"?page={page + 1}"
|
||||
next_url = prefix + current_local_href + next_qs
|
||||
parts.append(await render_to_sx("sentinel-mobile",
|
||||
parts.append(sx_call("sentinel-mobile",
|
||||
id=f"sentinel-{page}-m", next_url=next_url,
|
||||
hyperscript=_MOBILE_SENTINEL_HS))
|
||||
parts.append(await render_to_sx("sentinel-desktop",
|
||||
parts.append(sx_call("sentinel-desktop",
|
||||
id=f"sentinel-{page}-d", next_url=next_url,
|
||||
hyperscript=_DESKTOP_SENTINEL_HS))
|
||||
else:
|
||||
parts.append(await render_to_sx("end-of-results"))
|
||||
parts.append(sx_call("end-of-results"))
|
||||
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
|
||||
async def _like_button_sx(slug: str, liked: bool, csrf: str, ctx: dict) -> str:
|
||||
def _like_button_sx(slug: str, liked: bool, csrf: str, ctx: dict) -> str:
|
||||
"""Build the like/unlike heart button overlay as sx."""
|
||||
from quart import url_for
|
||||
|
||||
action = url_for("market.browse.product.like_toggle", product_slug=slug)
|
||||
icon_cls = "fa-solid fa-heart text-red-500" if liked else "fa-regular fa-heart text-stone-400"
|
||||
return await render_to_sx(
|
||||
return sx_call(
|
||||
"market-like-button",
|
||||
form_id=f"like-{slug}", action=action, slug=slug,
|
||||
csrf=csrf, icon_cls=icon_cls,
|
||||
@@ -151,7 +151,7 @@ async def _like_button_sx(slug: str, liked: bool, csrf: str, ctx: dict) -> str:
|
||||
# Market cards (all markets / page markets)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _market_card_sx(market: Any, page_info: dict, *, show_page_badge: bool = True,
|
||||
def _market_card_sx(market: Any, page_info: dict, *, show_page_badge: bool = True,
|
||||
post_slug: str = "") -> str:
|
||||
"""Build a single market card as sx."""
|
||||
from shared.infrastructure.urls import market_url
|
||||
@@ -173,20 +173,20 @@ async def _market_card_sx(market: Any, page_info: dict, *, show_page_badge: bool
|
||||
|
||||
title_sx = ""
|
||||
if market_href:
|
||||
title_sx = await render_to_sx("market-market-card-title-link", href=market_href, name=name)
|
||||
title_sx = sx_call("market-market-card-title-link", href=market_href, name=name)
|
||||
else:
|
||||
title_sx = await render_to_sx("market-market-card-title", name=name)
|
||||
title_sx = sx_call("market-market-card-title", name=name)
|
||||
|
||||
desc_sx = ""
|
||||
if description:
|
||||
desc_sx = await render_to_sx("market-market-card-desc", description=description)
|
||||
desc_sx = sx_call("market-market-card-desc", description=description)
|
||||
|
||||
badge_sx = ""
|
||||
if show_page_badge and p_title:
|
||||
badge_href = market_url(f"/{p_slug}/")
|
||||
badge_sx = await render_to_sx("market-market-card-badge", href=badge_href, title=p_title)
|
||||
badge_sx = sx_call("market-market-card-badge", href=badge_href, title=p_title)
|
||||
|
||||
return await render_to_sx(
|
||||
return sx_call(
|
||||
"market-market-card",
|
||||
title_content=SxExpr(title_sx) if title_sx else None,
|
||||
desc_content=SxExpr(desc_sx) if desc_sx else None,
|
||||
@@ -194,30 +194,30 @@ async def _market_card_sx(market: Any, page_info: dict, *, show_page_badge: bool
|
||||
)
|
||||
|
||||
|
||||
async def _market_cards_sx(markets: list, page_info: dict, page: int, has_more: bool,
|
||||
def _market_cards_sx(markets: list, page_info: dict, page: int, has_more: bool,
|
||||
next_url: str, *, show_page_badge: bool = True,
|
||||
post_slug: str = "") -> str:
|
||||
"""Build market cards with infinite scroll sentinel as sx."""
|
||||
parts = []
|
||||
for m in markets:
|
||||
parts.append(await _market_card_sx(m, page_info, show_page_badge=show_page_badge,
|
||||
parts.append(_market_card_sx(m, page_info, show_page_badge=show_page_badge,
|
||||
post_slug=post_slug))
|
||||
if has_more:
|
||||
parts.append(await render_to_sx(
|
||||
parts.append(sx_call(
|
||||
"sentinel-simple",
|
||||
id=f"sentinel-{page}", next_url=next_url,
|
||||
))
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
|
||||
async def _markets_grid(cards_sx: str) -> str:
|
||||
def _markets_grid(cards_sx: str) -> str:
|
||||
"""Wrap market cards in a grid as sx."""
|
||||
return await render_to_sx("market-markets-grid", cards=SxExpr(cards_sx))
|
||||
return sx_call("market-markets-grid", cards=SxExpr(cards_sx))
|
||||
|
||||
|
||||
async def _no_markets_sx(message: str = "No markets available") -> str:
|
||||
def _no_markets_sx(message: str = "No markets available") -> str:
|
||||
"""Empty state for markets as sx."""
|
||||
return await render_to_sx("empty-state", icon="fa fa-store", message=message,
|
||||
return sx_call("empty-state", icon="fa fa-store", message=message,
|
||||
cls="px-3 py-12 text-center text-stone-400")
|
||||
|
||||
|
||||
@@ -225,14 +225,14 @@ async def _no_markets_sx(message: str = "No markets available") -> str:
|
||||
# Market landing page
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _market_landing_content_sx(post: dict) -> str:
|
||||
def _market_landing_content_sx(post: dict) -> str:
|
||||
"""Build market landing page content as sx."""
|
||||
parts: list[str] = []
|
||||
if post.get("custom_excerpt"):
|
||||
parts.append(await render_to_sx("market-landing-excerpt", text=post["custom_excerpt"]))
|
||||
parts.append(sx_call("market-landing-excerpt", text=post["custom_excerpt"]))
|
||||
if post.get("feature_image"):
|
||||
parts.append(await render_to_sx("market-landing-image", src=post["feature_image"]))
|
||||
parts.append(sx_call("market-landing-image", src=post["feature_image"]))
|
||||
if post.get("html"):
|
||||
parts.append(await render_to_sx("market-landing-html", html=post["html"]))
|
||||
parts.append(sx_call("market-landing-html", html=post["html"]))
|
||||
inner = "(<> " + " ".join(parts) + ")" if parts else "(<>)"
|
||||
return await render_to_sx("market-landing-content", inner=SxExpr(inner))
|
||||
return sx_call("market-landing-content", inner=SxExpr(inner))
|
||||
|
||||
Reference in New Issue
Block a user