Remove render_to_sx from public API: enforce sx_call for all service code
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:
@@ -40,7 +40,7 @@ async def render_all_events_page(ctx: dict, entries, has_more, pending_tickets,
|
||||
ticket_url = url_for("all_events.adjust_ticket")
|
||||
next_url = prefix + url_for("all_events.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
content = await _events_main_panel_html(
|
||||
content = _events_main_panel_html(
|
||||
ctx, entries, has_more, pending_tickets, page_info,
|
||||
page, view, ticket_url, next_url, events_url,
|
||||
)
|
||||
@@ -59,15 +59,15 @@ async def render_all_events_oob(ctx: dict, entries, has_more, pending_tickets,
|
||||
ticket_url = url_for("all_events.adjust_ticket")
|
||||
next_url = prefix + url_for("all_events.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
content = await _events_main_panel_html(
|
||||
content = _events_main_panel_html(
|
||||
ctx, entries, has_more, pending_tickets, page_info,
|
||||
page, view, ticket_url, next_url, events_url,
|
||||
)
|
||||
return await oob_page_sx(content=content)
|
||||
|
||||
|
||||
async def render_all_events_cards(entries, has_more, pending_tickets,
|
||||
page_info, page, view) -> str:
|
||||
def render_all_events_cards(entries, has_more, pending_tickets,
|
||||
page_info, page, view) -> str:
|
||||
"""Pagination fragment: all events cards only."""
|
||||
from quart import url_for
|
||||
from shared.utils import route_prefix
|
||||
@@ -77,7 +77,7 @@ async def render_all_events_cards(entries, has_more, pending_tickets,
|
||||
ticket_url = url_for("all_events.adjust_ticket")
|
||||
next_url = prefix + url_for("all_events.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
return await _entry_cards_html(
|
||||
return _entry_cards_html(
|
||||
entries, page_info, pending_tickets, ticket_url, events_url,
|
||||
view, page, has_more, next_url,
|
||||
)
|
||||
@@ -99,7 +99,7 @@ async def render_page_summary_page(ctx: dict, entries, has_more, pending_tickets
|
||||
ticket_url = url_for("page_summary.adjust_ticket")
|
||||
next_url = prefix + url_for("page_summary.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
content = await _events_main_panel_html(
|
||||
content = _events_main_panel_html(
|
||||
ctx, entries, has_more, pending_tickets, page_info,
|
||||
page, view, ticket_url, next_url, events_url,
|
||||
is_page_scoped=True, post=post,
|
||||
@@ -122,7 +122,7 @@ async def render_page_summary_oob(ctx: dict, entries, has_more, pending_tickets,
|
||||
ticket_url = url_for("page_summary.adjust_ticket")
|
||||
next_url = prefix + url_for("page_summary.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
content = await _events_main_panel_html(
|
||||
content = _events_main_panel_html(
|
||||
ctx, entries, has_more, pending_tickets, page_info,
|
||||
page, view, ticket_url, next_url, events_url,
|
||||
is_page_scoped=True, post=post,
|
||||
@@ -133,8 +133,8 @@ async def render_page_summary_oob(ctx: dict, entries, has_more, pending_tickets,
|
||||
return await oob_page_sx(oobs=oobs, content=content)
|
||||
|
||||
|
||||
async def render_page_summary_cards(entries, has_more, pending_tickets,
|
||||
page_info, page, view, post) -> str:
|
||||
def render_page_summary_cards(entries, has_more, pending_tickets,
|
||||
page_info, page, view, post) -> str:
|
||||
"""Pagination fragment: page-scoped events cards only."""
|
||||
from quart import url_for
|
||||
from shared.utils import route_prefix
|
||||
@@ -144,7 +144,7 @@ async def render_page_summary_cards(entries, has_more, pending_tickets,
|
||||
ticket_url = url_for("page_summary.adjust_ticket")
|
||||
next_url = prefix + url_for("page_summary.entries_fragment", page=page + 1) + (f"?view={view}" if view != "list" else "")
|
||||
|
||||
return await _entry_cards_html(
|
||||
return _entry_cards_html(
|
||||
entries, page_info, pending_tickets, ticket_url, events_url,
|
||||
view, page, has_more, next_url,
|
||||
is_page_scoped=True, post=post,
|
||||
@@ -157,7 +157,7 @@ async def render_page_summary_cards(entries, has_more, pending_tickets,
|
||||
|
||||
async def render_calendars_page(ctx: dict) -> str:
|
||||
"""Full page: calendars listing."""
|
||||
content = await _calendars_main_panel_sx(ctx)
|
||||
content = _calendars_main_panel_sx(ctx)
|
||||
ctx = await _ensure_container_nav(ctx)
|
||||
slug = (ctx.get("post") or {}).get("slug", "")
|
||||
root_hdr = await render_to_sx_with_env("layout-root-full", {})
|
||||
@@ -168,7 +168,7 @@ async def render_calendars_page(ctx: dict) -> str:
|
||||
|
||||
async def render_calendars_oob(ctx: dict) -> str:
|
||||
"""OOB response: calendars listing."""
|
||||
content = await _calendars_main_panel_sx(ctx)
|
||||
content = _calendars_main_panel_sx(ctx)
|
||||
ctx = await _ensure_container_nav(ctx)
|
||||
slug = (ctx.get("post") or {}).get("slug", "")
|
||||
oobs = await post_admin_header_sx(ctx, slug, oob=True, selected="calendars")
|
||||
@@ -183,19 +183,19 @@ async def render_calendars_oob(ctx: dict) -> str:
|
||||
|
||||
async def render_calendar_page(ctx: dict) -> str:
|
||||
"""Full page: calendar month view."""
|
||||
content = await _calendar_main_panel_html(ctx)
|
||||
content = _calendar_main_panel_html(ctx)
|
||||
hdr = await render_to_sx_with_env("layout-root-full", {})
|
||||
child = await _post_header_sx(ctx) + await _calendar_header_sx(ctx)
|
||||
child = await _post_header_sx(ctx) + _calendar_header_sx(ctx)
|
||||
hdr += await header_child_sx(child)
|
||||
return await full_page_sx(ctx, header_rows=hdr, content=content)
|
||||
|
||||
|
||||
async def render_calendar_oob(ctx: dict) -> str:
|
||||
"""OOB response: calendar month view."""
|
||||
content = await _calendar_main_panel_html(ctx)
|
||||
content = _calendar_main_panel_html(ctx)
|
||||
oobs = await _post_header_sx(ctx, oob=True)
|
||||
oobs += await oob_header_sx("post-header-child", "calendar-header-child",
|
||||
await _calendar_header_sx(ctx))
|
||||
_calendar_header_sx(ctx))
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
"calendar-row", "calendar-header-child")
|
||||
return await oob_page_sx(oobs=oobs, content=content)
|
||||
@@ -207,20 +207,20 @@ async def render_calendar_oob(ctx: dict) -> str:
|
||||
|
||||
async def render_day_page(ctx: dict) -> str:
|
||||
"""Full page: day detail."""
|
||||
content = await _day_main_panel_html(ctx)
|
||||
content = _day_main_panel_html(ctx)
|
||||
hdr = await render_to_sx_with_env("layout-root-full", {})
|
||||
child = (await _post_header_sx(ctx)
|
||||
+ await _calendar_header_sx(ctx) + await _day_header_sx(ctx))
|
||||
+ _calendar_header_sx(ctx) + _day_header_sx(ctx))
|
||||
hdr += await header_child_sx(child)
|
||||
return await full_page_sx(ctx, header_rows=hdr, content=content)
|
||||
|
||||
|
||||
async def render_day_oob(ctx: dict) -> str:
|
||||
"""OOB response: day detail."""
|
||||
content = await _day_main_panel_html(ctx)
|
||||
oobs = await _calendar_header_sx(ctx, oob=True)
|
||||
content = _day_main_panel_html(ctx)
|
||||
oobs = _calendar_header_sx(ctx, oob=True)
|
||||
oobs += await oob_header_sx("calendar-header-child", "day-header-child",
|
||||
await _day_header_sx(ctx))
|
||||
_day_header_sx(ctx))
|
||||
oobs += _clear_deeper_oob("post-row", "post-header-child",
|
||||
"calendar-row", "calendar-header-child",
|
||||
"day-row", "day-header-child")
|
||||
@@ -231,36 +231,36 @@ async def render_day_oob(ctx: dict) -> str:
|
||||
# Day main panel -- public API
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_day_main_panel(ctx: dict) -> str:
|
||||
def render_day_main_panel(ctx: dict) -> str:
|
||||
"""Public wrapper for day main panel rendering."""
|
||||
return await _day_main_panel_html(ctx)
|
||||
return _day_main_panel_html(ctx)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Calendar description display + edit form
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_calendar_description(calendar, *, oob: bool = False) -> str:
|
||||
def render_calendar_description(calendar, *, oob: bool = False) -> str:
|
||||
"""Render calendar description display with edit button, optionally with OOB title."""
|
||||
from quart import url_for
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.helpers import sx_call
|
||||
|
||||
cal_slug = getattr(calendar, "slug", "")
|
||||
edit_url = url_for("calendar.admin.calendar_description_edit", calendar_slug=cal_slug)
|
||||
html = await _calendar_description_display_html(calendar, edit_url)
|
||||
html = _calendar_description_display_html(calendar, edit_url)
|
||||
|
||||
if oob:
|
||||
desc = getattr(calendar, "description", "") or ""
|
||||
html += await render_to_sx("events-calendar-description-title-oob",
|
||||
html += sx_call("events-calendar-description-title-oob",
|
||||
description=desc)
|
||||
return html
|
||||
|
||||
|
||||
async def render_calendar_description_edit(calendar) -> str:
|
||||
def render_calendar_description_edit(calendar) -> str:
|
||||
"""Render calendar description edit form."""
|
||||
from quart import url_for
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.helpers import sx_call
|
||||
csrf = generate_csrf_token()
|
||||
cal_slug = getattr(calendar, "slug", "")
|
||||
desc = getattr(calendar, "description", "") or ""
|
||||
@@ -268,7 +268,7 @@ async def render_calendar_description_edit(calendar) -> str:
|
||||
save_url = url_for("calendar.admin.calendar_description_save", calendar_slug=cal_slug)
|
||||
cancel_url = url_for("calendar.admin.calendar_description_view", calendar_slug=cal_slug)
|
||||
|
||||
return await render_to_sx("events-calendar-description-edit-form",
|
||||
return sx_call("events-calendar-description-edit-form",
|
||||
save_url=save_url, cancel_url=cancel_url,
|
||||
csrf=csrf, description=desc)
|
||||
|
||||
@@ -277,11 +277,11 @@ async def render_calendar_description_edit(calendar) -> str:
|
||||
# Calendars / Markets list panels (for POST create / DELETE)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_calendars_list_panel(ctx: dict) -> str:
|
||||
def render_calendars_list_panel(ctx: dict) -> str:
|
||||
"""Render the calendars main panel HTML for POST/DELETE response."""
|
||||
return await _calendars_main_panel_sx(ctx)
|
||||
return _calendars_main_panel_sx(ctx)
|
||||
|
||||
|
||||
async def render_markets_list_panel(ctx: dict) -> str:
|
||||
def render_markets_list_panel(ctx: dict) -> str:
|
||||
"""Render the markets main panel HTML for POST/DELETE response."""
|
||||
return await _markets_main_panel_html(ctx)
|
||||
return _markets_main_panel_html(ctx)
|
||||
|
||||
Reference in New Issue
Block a user