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:
@@ -11,7 +11,7 @@ from quart import (
|
||||
)
|
||||
from shared.browser.app.authz import require_admin, require_post_author
|
||||
from markupsafe import escape
|
||||
from shared.sx.helpers import sx_response, render_to_sx
|
||||
from shared.sx.helpers import sx_response, sx_call
|
||||
from shared.sx.parser import SxExpr, serialize as sx_serialize
|
||||
from shared.utils import host_url
|
||||
|
||||
@@ -60,10 +60,10 @@ def _post_to_edit_dict(post) -> dict:
|
||||
return d
|
||||
|
||||
|
||||
async def _render_features(features, post, result):
|
||||
def _render_features(features, post, result):
|
||||
"""Render features panel via .sx defcomp."""
|
||||
slug = post.get("slug", "")
|
||||
return await render_to_sx("blog-features-panel-content",
|
||||
return sx_call("blog-features-panel-content",
|
||||
features_url=host_url(url_for("blog.post.admin.update_features", slug=slug)),
|
||||
calendar_checked=bool(features.get("calendar")),
|
||||
market_checked=bool(features.get("market")),
|
||||
@@ -187,7 +187,7 @@ def _render_calendar_view(
|
||||
return _raw_html_sx(html)
|
||||
|
||||
|
||||
async def _render_associated_entries(all_calendars, associated_entry_ids, post_slug: str) -> str:
|
||||
def _render_associated_entries(all_calendars, associated_entry_ids, post_slug: str) -> str:
|
||||
"""Render the associated entries panel."""
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
from quart import url_for as qurl
|
||||
@@ -216,13 +216,13 @@ async def _render_associated_entries(all_calendars, associated_entry_ids, post_s
|
||||
|
||||
toggle_url = host_url(qurl("blog.post.admin.toggle_entry", slug=post_slug, entry_id=e_id))
|
||||
|
||||
img_sx = await render_to_sx("blog-entry-image", src=cal_fi, title=cal_title)
|
||||
img_sx = sx_call("blog-entry-image", src=cal_fi, title=cal_title)
|
||||
|
||||
date_str = e_start.strftime("%A, %B %d, %Y at %H:%M") if e_start else ""
|
||||
if e_end:
|
||||
date_str += f" \u2013 {e_end.strftime('%H:%M')}"
|
||||
|
||||
entry_items.append(await render_to_sx("blog-associated-entry",
|
||||
entry_items.append(sx_call("blog-associated-entry",
|
||||
confirm_text=f"This will remove {e_name} from this post",
|
||||
toggle_url=toggle_url,
|
||||
hx_headers=f'{{"X-CSRFToken": "{csrf}"}}',
|
||||
@@ -231,16 +231,16 @@ async def _render_associated_entries(all_calendars, associated_entry_ids, post_s
|
||||
))
|
||||
|
||||
if has_entries:
|
||||
content_sx = await render_to_sx("blog-associated-entries-content",
|
||||
content_sx = sx_call("blog-associated-entries-content",
|
||||
items=SxExpr("(<> " + " ".join(entry_items) + ")"),
|
||||
)
|
||||
else:
|
||||
content_sx = await render_to_sx("blog-associated-entries-empty")
|
||||
content_sx = sx_call("blog-associated-entries-empty")
|
||||
|
||||
return await render_to_sx("blog-associated-entries-panel", content=SxExpr(content_sx))
|
||||
return sx_call("blog-associated-entries-panel", content=SxExpr(content_sx))
|
||||
|
||||
|
||||
async def _render_nav_entries_oob(associated_entries, calendars, post: dict) -> str:
|
||||
def _render_nav_entries_oob(associated_entries, calendars, post: dict) -> str:
|
||||
"""Render the OOB nav entries swap."""
|
||||
entries_list = []
|
||||
if associated_entries and hasattr(associated_entries, "entries"):
|
||||
@@ -249,7 +249,7 @@ async def _render_nav_entries_oob(associated_entries, calendars, post: dict) ->
|
||||
has_items = bool(entries_list or calendars)
|
||||
|
||||
if not has_items:
|
||||
return await render_to_sx("blog-nav-entries-empty")
|
||||
return sx_call("blog-nav-entries-empty")
|
||||
|
||||
select_colours = (
|
||||
"[.hover-capable_&]:hover:bg-yellow-300"
|
||||
@@ -291,7 +291,7 @@ async def _render_nav_entries_oob(associated_entries, calendars, post: dict) ->
|
||||
entry_path = f"/{post_slug}/{cal_slug}/"
|
||||
date_str = ""
|
||||
|
||||
item_parts.append(await render_to_sx("calendar-entry-nav",
|
||||
item_parts.append(sx_call("calendar-entry-nav",
|
||||
href=entry_path, nav_class=nav_cls, name=e_name, date_str=date_str,
|
||||
))
|
||||
|
||||
@@ -300,13 +300,13 @@ async def _render_nav_entries_oob(associated_entries, calendars, post: dict) ->
|
||||
cal_slug = getattr(calendar, "slug", "")
|
||||
cal_path = f"/{post_slug}/{cal_slug}/"
|
||||
|
||||
item_parts.append(await render_to_sx("blog-nav-calendar-item",
|
||||
item_parts.append(sx_call("blog-nav-calendar-item",
|
||||
href=cal_path, nav_cls=nav_cls, name=cal_name,
|
||||
))
|
||||
|
||||
items_sx = "(<> " + " ".join(item_parts) + ")" if item_parts else ""
|
||||
|
||||
return await render_to_sx("scroll-nav-wrapper",
|
||||
return sx_call("scroll-nav-wrapper",
|
||||
wrapper_id="entries-calendars-nav-wrapper", container_id="associated-items-container",
|
||||
arrow_cls="entries-nav-arrow",
|
||||
left_hs="on click set #associated-items-container.scrollLeft to #associated-items-container.scrollLeft - 200",
|
||||
@@ -353,7 +353,7 @@ def register():
|
||||
})
|
||||
|
||||
features = result.get("features", {})
|
||||
html = await _render_features(features, post, result)
|
||||
html = _render_features(features, post, result)
|
||||
return sx_response(html)
|
||||
|
||||
@bp.put("/admin/sumup/")
|
||||
@@ -386,7 +386,7 @@ def register():
|
||||
result = await call_action("blog", "update-page-config", payload=payload)
|
||||
|
||||
features = result.get("features", {})
|
||||
html = await _render_features(features, post, result)
|
||||
html = _render_features(features, post, result)
|
||||
return sx_response(html)
|
||||
|
||||
@bp.get("/entries/calendar/<int:calendar_id>/")
|
||||
@@ -508,8 +508,8 @@ def register():
|
||||
|
||||
# Return the associated entries admin list + OOB update for nav entries
|
||||
post = g.post_data["post"]
|
||||
admin_list = await _render_associated_entries(all_calendars, associated_entry_ids, post["slug"])
|
||||
nav_entries_html = await _render_nav_entries_oob(associated_entries, calendars, post)
|
||||
admin_list = _render_associated_entries(all_calendars, associated_entry_ids, post["slug"])
|
||||
nav_entries_html = _render_nav_entries_oob(associated_entries, calendars, post)
|
||||
|
||||
return sx_response(admin_list + nav_entries_html)
|
||||
|
||||
@@ -686,7 +686,7 @@ def register():
|
||||
|
||||
slug = post.get("slug", "")
|
||||
create_url = host_url(url_for("blog.post.admin.create_market", slug=slug))
|
||||
html = await render_to_sx("blog-markets-panel-content",
|
||||
html = sx_call("blog-markets-panel-content",
|
||||
markets=_serialize_markets(page_markets, slug), create_url=create_url)
|
||||
return sx_response(html)
|
||||
|
||||
@@ -715,7 +715,7 @@ def register():
|
||||
|
||||
slug = post.get("slug", "")
|
||||
create_url = host_url(url_for("blog.post.admin.create_market", slug=slug))
|
||||
html = await render_to_sx("blog-markets-panel-content",
|
||||
html = sx_call("blog-markets-panel-content",
|
||||
markets=_serialize_markets(page_markets, slug), create_url=create_url)
|
||||
return sx_response(html)
|
||||
|
||||
@@ -738,7 +738,7 @@ def register():
|
||||
|
||||
slug = post.get("slug", "")
|
||||
create_url = host_url(url_for("blog.post.admin.create_market", slug=slug))
|
||||
html = await render_to_sx("blog-markets-panel-content",
|
||||
html = sx_call("blog-markets-panel-content",
|
||||
markets=_serialize_markets(page_markets, slug), create_url=create_url)
|
||||
return sx_response(html)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user