Delete orders + federation sx_components.py — rendering inlined to routes
Phase 2 (Orders): - Checkout error/return renders moved directly into route handlers - Removed orphaned test_sx_helpers.py Phase 3 (Federation): - Auth pages use _render_social_auth_page() helper in routes - Choose-username render inlined into identity routes - Timeline/search/follow/interaction renders inlined into social routes using serializers imported from sxc.pages - Added _social_page() to sxc/pages/__init__.py for shared use - Home page renders inline in app.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,118 @@ from services.checkout import validate_webhook_secret, get_order_with_details
|
||||
from services.check_sumup_status import check_sumup_status
|
||||
|
||||
|
||||
async def _render_checkout_return(ctx: dict, order=None, status: str = "",
|
||||
calendar_entries=None, order_tickets=None) -> str:
|
||||
"""Render checkout return page — replaces sx_components helper."""
|
||||
from shared.sx.helpers import (
|
||||
render_to_sx, root_header_sx, header_child_sx, full_page_sx, call_url,
|
||||
)
|
||||
from shared.sx.parser import SxExpr
|
||||
from shared.infrastructure.urls import market_product_url
|
||||
|
||||
filt = await render_to_sx("checkout-return-header", status=status)
|
||||
|
||||
if not order:
|
||||
content = await render_to_sx("checkout-return-missing")
|
||||
else:
|
||||
summary = await render_to_sx("order-summary-card",
|
||||
order_id=order.id,
|
||||
created_at=order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else None,
|
||||
description=order.description, status=order.status,
|
||||
currency=order.currency,
|
||||
total_amount=f"{order.total_amount:.2f}" if order.total_amount else None,
|
||||
)
|
||||
|
||||
items = ""
|
||||
if order.items:
|
||||
item_parts = []
|
||||
for item in order.items:
|
||||
product_url = market_product_url(item.product_slug)
|
||||
if item.product_image:
|
||||
img = await render_to_sx("order-item-image",
|
||||
src=item.product_image,
|
||||
alt=item.product_title or "Product image")
|
||||
else:
|
||||
img = await render_to_sx("order-item-no-image")
|
||||
item_parts.append(await render_to_sx("order-item-row",
|
||||
href=product_url, img=SxExpr(img),
|
||||
title=item.product_title or "Unknown product",
|
||||
pid=f"Product ID: {item.product_id}",
|
||||
qty=f"Qty: {item.quantity}",
|
||||
price=f"{item.currency or order.currency or 'GBP'} {item.unit_price or 0:.2f}",
|
||||
))
|
||||
items = await render_to_sx("order-items-panel",
|
||||
items=SxExpr("(<> " + " ".join(item_parts) + ")"))
|
||||
|
||||
calendar = ""
|
||||
if calendar_entries:
|
||||
cal_parts = []
|
||||
for e in calendar_entries:
|
||||
st = e.state or ""
|
||||
pill = (
|
||||
"bg-emerald-100 text-emerald-800" if st == "confirmed"
|
||||
else "bg-amber-100 text-amber-800" if st == "provisional"
|
||||
else "bg-blue-100 text-blue-800" if st == "ordered"
|
||||
else "bg-stone-100 text-stone-700"
|
||||
)
|
||||
ds = e.start_at.strftime("%-d %b %Y, %H:%M") if e.start_at else ""
|
||||
if e.end_at:
|
||||
ds += f" \u2013 {e.end_at.strftime('%-d %b %Y, %H:%M')}"
|
||||
cal_parts.append(await render_to_sx("order-calendar-entry",
|
||||
name=e.name,
|
||||
pill=f"inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium {pill}",
|
||||
status=st.capitalize(), date_str=ds,
|
||||
cost=f"\u00a3{e.cost or 0:.2f}",
|
||||
))
|
||||
calendar = await render_to_sx("order-calendar-section",
|
||||
items=SxExpr("(<> " + " ".join(cal_parts) + ")"))
|
||||
|
||||
tickets = ""
|
||||
if order_tickets:
|
||||
tk_parts = []
|
||||
for tk in order_tickets:
|
||||
st = tk.state or ""
|
||||
pill = (
|
||||
"bg-emerald-100 text-emerald-800" if st == "confirmed"
|
||||
else "bg-amber-100 text-amber-800" if st == "reserved"
|
||||
else "bg-blue-100 text-blue-800" if st == "checked_in"
|
||||
else "bg-stone-100 text-stone-700"
|
||||
)
|
||||
pill_cls = f"inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium {pill}"
|
||||
ds = tk.entry_start_at.strftime("%-d %b %Y, %H:%M") if tk.entry_start_at else ""
|
||||
if tk.entry_end_at:
|
||||
ds += f" \u2013 {tk.entry_end_at.strftime('%-d %b %Y, %H:%M')}"
|
||||
tk_parts.append(await render_to_sx("checkout-return-ticket",
|
||||
name=tk.entry_name, pill=pill_cls,
|
||||
state=st.replace("_", " ").capitalize(),
|
||||
type_name=tk.ticket_type_name or None,
|
||||
date_str=ds, code=tk.code,
|
||||
price=f"\u00a3{tk.price or 0:.2f}",
|
||||
))
|
||||
tickets = await render_to_sx("checkout-return-tickets",
|
||||
items=SxExpr("(<> " + " ".join(tk_parts) + ")"))
|
||||
|
||||
status_msg = ""
|
||||
if order.status == "failed":
|
||||
status_msg = await render_to_sx("checkout-return-failed", order_id=order.id)
|
||||
elif order.status == "paid":
|
||||
status_msg = await render_to_sx("checkout-return-paid")
|
||||
|
||||
content = await render_to_sx("checkout-return-content",
|
||||
summary=SxExpr(summary),
|
||||
items=SxExpr(items) if items else None,
|
||||
calendar=SxExpr(calendar) if calendar else None,
|
||||
tickets=SxExpr(tickets) if tickets else None,
|
||||
status_message=SxExpr(status_msg) if status_msg else None,
|
||||
)
|
||||
|
||||
account_url = call_url(ctx, "account_url", "")
|
||||
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
|
||||
hdr = "(<> " + await root_header_sx(ctx) + " " + await header_child_sx(auth_hdr) + ")"
|
||||
|
||||
return await full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
|
||||
|
||||
def register() -> Blueprint:
|
||||
bp = Blueprint("checkout", __name__, url_prefix="/checkout")
|
||||
|
||||
@@ -47,12 +159,11 @@ def register() -> Blueprint:
|
||||
async def checkout_return(order_id: int):
|
||||
"""Handle the browser returning from SumUp after payment."""
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import render_checkout_return_page
|
||||
|
||||
order = await get_order_with_details(g.s, order_id)
|
||||
if not order:
|
||||
tctx = await get_template_context()
|
||||
html = await render_checkout_return_page(tctx, order=None, status="missing")
|
||||
html = await _render_checkout_return(tctx, order=None, status="missing")
|
||||
return await make_response(html)
|
||||
|
||||
if order.page_config_id:
|
||||
@@ -90,7 +201,7 @@ def register() -> Blueprint:
|
||||
await g.s.flush()
|
||||
|
||||
tctx = await get_template_context()
|
||||
html = await render_checkout_return_page(
|
||||
html = await _render_checkout_return(
|
||||
tctx, order=order, status=status,
|
||||
calendar_entries=calendar_entries,
|
||||
order_tickets=order_tickets,
|
||||
|
||||
@@ -70,9 +70,22 @@ def register() -> Blueprint:
|
||||
|
||||
if not hosted_url:
|
||||
from shared.sx.page import get_template_context
|
||||
from sx.sx_components import render_checkout_error_page
|
||||
from shared.sx.helpers import render_to_sx, root_header_sx, header_child_sx, full_page_sx, call_url
|
||||
from shared.sx.parser import SxExpr
|
||||
from shared.infrastructure.urls import cart_url
|
||||
tctx = await get_template_context()
|
||||
html = await render_checkout_error_page(tctx, error="No hosted checkout URL returned from SumUp when trying to reopen payment.", order=order)
|
||||
account_url = call_url(tctx, "account_url", "")
|
||||
auth_hdr = await render_to_sx("auth-header-row", account_url=account_url)
|
||||
hdr = "(<> " + await root_header_sx(tctx) + " " + await header_child_sx(auth_hdr) + ")"
|
||||
filt = await render_to_sx("checkout-error-header")
|
||||
order_sx = await render_to_sx("checkout-error-order-id", oid=f"#{order.id}")
|
||||
content = await render_to_sx(
|
||||
"checkout-error-content",
|
||||
msg="No hosted checkout URL returned from SumUp when trying to reopen payment.",
|
||||
order=SxExpr(order_sx),
|
||||
back_url=cart_url("/"),
|
||||
)
|
||||
html = await full_page_sx(tctx, header_rows=hdr, filter=filt, content=content)
|
||||
return await make_response(html, 500)
|
||||
|
||||
return redirect(hosted_url)
|
||||
|
||||
Reference in New Issue
Block a user