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:
@@ -3,8 +3,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from shared.sx.parser import serialize, SxExpr
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.parser import SxExpr
|
||||
from shared.sx.helpers import sx_call
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -22,7 +22,6 @@ _MARKET_DEEP_IDS = [
|
||||
|
||||
def _clear_deeper_oob(*keep_ids: str) -> str:
|
||||
"""Clear all market header rows/children NOT in keep_ids."""
|
||||
from shared.sx.helpers import sx_call
|
||||
to_clear = [i for i in _MARKET_DEEP_IDS if i not in keep_ids]
|
||||
return " ".join(sx_call("clear-oob-div", id=i) for i in to_clear)
|
||||
|
||||
@@ -55,27 +54,27 @@ def _set_prices(item: dict) -> dict:
|
||||
rp_val=rp_val, rp_raw=rp_raw, rp_cur=rp_cur)
|
||||
|
||||
|
||||
async def _card_price_sx(p: dict) -> str:
|
||||
def _card_price_sx(p: dict) -> str:
|
||||
"""Build price line for product card as sx call."""
|
||||
pr = _set_prices(p)
|
||||
sp_str = _price_str(pr["sp_val"], pr["sp_raw"], pr["sp_cur"])
|
||||
rp_str = _price_str(pr["rp_val"], pr["rp_raw"], pr["rp_cur"])
|
||||
parts: list[str] = []
|
||||
if pr["sp_val"]:
|
||||
parts.append(await render_to_sx("market-price-special", price=sp_str))
|
||||
parts.append(sx_call("market-price-special", price=sp_str))
|
||||
if pr["rp_val"]:
|
||||
parts.append(await render_to_sx("market-price-regular-strike", price=rp_str))
|
||||
parts.append(sx_call("market-price-regular-strike", price=rp_str))
|
||||
elif pr["rp_val"]:
|
||||
parts.append(await render_to_sx("market-price-regular", price=rp_str))
|
||||
parts.append(sx_call("market-price-regular", price=rp_str))
|
||||
inner = "(<> " + " ".join(parts) + ")" if parts else None
|
||||
return await render_to_sx("market-price-line", inner=SxExpr(inner) if inner else None)
|
||||
return sx_call("market-price-line", inner=SxExpr(inner) if inner else None)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Product detail page content
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
"""Build product detail main panel content as sx."""
|
||||
from quart import url_for
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -97,19 +96,19 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
# Like button
|
||||
like_sx = ""
|
||||
if user:
|
||||
like_sx = await _like_button_sx(slug, liked_by_current_user, csrf, ctx)
|
||||
like_sx = _like_button_sx(slug, liked_by_current_user, csrf, ctx)
|
||||
|
||||
# Main image + labels
|
||||
label_parts: list[str] = []
|
||||
if callable(asset_url_fn):
|
||||
for l in labels:
|
||||
label_parts.append(await render_to_sx(
|
||||
label_parts.append(sx_call(
|
||||
"market-label-overlay",
|
||||
src=asset_url_fn("labels/" + l + ".svg"),
|
||||
))
|
||||
labels_sx = "(<> " + " ".join(label_parts) + ")" if label_parts else None
|
||||
|
||||
gallery_inner = await render_to_sx(
|
||||
gallery_inner = sx_call(
|
||||
"market-detail-gallery-inner",
|
||||
like=SxExpr(like_sx) if like_sx else None,
|
||||
image=images[0], alt=d.get("title", ""),
|
||||
@@ -120,9 +119,9 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
# Prev/next buttons
|
||||
nav_buttons = ""
|
||||
if len(images) > 1:
|
||||
nav_buttons = await render_to_sx("market-detail-nav-buttons")
|
||||
nav_buttons = sx_call("market-detail-nav-buttons")
|
||||
|
||||
gallery_sx = await render_to_sx(
|
||||
gallery_sx = sx_call(
|
||||
"market-detail-gallery",
|
||||
inner=SxExpr(gallery_inner),
|
||||
nav=SxExpr(nav_buttons) if nav_buttons else None,
|
||||
@@ -133,18 +132,18 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
if len(images) > 1:
|
||||
thumb_parts = []
|
||||
for i, u in enumerate(images):
|
||||
thumb_parts.append(await render_to_sx(
|
||||
thumb_parts.append(sx_call(
|
||||
"market-detail-thumb",
|
||||
title=f"Image {i+1}", src=u, alt=f"thumb {i+1}",
|
||||
))
|
||||
thumbs_sx = "(<> " + " ".join(thumb_parts) + ")"
|
||||
gallery_parts.append(await render_to_sx("market-detail-thumbs", thumbs=SxExpr(thumbs_sx)))
|
||||
gallery_parts.append(sx_call("market-detail-thumbs", thumbs=SxExpr(thumbs_sx)))
|
||||
gallery_final = "(<> " + " ".join(gallery_parts) + ")"
|
||||
else:
|
||||
like_sx = ""
|
||||
if user:
|
||||
like_sx = await _like_button_sx(slug, liked_by_current_user, csrf, ctx)
|
||||
gallery_final = await render_to_sx("market-detail-no-image",
|
||||
like_sx = _like_button_sx(slug, liked_by_current_user, csrf, ctx)
|
||||
gallery_final = sx_call("market-detail-no-image",
|
||||
like=SxExpr(like_sx) if like_sx else None)
|
||||
|
||||
# Stickers below gallery
|
||||
@@ -152,12 +151,12 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
if stickers and callable(asset_url_fn):
|
||||
sticker_parts = []
|
||||
for s in stickers:
|
||||
sticker_parts.append(await render_to_sx(
|
||||
sticker_parts.append(sx_call(
|
||||
"market-detail-sticker",
|
||||
src=asset_url_fn("stickers/" + s + ".svg"), name=s,
|
||||
))
|
||||
sticker_items_sx = "(<> " + " ".join(sticker_parts) + ")"
|
||||
stickers_sx = await render_to_sx("market-detail-stickers", items=SxExpr(sticker_items_sx))
|
||||
stickers_sx = sx_call("market-detail-stickers", items=SxExpr(sticker_items_sx))
|
||||
|
||||
# Right column: prices, description, sections
|
||||
pr = _set_prices(d)
|
||||
@@ -167,15 +166,15 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
extra_parts: list[str] = []
|
||||
ppu = d.get("price_per_unit") or d.get("price_per_unit_raw")
|
||||
if ppu:
|
||||
extra_parts.append(await render_to_sx(
|
||||
extra_parts.append(sx_call(
|
||||
"market-detail-unit-price",
|
||||
price=_price_str(d.get("price_per_unit"), d.get("price_per_unit_raw"), d.get("price_per_unit_currency")),
|
||||
))
|
||||
if d.get("case_size_raw"):
|
||||
extra_parts.append(await render_to_sx("market-detail-case-size", size=d["case_size_raw"]))
|
||||
extra_parts.append(sx_call("market-detail-case-size", size=d["case_size_raw"]))
|
||||
if extra_parts:
|
||||
extras_sx = "(<> " + " ".join(extra_parts) + ")"
|
||||
detail_parts.append(await render_to_sx("market-detail-extras", inner=SxExpr(extras_sx)))
|
||||
detail_parts.append(sx_call("market-detail-extras", inner=SxExpr(extras_sx)))
|
||||
|
||||
# Description
|
||||
desc_short = d.get("description_short")
|
||||
@@ -183,28 +182,28 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
if desc_short or desc_html_val:
|
||||
desc_parts: list[str] = []
|
||||
if desc_short:
|
||||
desc_parts.append(await render_to_sx("market-detail-desc-short", text=desc_short))
|
||||
desc_parts.append(sx_call("market-detail-desc-short", text=desc_short))
|
||||
if desc_html_val:
|
||||
desc_parts.append(await render_to_sx("market-detail-desc-html", html=desc_html_val))
|
||||
desc_parts.append(sx_call("market-detail-desc-html", html=desc_html_val))
|
||||
desc_inner = "(<> " + " ".join(desc_parts) + ")"
|
||||
detail_parts.append(await render_to_sx("market-detail-desc-wrapper", inner=SxExpr(desc_inner)))
|
||||
detail_parts.append(sx_call("market-detail-desc-wrapper", inner=SxExpr(desc_inner)))
|
||||
|
||||
# Sections (expandable)
|
||||
sections = d.get("sections", [])
|
||||
if sections:
|
||||
sec_parts = []
|
||||
for sec in sections:
|
||||
sec_parts.append(await render_to_sx(
|
||||
sec_parts.append(sx_call(
|
||||
"market-detail-section",
|
||||
title=sec.get("title", ""), html=sec.get("html", ""),
|
||||
))
|
||||
sec_items_sx = "(<> " + " ".join(sec_parts) + ")"
|
||||
detail_parts.append(await render_to_sx("market-detail-sections", items=SxExpr(sec_items_sx)))
|
||||
detail_parts.append(sx_call("market-detail-sections", items=SxExpr(sec_items_sx)))
|
||||
|
||||
details_inner_sx = "(<> " + " ".join(detail_parts) + ")" if detail_parts else "(<>)"
|
||||
details_sx = await render_to_sx("market-detail-right-col", inner=SxExpr(details_inner_sx))
|
||||
details_sx = sx_call("market-detail-right-col", inner=SxExpr(details_inner_sx))
|
||||
|
||||
return await render_to_sx(
|
||||
return sx_call(
|
||||
"market-detail-layout",
|
||||
gallery=SxExpr(gallery_final),
|
||||
stickers=SxExpr(stickers_sx) if stickers_sx else None,
|
||||
@@ -216,7 +215,7 @@ async def _product_detail_sx(d: dict, ctx: dict) -> str:
|
||||
# Product meta (OpenGraph, JSON-LD)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _product_meta_sx(d: dict, ctx: dict) -> str:
|
||||
def _product_meta_sx(d: dict, ctx: dict) -> str:
|
||||
"""Build product meta tags as sx (auto-hoisted to <head> by sx.js)."""
|
||||
import json
|
||||
from quart import request
|
||||
@@ -234,34 +233,34 @@ async def _product_meta_sx(d: dict, ctx: dict) -> str:
|
||||
price = d.get("special_price") or d.get("regular_price") or d.get("rrp")
|
||||
price_currency = d.get("special_price_currency") or d.get("regular_price_currency") or d.get("rrp_currency")
|
||||
|
||||
parts = [await render_to_sx("market-meta-title", title=title)]
|
||||
parts.append(await render_to_sx("market-meta-description", description=description))
|
||||
parts = [sx_call("market-meta-title", title=title)]
|
||||
parts.append(sx_call("market-meta-description", description=description))
|
||||
if canonical:
|
||||
parts.append(await render_to_sx("market-meta-canonical", href=canonical))
|
||||
parts.append(sx_call("market-meta-canonical", href=canonical))
|
||||
|
||||
# OpenGraph
|
||||
site_title = ctx.get("base_title", "")
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:site_name", content=site_title))
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:type", content="product"))
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:title", content=title))
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:description", content=description))
|
||||
parts.append(sx_call("market-meta-og", property="og:site_name", content=site_title))
|
||||
parts.append(sx_call("market-meta-og", property="og:type", content="product"))
|
||||
parts.append(sx_call("market-meta-og", property="og:title", content=title))
|
||||
parts.append(sx_call("market-meta-og", property="og:description", content=description))
|
||||
if canonical:
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:url", content=canonical))
|
||||
parts.append(sx_call("market-meta-og", property="og:url", content=canonical))
|
||||
if image_url:
|
||||
parts.append(await render_to_sx("market-meta-og", property="og:image", content=image_url))
|
||||
parts.append(sx_call("market-meta-og", property="og:image", content=image_url))
|
||||
if price and price_currency:
|
||||
parts.append(await render_to_sx("market-meta-og", property="product:price:amount", content=f"{price:.2f}"))
|
||||
parts.append(await render_to_sx("market-meta-og", property="product:price:currency", content=price_currency))
|
||||
parts.append(sx_call("market-meta-og", property="product:price:amount", content=f"{price:.2f}"))
|
||||
parts.append(sx_call("market-meta-og", property="product:price:currency", content=price_currency))
|
||||
if brand:
|
||||
parts.append(await render_to_sx("market-meta-og", property="product:brand", content=brand))
|
||||
parts.append(sx_call("market-meta-og", property="product:brand", content=brand))
|
||||
|
||||
# Twitter
|
||||
card_type = "summary_large_image" if image_url else "summary"
|
||||
parts.append(await render_to_sx("market-meta-twitter", name="twitter:card", content=card_type))
|
||||
parts.append(await render_to_sx("market-meta-twitter", name="twitter:title", content=title))
|
||||
parts.append(await render_to_sx("market-meta-twitter", name="twitter:description", content=description))
|
||||
parts.append(sx_call("market-meta-twitter", name="twitter:card", content=card_type))
|
||||
parts.append(sx_call("market-meta-twitter", name="twitter:title", content=title))
|
||||
parts.append(sx_call("market-meta-twitter", name="twitter:description", content=description))
|
||||
if image_url:
|
||||
parts.append(await render_to_sx("market-meta-twitter", name="twitter:image", content=image_url))
|
||||
parts.append(sx_call("market-meta-twitter", name="twitter:image", content=image_url))
|
||||
|
||||
# JSON-LD
|
||||
jsonld = {
|
||||
@@ -283,6 +282,6 @@ async def _product_meta_sx(d: dict, ctx: dict) -> str:
|
||||
"url": canonical,
|
||||
"availability": "https://schema.org/InStock",
|
||||
}
|
||||
parts.append(await render_to_sx("market-meta-jsonld", json=json.dumps(jsonld)))
|
||||
parts.append(sx_call("market-meta-jsonld", json=json.dumps(jsonld)))
|
||||
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
Reference in New Issue
Block a user