Move events/market/blog composition from Python to .sx defcomps (Phase 9)
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 2m33s
Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 2m33s
Continues the pattern of eliminating Python sx_call tree-building in favour of data-driven .sx defcomps. POST/PUT/DELETE routes now pass plain data (dicts, lists, scalars) and let .sx handle iteration, conditionals, and layout via map/let/when/if. Single response components wrap OOB swaps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,31 +14,6 @@ from shared.sx.helpers import sx_call
|
||||
# Post header helpers — thin wrapper over shared post_header_sx
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _clear_oob(*ids: str) -> str:
|
||||
"""Generate OOB swaps to remove orphaned header rows/children."""
|
||||
from shared.sx.helpers import sx_call
|
||||
return "".join(sx_call("clear-oob-div", id=i) for i in ids)
|
||||
|
||||
|
||||
# All possible header row/child IDs at each depth (deepest first)
|
||||
_EVENTS_DEEP_IDS = [
|
||||
"entry-admin-row", "entry-admin-header-child",
|
||||
"entry-row", "entry-header-child",
|
||||
"day-admin-row", "day-admin-header-child",
|
||||
"day-row", "day-header-child",
|
||||
"calendar-admin-row", "calendar-admin-header-child",
|
||||
"calendar-row", "calendar-header-child",
|
||||
"calendars-row", "calendars-header-child",
|
||||
"post-admin-row", "post-admin-header-child",
|
||||
]
|
||||
|
||||
|
||||
def _clear_deeper_oob(*keep_ids: str) -> str:
|
||||
"""Clear all events header rows/children NOT in keep_ids."""
|
||||
to_clear = [i for i in _EVENTS_DEEP_IDS if i not in keep_ids]
|
||||
return _clear_oob(*to_clear)
|
||||
|
||||
|
||||
async def _ensure_container_nav(ctx: dict) -> dict:
|
||||
"""Fetch container_nav if not already present (for post header row)."""
|
||||
if ctx.get("container_nav"):
|
||||
@@ -87,19 +62,6 @@ def _entry_state_badge_html(state: str) -> str:
|
||||
return sx_call("badge", cls=cls, label=label)
|
||||
|
||||
|
||||
def _ticket_state_badge_html(state: str) -> str:
|
||||
"""Render a ticket state badge."""
|
||||
cls_map = {
|
||||
"confirmed": "bg-emerald-100 text-emerald-800",
|
||||
"checked_in": "bg-blue-100 text-blue-800",
|
||||
"reserved": "bg-amber-100 text-amber-800",
|
||||
"cancelled": "bg-red-100 text-red-800",
|
||||
}
|
||||
cls = cls_map.get(state, "bg-stone-100 text-stone-700")
|
||||
label = (state or "").replace("_", " ").capitalize()
|
||||
return sx_call("badge", cls=cls, label=label)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# View toggle + SVG caching
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -150,6 +112,12 @@ def _view_toggle_html(ctx: dict, view: str) -> str:
|
||||
|
||||
def _cart_icon_oob(count: int) -> str:
|
||||
"""Render the OOB cart icon/badge swap."""
|
||||
ctx = _cart_icon_ctx(count)
|
||||
return sx_call("events-cart-icon", **ctx)
|
||||
|
||||
|
||||
def _cart_icon_ctx(count: int) -> dict:
|
||||
"""Return data dict for the ~events-cart-icon component."""
|
||||
from quart import g
|
||||
|
||||
blog_url_fn = getattr(g, "blog_url", None)
|
||||
@@ -160,11 +128,11 @@ def _cart_icon_oob(count: int) -> str:
|
||||
site_obj = site_fn() if callable(site_fn) else site_fn
|
||||
logo = getattr(site_obj, "logo", "") if site_obj else ""
|
||||
|
||||
if count == 0:
|
||||
blog_href = blog_url_fn("/") if blog_url_fn else "/"
|
||||
return sx_call("events-cart-icon-logo",
|
||||
blog_href=blog_href, logo=logo)
|
||||
|
||||
blog_href = blog_url_fn("/") if blog_url_fn else "/"
|
||||
cart_href = cart_url_fn("/") if cart_url_fn else "/"
|
||||
return sx_call("events-cart-icon-badge",
|
||||
cart_href=cart_href, count=str(count))
|
||||
return {
|
||||
"cart_count": count,
|
||||
"blog_href": blog_href,
|
||||
"cart_href": cart_href,
|
||||
"logo": logo,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user