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,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from markupsafe import escape
|
||||
|
||||
from shared.sx.helpers import render_to_sx
|
||||
from shared.sx.helpers import sx_call
|
||||
from shared.sx.parser import SxExpr
|
||||
|
||||
from .utils import (
|
||||
@@ -15,7 +15,7 @@ from .utils import (
|
||||
# Ticket widget (inline +/- for entry cards)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _ticket_widget_html(entry, qty: int, ticket_url: str, *, ctx: dict) -> str:
|
||||
def _ticket_widget_html(entry, qty: int, ticket_url: str, *, ctx: dict) -> str:
|
||||
"""Render the inline +/- ticket widget."""
|
||||
csrf_token_val = ""
|
||||
if ctx:
|
||||
@@ -32,22 +32,22 @@ async def _ticket_widget_html(entry, qty: int, ticket_url: str, *, ctx: dict) ->
|
||||
tp = getattr(entry, "ticket_price", 0) or 0
|
||||
tgt = f"#page-ticket-{eid}"
|
||||
|
||||
async def _tw_form(count_val, btn_html):
|
||||
return await render_to_sx("events-tw-form",
|
||||
def _tw_form(count_val, btn_html):
|
||||
return sx_call("events-tw-form",
|
||||
ticket_url=ticket_url, target=tgt,
|
||||
csrf=csrf_token_val, entry_id=str(eid),
|
||||
count_val=str(count_val), btn=SxExpr(btn_html))
|
||||
|
||||
if qty == 0:
|
||||
inner = await _tw_form(1, await render_to_sx("events-tw-cart-plus"))
|
||||
inner = _tw_form(1, sx_call("events-tw-cart-plus"))
|
||||
else:
|
||||
minus = await _tw_form(qty - 1, await render_to_sx("events-tw-minus"))
|
||||
cart_icon = await render_to_sx("events-tw-cart-icon", qty=str(qty))
|
||||
plus = await _tw_form(qty + 1, await render_to_sx("events-tw-plus"))
|
||||
minus = _tw_form(qty - 1, sx_call("events-tw-minus"))
|
||||
cart_icon = sx_call("events-tw-cart-icon", qty=str(qty))
|
||||
plus = _tw_form(qty + 1, sx_call("events-tw-plus"))
|
||||
inner = minus + cart_icon + plus
|
||||
|
||||
return await render_to_sx("events-tw-widget",
|
||||
entry_id=str(eid), price=f"£{tp:.2f}",
|
||||
return sx_call("events-tw-widget",
|
||||
entry_id=str(eid), price=f"\u00a3{tp:.2f}",
|
||||
inner=SxExpr(inner))
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ async def _ticket_widget_html(entry, qty: int, ticket_url: str, *, ctx: dict) ->
|
||||
# Tickets main panel (my tickets)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _tickets_main_panel_html(ctx: dict, tickets: list) -> str:
|
||||
def _tickets_main_panel_html(ctx: dict, tickets: list) -> str:
|
||||
"""Render my tickets list."""
|
||||
from quart import url_for
|
||||
|
||||
@@ -75,16 +75,16 @@ async def _tickets_main_panel_html(ctx: dict, tickets: list) -> str:
|
||||
if entry.end_at:
|
||||
time_str += f" \u2013 {entry.end_at.strftime('%H:%M')}"
|
||||
|
||||
ticket_cards.append(await render_to_sx("events-ticket-card",
|
||||
ticket_cards.append(sx_call("events-ticket-card",
|
||||
href=href, entry_name=entry_name,
|
||||
type_name=tt.name if tt else None,
|
||||
time_str=time_str or None,
|
||||
cal_name=cal.name if cal else None,
|
||||
badge=SxExpr(await _ticket_state_badge_html(state)),
|
||||
badge=SxExpr(_ticket_state_badge_html(state)),
|
||||
code_prefix=ticket.code[:8]))
|
||||
|
||||
cards_html = "".join(ticket_cards)
|
||||
return await render_to_sx("events-tickets-panel",
|
||||
return sx_call("events-tickets-panel",
|
||||
list_container=_list_container(ctx),
|
||||
has_tickets=bool(tickets), cards=SxExpr(cards_html))
|
||||
|
||||
@@ -93,7 +93,7 @@ async def _tickets_main_panel_html(ctx: dict, tickets: list) -> str:
|
||||
# Ticket detail panel
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _ticket_detail_panel_html(ctx: dict, ticket) -> str:
|
||||
def _ticket_detail_panel_html(ctx: dict, ticket) -> str:
|
||||
"""Render a single ticket detail with QR code."""
|
||||
from quart import url_for
|
||||
|
||||
@@ -110,7 +110,7 @@ async def _ticket_detail_panel_html(ctx: dict, ticket) -> str:
|
||||
back_href = url_for("defpage_my_tickets")
|
||||
|
||||
# Badge with larger sizing
|
||||
badge = (await _ticket_state_badge_html(state)).replace('px-2 py-0.5 text-xs', 'px-3 py-1 text-sm')
|
||||
badge = (_ticket_state_badge_html(state)).replace('px-2 py-0.5 text-xs', 'px-3 py-1 text-sm')
|
||||
|
||||
# Time info
|
||||
time_date = entry.start_at.strftime("%A, %B %d, %Y") if entry and entry.start_at else None
|
||||
@@ -129,7 +129,7 @@ async def _ticket_detail_panel_html(ctx: dict, ticket) -> str:
|
||||
"}})()"
|
||||
)
|
||||
|
||||
return await render_to_sx("events-ticket-detail",
|
||||
return sx_call("events-ticket-detail",
|
||||
list_container=_list_container(ctx), back_href=back_href,
|
||||
header_bg=header_bg, entry_name=entry_name,
|
||||
badge=SxExpr(badge), type_name=tt.name if tt else None,
|
||||
@@ -143,7 +143,7 @@ async def _ticket_detail_panel_html(ctx: dict, ticket) -> str:
|
||||
# Ticket admin main panel
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _ticket_admin_main_panel_html(ctx: dict, tickets: list, stats: dict) -> str:
|
||||
def _ticket_admin_main_panel_html(ctx: dict, tickets: list, stats: dict) -> str:
|
||||
"""Render ticket admin dashboard."""
|
||||
from quart import url_for
|
||||
csrf_token = ctx.get("csrf_token")
|
||||
@@ -160,7 +160,7 @@ async def _ticket_admin_main_panel_html(ctx: dict, tickets: list, stats: dict) -
|
||||
]:
|
||||
val = stats.get(key, 0)
|
||||
lbl_cls = text_cls.replace("700", "600").replace("900", "500") if "stone" not in text_cls else "text-stone-500"
|
||||
stats_html += await render_to_sx("events-ticket-admin-stat",
|
||||
stats_html += sx_call("events-ticket-admin-stat",
|
||||
border=border, bg=bg, text_cls=text_cls,
|
||||
label_cls=lbl_cls, value=str(val), label=label)
|
||||
|
||||
@@ -174,29 +174,29 @@ async def _ticket_admin_main_panel_html(ctx: dict, tickets: list, stats: dict) -
|
||||
|
||||
date_html = ""
|
||||
if entry and entry.start_at:
|
||||
date_html = await render_to_sx("events-ticket-admin-date",
|
||||
date_html = sx_call("events-ticket-admin-date",
|
||||
date_str=entry.start_at.strftime("%d %b %Y, %H:%M"))
|
||||
|
||||
action_html = ""
|
||||
if state in ("confirmed", "reserved"):
|
||||
checkin_url = url_for("ticket_admin.do_checkin", code=code)
|
||||
action_html = await render_to_sx("events-ticket-admin-checkin-form",
|
||||
action_html = sx_call("events-ticket-admin-checkin-form",
|
||||
checkin_url=checkin_url, code=code, csrf=csrf)
|
||||
elif state == "checked_in":
|
||||
checked_in_at = getattr(ticket, "checked_in_at", None)
|
||||
t_str = checked_in_at.strftime("%H:%M") if checked_in_at else ""
|
||||
action_html = await render_to_sx("events-ticket-admin-checked-in",
|
||||
action_html = sx_call("events-ticket-admin-checked-in",
|
||||
time_str=t_str)
|
||||
|
||||
rows_html += await render_to_sx("events-ticket-admin-row",
|
||||
rows_html += sx_call("events-ticket-admin-row",
|
||||
code=code, code_short=code[:12] + "...",
|
||||
entry_name=entry.name if entry else "\u2014",
|
||||
date=SxExpr(date_html),
|
||||
type_name=tt.name if tt else "\u2014",
|
||||
badge=SxExpr(await _ticket_state_badge_html(state)),
|
||||
badge=SxExpr(_ticket_state_badge_html(state)),
|
||||
action=SxExpr(action_html))
|
||||
|
||||
return await render_to_sx("events-ticket-admin-panel",
|
||||
return sx_call("events-ticket-admin-panel",
|
||||
list_container=_list_container(ctx), stats=SxExpr(stats_html),
|
||||
lookup_url=lookup_url, has_tickets=bool(tickets),
|
||||
rows=SxExpr(rows_html))
|
||||
@@ -206,19 +206,19 @@ async def _ticket_admin_main_panel_html(ctx: dict, tickets: list, stats: dict) -
|
||||
# Public render: ticket widget
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_ticket_widget(entry, qty: int, ticket_url: str) -> str:
|
||||
def render_ticket_widget(entry, qty: int, ticket_url: str) -> str:
|
||||
"""Render the +/- ticket widget for page_summary / all_events adjust_ticket."""
|
||||
return await _ticket_widget_html(entry, qty, ticket_url, ctx={})
|
||||
return _ticket_widget_html(entry, qty, ticket_url, ctx={})
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Ticket admin: checkin result
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_checkin_result(success: bool, error: str | None, ticket) -> str:
|
||||
def render_checkin_result(success: bool, error: str | None, ticket) -> str:
|
||||
"""Render checkin result: table row on success, error div on failure."""
|
||||
if not success:
|
||||
return await render_to_sx("events-checkin-error",
|
||||
return sx_call("events-checkin-error",
|
||||
message=error or "Check-in failed")
|
||||
if not ticket:
|
||||
return ""
|
||||
@@ -230,15 +230,15 @@ async def render_checkin_result(success: bool, error: str | None, ticket) -> str
|
||||
|
||||
date_html = ""
|
||||
if entry and entry.start_at:
|
||||
date_html = await render_to_sx("events-ticket-admin-date",
|
||||
date_html = sx_call("events-ticket-admin-date",
|
||||
date_str=entry.start_at.strftime("%d %b %Y, %H:%M"))
|
||||
|
||||
return await render_to_sx("events-checkin-success-row",
|
||||
return sx_call("events-checkin-success-row",
|
||||
code=code, code_short=code[:12] + "...",
|
||||
entry_name=entry.name if entry else "\u2014",
|
||||
date=SxExpr(date_html),
|
||||
type_name=tt.name if tt else "\u2014",
|
||||
badge=SxExpr(await _ticket_state_badge_html("checked_in")),
|
||||
badge=SxExpr(_ticket_state_badge_html("checked_in")),
|
||||
time_str=time_str)
|
||||
|
||||
|
||||
@@ -246,13 +246,13 @@ async def render_checkin_result(success: bool, error: str | None, ticket) -> str
|
||||
# Ticket admin: lookup result
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_lookup_result(ticket, error: str | None) -> str:
|
||||
def render_lookup_result(ticket, error: str | None) -> str:
|
||||
"""Render ticket lookup result: error div or ticket info card."""
|
||||
from quart import url_for
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
|
||||
if error:
|
||||
return await render_to_sx("events-lookup-error", message=error)
|
||||
return sx_call("events-lookup-error", message=error)
|
||||
if not ticket:
|
||||
return ""
|
||||
|
||||
@@ -264,34 +264,34 @@ async def render_lookup_result(ticket, error: str | None) -> str:
|
||||
csrf = generate_csrf_token()
|
||||
|
||||
# Info section
|
||||
info_html = await render_to_sx("events-lookup-info",
|
||||
info_html = sx_call("events-lookup-info",
|
||||
entry_name=entry.name if entry else "Unknown event")
|
||||
if tt:
|
||||
info_html += await render_to_sx("events-lookup-type", type_name=tt.name)
|
||||
info_html += sx_call("events-lookup-type", type_name=tt.name)
|
||||
if entry and entry.start_at:
|
||||
info_html += await render_to_sx("events-lookup-date",
|
||||
info_html += sx_call("events-lookup-date",
|
||||
date_str=entry.start_at.strftime("%A, %B %d, %Y at %H:%M"))
|
||||
cal = getattr(entry, "calendar", None) if entry else None
|
||||
if cal:
|
||||
info_html += await render_to_sx("events-lookup-cal", cal_name=cal.name)
|
||||
info_html += await render_to_sx("events-lookup-status",
|
||||
badge=SxExpr(await _ticket_state_badge_html(state)), code=code)
|
||||
info_html += sx_call("events-lookup-cal", cal_name=cal.name)
|
||||
info_html += sx_call("events-lookup-status",
|
||||
badge=SxExpr(_ticket_state_badge_html(state)), code=code)
|
||||
if checked_in_at:
|
||||
info_html += await render_to_sx("events-lookup-checkin-time",
|
||||
info_html += sx_call("events-lookup-checkin-time",
|
||||
date_str=checked_in_at.strftime("%B %d, %Y at %H:%M"))
|
||||
|
||||
# Action area
|
||||
action_html = ""
|
||||
if state in ("confirmed", "reserved"):
|
||||
checkin_url = url_for("ticket_admin.do_checkin", code=code)
|
||||
action_html = await render_to_sx("events-lookup-checkin-btn",
|
||||
action_html = sx_call("events-lookup-checkin-btn",
|
||||
checkin_url=checkin_url, code=code, csrf=csrf)
|
||||
elif state == "checked_in":
|
||||
action_html = await render_to_sx("events-lookup-checked-in")
|
||||
action_html = sx_call("events-lookup-checked-in")
|
||||
elif state == "cancelled":
|
||||
action_html = await render_to_sx("events-lookup-cancelled")
|
||||
action_html = sx_call("events-lookup-cancelled")
|
||||
|
||||
return await render_to_sx("events-lookup-card",
|
||||
return sx_call("events-lookup-card",
|
||||
info=SxExpr(info_html), code=code, action=SxExpr(action_html))
|
||||
|
||||
|
||||
@@ -299,7 +299,7 @@ async def render_lookup_result(ticket, error: str | None) -> str:
|
||||
# Ticket admin: entry tickets table
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_entry_tickets_admin(entry, tickets: list) -> str:
|
||||
def render_entry_tickets_admin(entry, tickets: list) -> str:
|
||||
"""Render admin ticket table for a specific entry."""
|
||||
from quart import url_for
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -318,26 +318,26 @@ async def render_entry_tickets_admin(entry, tickets: list) -> str:
|
||||
action_html = ""
|
||||
if state in ("confirmed", "reserved"):
|
||||
checkin_url = url_for("ticket_admin.do_checkin", code=code)
|
||||
action_html = await render_to_sx("events-entry-tickets-admin-checkin",
|
||||
action_html = sx_call("events-entry-tickets-admin-checkin",
|
||||
checkin_url=checkin_url, code=code, csrf=csrf)
|
||||
elif state == "checked_in":
|
||||
t_str = checked_in_at.strftime("%H:%M") if checked_in_at else ""
|
||||
action_html = await render_to_sx("events-ticket-admin-checked-in",
|
||||
action_html = sx_call("events-ticket-admin-checked-in",
|
||||
time_str=t_str)
|
||||
|
||||
rows_html += await render_to_sx("events-entry-tickets-admin-row",
|
||||
rows_html += sx_call("events-entry-tickets-admin-row",
|
||||
code=code, code_short=code[:12] + "...",
|
||||
type_name=tt.name if tt else "\u2014",
|
||||
badge=SxExpr(await _ticket_state_badge_html(state)),
|
||||
badge=SxExpr(_ticket_state_badge_html(state)),
|
||||
action=SxExpr(action_html))
|
||||
|
||||
if tickets:
|
||||
body_html = await render_to_sx("events-entry-tickets-admin-table",
|
||||
body_html = sx_call("events-entry-tickets-admin-table",
|
||||
rows=SxExpr(rows_html))
|
||||
else:
|
||||
body_html = await render_to_sx("events-entry-tickets-admin-empty")
|
||||
body_html = sx_call("events-entry-tickets-admin-empty")
|
||||
|
||||
return await render_to_sx("events-entry-tickets-admin-panel",
|
||||
return sx_call("events-entry-tickets-admin-panel",
|
||||
entry_name=entry.name,
|
||||
count_label=f"{count} ticket{suffix}",
|
||||
body=SxExpr(body_html))
|
||||
@@ -347,7 +347,7 @@ async def render_entry_tickets_admin(entry, tickets: list) -> str:
|
||||
# Ticket type main panel
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_ticket_type_main_panel(ticket_type, entry, calendar, day, month, year, *, oob: bool = False) -> str:
|
||||
def render_ticket_type_main_panel(ticket_type, entry, calendar, day, month, year, *, oob: bool = False) -> str:
|
||||
"""Render ticket type detail view."""
|
||||
from quart import url_for, g
|
||||
|
||||
@@ -367,14 +367,14 @@ async def render_ticket_type_main_panel(ticket_type, entry, calendar, day, month
|
||||
year=year, month=month, day=day, entry_id=entry.id,
|
||||
)
|
||||
|
||||
async def _col(label, val):
|
||||
return await render_to_sx("events-ticket-type-col", label=label, value=val)
|
||||
def _col(label, val):
|
||||
return sx_call("events-ticket-type-col", label=label, value=val)
|
||||
|
||||
return await render_to_sx("events-ticket-type-panel",
|
||||
return sx_call("events-ticket-type-panel",
|
||||
ticket_id=tid, list_container=list_container,
|
||||
c1=await _col("Name", ticket_type.name),
|
||||
c2=await _col("Cost", cost_str),
|
||||
c3=await _col("Count", str(count)),
|
||||
c1=_col("Name", ticket_type.name),
|
||||
c2=_col("Cost", cost_str),
|
||||
c3=_col("Count", str(count)),
|
||||
pre_action=pre_action, edit_url=edit_url)
|
||||
|
||||
|
||||
@@ -382,7 +382,7 @@ async def render_ticket_type_main_panel(ticket_type, entry, calendar, day, month
|
||||
# Ticket types table
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_ticket_types_table(ticket_types, entry, calendar, day, month, year) -> str:
|
||||
def render_ticket_types_table(ticket_types, entry, calendar, day, month, year) -> str:
|
||||
"""Render ticket types table with rows and add button."""
|
||||
from quart import url_for, g
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -413,7 +413,7 @@ async def render_ticket_types_table(ticket_types, entry, calendar, day, month, y
|
||||
cost = getattr(tt, "cost", None)
|
||||
cost_str = f"\u00a3{cost:.2f}" if cost is not None else "\u00a30.00"
|
||||
|
||||
rows_html += await render_to_sx("events-ticket-types-row",
|
||||
rows_html += sx_call("events-ticket-types-row",
|
||||
tr_cls=tr_cls, tt_href=tt_href,
|
||||
pill_cls=pill_cls, hx_select=hx_select,
|
||||
tt_name=tt.name, cost_str=cost_str,
|
||||
@@ -421,14 +421,14 @@ async def render_ticket_types_table(ticket_types, entry, calendar, day, month, y
|
||||
del_url=del_url,
|
||||
csrf_hdr=f'{{"X-CSRFToken": "{csrf}"}}')
|
||||
else:
|
||||
rows_html = await render_to_sx("events-ticket-types-empty-row")
|
||||
rows_html = sx_call("events-ticket-types-empty-row")
|
||||
|
||||
add_url = url_for(
|
||||
"calendar.day.calendar_entries.calendar_entry.ticket_types.add_form",
|
||||
calendar_slug=cal_slug, entry_id=eid, year=year, month=month, day=day,
|
||||
)
|
||||
|
||||
return await render_to_sx("events-ticket-types-table",
|
||||
return sx_call("events-ticket-types-table",
|
||||
list_container=list_container, rows=SxExpr(rows_html),
|
||||
action_btn=action_btn, add_url=add_url)
|
||||
|
||||
@@ -437,11 +437,11 @@ async def render_ticket_types_table(ticket_types, entry, calendar, day, month, y
|
||||
# Buy result (ticket purchase confirmation)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_buy_result(entry, created_tickets, remaining, cart_count) -> str:
|
||||
def render_buy_result(entry, created_tickets, remaining, cart_count) -> str:
|
||||
"""Render buy result card with created tickets + OOB cart icon."""
|
||||
from quart import url_for
|
||||
|
||||
cart_html = await _cart_icon_oob(cart_count)
|
||||
cart_html = _cart_icon_oob(cart_count)
|
||||
|
||||
count = len(created_tickets)
|
||||
suffix = "s" if count != 1 else ""
|
||||
@@ -449,18 +449,18 @@ async def render_buy_result(entry, created_tickets, remaining, cart_count) -> st
|
||||
tickets_html = ""
|
||||
for ticket in created_tickets:
|
||||
href = url_for("defpage_ticket_detail", code=ticket.code)
|
||||
tickets_html += await render_to_sx("events-buy-result-ticket",
|
||||
tickets_html += sx_call("events-buy-result-ticket",
|
||||
href=href, code_short=ticket.code[:12] + "...")
|
||||
|
||||
remaining_html = ""
|
||||
if remaining is not None:
|
||||
r_suffix = "s" if remaining != 1 else ""
|
||||
remaining_html = await render_to_sx("events-buy-result-remaining",
|
||||
remaining_html = sx_call("events-buy-result-remaining",
|
||||
text=f"{remaining} ticket{r_suffix} remaining")
|
||||
|
||||
my_href = url_for("defpage_my_tickets")
|
||||
|
||||
return cart_html + await render_to_sx("events-buy-result",
|
||||
return cart_html + sx_call("events-buy-result",
|
||||
entry_id=str(entry.id),
|
||||
count_label=f"{count} ticket{suffix} reserved",
|
||||
tickets=SxExpr(tickets_html),
|
||||
@@ -472,7 +472,7 @@ async def render_buy_result(entry, created_tickets, remaining, cart_count) -> st
|
||||
# Buy form (ticket +/- controls)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_buy_form(entry, ticket_remaining, ticket_sold_count,
|
||||
def render_buy_form(entry, ticket_remaining, ticket_sold_count,
|
||||
user_ticket_count, user_ticket_counts_by_type) -> str:
|
||||
"""Render the ticket buy/adjust form with +/- controls."""
|
||||
from quart import url_for
|
||||
@@ -489,7 +489,7 @@ async def render_buy_form(entry, ticket_remaining, ticket_sold_count,
|
||||
return ""
|
||||
|
||||
if state != "confirmed":
|
||||
return await render_to_sx("events-buy-not-confirmed", entry_id=eid_s)
|
||||
return sx_call("events-buy-not-confirmed", entry_id=eid_s)
|
||||
|
||||
adjust_url = url_for("tickets.adjust_quantity")
|
||||
target = f"#ticket-buy-{eid}"
|
||||
@@ -498,16 +498,16 @@ async def render_buy_form(entry, ticket_remaining, ticket_sold_count,
|
||||
info_html = ""
|
||||
info_items = ""
|
||||
if ticket_sold_count:
|
||||
info_items += await render_to_sx("events-buy-info-sold",
|
||||
info_items += sx_call("events-buy-info-sold",
|
||||
count=str(ticket_sold_count))
|
||||
if ticket_remaining is not None:
|
||||
info_items += await render_to_sx("events-buy-info-remaining",
|
||||
info_items += sx_call("events-buy-info-remaining",
|
||||
count=str(ticket_remaining))
|
||||
if user_ticket_count:
|
||||
info_items += await render_to_sx("events-buy-info-basket",
|
||||
info_items += sx_call("events-buy-info-basket",
|
||||
count=str(user_ticket_count))
|
||||
if info_items:
|
||||
info_html = await render_to_sx("events-buy-info-bar", items=SxExpr(info_items))
|
||||
info_html = sx_call("events-buy-info-bar", items=SxExpr(info_items))
|
||||
|
||||
active_types = [tt for tt in ticket_types if getattr(tt, "deleted_at", None) is None]
|
||||
|
||||
@@ -517,46 +517,46 @@ async def render_buy_form(entry, ticket_remaining, ticket_sold_count,
|
||||
for tt in active_types:
|
||||
type_count = user_ticket_counts_by_type.get(tt.id, 0) if user_ticket_counts_by_type else 0
|
||||
cost_str = f"\u00a3{tt.cost:.2f}" if tt.cost is not None else "\u00a30.00"
|
||||
type_items += await render_to_sx("events-buy-type-item",
|
||||
type_items += sx_call("events-buy-type-item",
|
||||
type_name=tt.name, cost_str=cost_str,
|
||||
adjust_controls=SxExpr(await _ticket_adjust_controls(csrf, adjust_url, target, eid, type_count, ticket_type_id=tt.id)))
|
||||
body_html = await render_to_sx("events-buy-types-wrapper", items=SxExpr(type_items))
|
||||
adjust_controls=SxExpr(_ticket_adjust_controls(csrf, adjust_url, target, eid, type_count, ticket_type_id=tt.id)))
|
||||
body_html = sx_call("events-buy-types-wrapper", items=SxExpr(type_items))
|
||||
else:
|
||||
qty = user_ticket_count or 0
|
||||
body_html = await render_to_sx("events-buy-default",
|
||||
body_html = sx_call("events-buy-default",
|
||||
price_str=f"\u00a3{tp:.2f}",
|
||||
adjust_controls=SxExpr(await _ticket_adjust_controls(csrf, adjust_url, target, eid, qty)))
|
||||
adjust_controls=SxExpr(_ticket_adjust_controls(csrf, adjust_url, target, eid, qty)))
|
||||
|
||||
return await render_to_sx("events-buy-panel",
|
||||
return sx_call("events-buy-panel",
|
||||
entry_id=eid_s, info=SxExpr(info_html), body=SxExpr(body_html))
|
||||
|
||||
|
||||
async def _ticket_adjust_controls(csrf, adjust_url, target, entry_id, count, *, ticket_type_id=None):
|
||||
def _ticket_adjust_controls(csrf, adjust_url, target, entry_id, count, *, ticket_type_id=None):
|
||||
"""Render +/- ticket controls for buy form."""
|
||||
from quart import url_for
|
||||
|
||||
tt_html = await render_to_sx("events-adjust-tt-hidden",
|
||||
tt_html = sx_call("events-adjust-tt-hidden",
|
||||
ticket_type_id=str(ticket_type_id)) if ticket_type_id else ""
|
||||
eid_s = str(entry_id)
|
||||
|
||||
async def _adj_form(count_val, btn_html, *, extra_cls=""):
|
||||
return await render_to_sx("events-adjust-form",
|
||||
def _adj_form(count_val, btn_html, *, extra_cls=""):
|
||||
return sx_call("events-adjust-form",
|
||||
adjust_url=adjust_url, target=target,
|
||||
extra_cls=extra_cls, csrf=csrf,
|
||||
entry_id=eid_s, tt=SxExpr(tt_html) if tt_html else None,
|
||||
count_val=str(count_val), btn=SxExpr(btn_html))
|
||||
|
||||
if count == 0:
|
||||
return await _adj_form(1, await render_to_sx("events-adjust-cart-plus"),
|
||||
return _adj_form(1, sx_call("events-adjust-cart-plus"),
|
||||
extra_cls="flex items-center")
|
||||
|
||||
my_tickets_href = url_for("defpage_my_tickets")
|
||||
minus = await _adj_form(count - 1, await render_to_sx("events-adjust-minus"))
|
||||
cart_icon = await render_to_sx("events-adjust-cart-icon",
|
||||
minus = _adj_form(count - 1, sx_call("events-adjust-minus"))
|
||||
cart_icon = sx_call("events-adjust-cart-icon",
|
||||
href=my_tickets_href, count=str(count))
|
||||
plus = await _adj_form(count + 1, await render_to_sx("events-adjust-plus"))
|
||||
plus = _adj_form(count + 1, sx_call("events-adjust-plus"))
|
||||
|
||||
return await render_to_sx("events-adjust-controls",
|
||||
return sx_call("events-adjust-controls",
|
||||
minus=SxExpr(minus), cart_icon=SxExpr(cart_icon), plus=SxExpr(plus))
|
||||
|
||||
|
||||
@@ -564,12 +564,12 @@ async def _ticket_adjust_controls(csrf, adjust_url, target, entry_id, count, *,
|
||||
# Adjust response (OOB cart icon + buy form)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_adjust_response(entry, ticket_remaining, ticket_sold_count,
|
||||
def render_adjust_response(entry, ticket_remaining, ticket_sold_count,
|
||||
user_ticket_count, user_ticket_counts_by_type,
|
||||
cart_count) -> str:
|
||||
"""Render ticket adjust response: OOB cart icon + buy form."""
|
||||
cart_html = await _cart_icon_oob(cart_count)
|
||||
form_html = await render_buy_form(
|
||||
cart_html = _cart_icon_oob(cart_count)
|
||||
form_html = render_buy_form(
|
||||
entry, ticket_remaining, ticket_sold_count,
|
||||
user_ticket_count, user_ticket_counts_by_type,
|
||||
)
|
||||
@@ -580,7 +580,7 @@ async def render_adjust_response(entry, ticket_remaining, ticket_sold_count,
|
||||
# Ticket types header rows
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def _ticket_types_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
def _ticket_types_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
"""Build the ticket types header row."""
|
||||
from quart import url_for
|
||||
|
||||
@@ -599,15 +599,15 @@ async def _ticket_types_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
|
||||
label_html = '<i class="fa fa-ticket"></i><div class="shrink-0">ticket types</div>'
|
||||
|
||||
nav_html = await render_to_sx("events-admin-placeholder-nav")
|
||||
nav_html = sx_call("events-admin-placeholder-nav")
|
||||
|
||||
return await render_to_sx("menu-row-sx", id="ticket_types-row", level=7,
|
||||
return sx_call("menu-row-sx", id="ticket_types-row", level=7,
|
||||
link_href=link_href, link_label_content=SxExpr(label_html),
|
||||
nav=SxExpr(nav_html) if nav_html else None, child_id="ticket_type-header-child", oob=oob)
|
||||
|
||||
|
||||
|
||||
async def _ticket_type_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
def _ticket_type_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
"""Build the single ticket type header row."""
|
||||
from quart import url_for
|
||||
|
||||
@@ -635,9 +635,9 @@ async def _ticket_type_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
f'</div></div>'
|
||||
)
|
||||
|
||||
nav_html = await render_to_sx("events-admin-placeholder-nav")
|
||||
nav_html = sx_call("events-admin-placeholder-nav")
|
||||
|
||||
return await render_to_sx("menu-row-sx", id="ticket_type-row", level=8,
|
||||
return sx_call("menu-row-sx", id="ticket_type-row", level=8,
|
||||
link_href=link_href, link_label_content=SxExpr(label_html),
|
||||
nav=SxExpr(nav_html) if nav_html else None, child_id="ticket_type-header-child-inner", oob=oob)
|
||||
|
||||
@@ -646,7 +646,7 @@ async def _ticket_type_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
# Ticket type edit form
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_ticket_type_edit_form(ticket_type, entry, calendar, day, month, year) -> str:
|
||||
def render_ticket_type_edit_form(ticket_type, entry, calendar, day, month, year) -> str:
|
||||
"""Render ticket type edit form (replaces _types/ticket_type/_edit.html)."""
|
||||
from quart import url_for, g
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -670,7 +670,7 @@ async def render_ticket_type_edit_form(ticket_type, entry, calendar, day, month,
|
||||
cost_val = f"{cost:.2f}" if cost is not None else ""
|
||||
count = getattr(ticket_type, "count", 0)
|
||||
|
||||
return await render_to_sx("events-ticket-type-edit-form",
|
||||
return sx_call("events-ticket-type-edit-form",
|
||||
ticket_id=str(tid), list_container=list_container,
|
||||
put_url=put_url, cancel_url=cancel_url, csrf=csrf,
|
||||
name_val=ticket_type.name or "",
|
||||
@@ -682,7 +682,7 @@ async def render_ticket_type_edit_form(ticket_type, entry, calendar, day, month,
|
||||
# Ticket type add form / button
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_ticket_type_add_form(entry, calendar, day, month, year) -> str:
|
||||
def render_ticket_type_add_form(entry, calendar, day, month, year) -> str:
|
||||
"""Render ticket type add form (replaces _types/ticket_types/_add.html)."""
|
||||
from quart import url_for, g
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
@@ -701,13 +701,13 @@ async def render_ticket_type_add_form(entry, calendar, day, month, year) -> str:
|
||||
year=year, month=month, day=day)
|
||||
csrf_hdr = f'{{"X-CSRFToken": "{csrf}"}}'
|
||||
|
||||
return await render_to_sx("events-ticket-type-add-form",
|
||||
return sx_call("events-ticket-type-add-form",
|
||||
post_url=post_url, csrf=csrf_hdr,
|
||||
action_btn=action_btn, cancel_btn=cancel_btn,
|
||||
cancel_url=cancel_url)
|
||||
|
||||
|
||||
async def render_ticket_type_add_button(entry, calendar, day, month, year) -> str:
|
||||
def render_ticket_type_add_button(entry, calendar, day, month, year) -> str:
|
||||
"""Render ticket type add button (replaces _types/ticket_types/_add_button.html)."""
|
||||
from quart import url_for, g
|
||||
|
||||
@@ -719,5 +719,5 @@ async def render_ticket_type_add_button(entry, calendar, day, month, year) -> st
|
||||
calendar_slug=cal_slug, entry_id=entry.id,
|
||||
year=year, month=month, day=day)
|
||||
|
||||
return await render_to_sx("events-ticket-type-add-button",
|
||||
return sx_call("events-ticket-type-add-button",
|
||||
action_btn=action_btn, add_url=add_url)
|
||||
|
||||
Reference in New Issue
Block a user