Phase 7: Replace render_template() with s-expression rendering in all POST/PUT/DELETE routes
Eliminates all render_template() calls from POST/PUT/DELETE handlers across all 7 services. Moves sexp_components.py into sexp/ packages per service. - Blog: like toggle, snippets, cache clear, features/sumup/entry panels, create/delete market, WYSIWYG editor panel (render_editor_panel) - Federation: like/unlike/boost/unboost, follow/unfollow, actor card, interaction buttons - Events: ticket widget, checkin, confirm/decline/provisional, tickets config, posts CRUD, description edit/save, calendar/slot/ticket_type CRUD, payments, buy tickets, day main panel, entry page - Market: like toggle, cart add response - Account: newsletter toggle - Cart: checkout error pages (3 handlers) - Orders: checkout error page (1 handler) Remaining render_template() calls are exclusively in GET handlers and internal services (email templates, fragment endpoints). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
import path_setup # noqa: F401 # adds shared/ to sys.path
|
||||
import sexp_components # noqa: F401 # ensure Hypercorn --reload watches this file
|
||||
import sexp.sexp_components as sexp_components # noqa: F401 # ensure Hypercorn --reload watches this file
|
||||
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
@@ -71,7 +71,7 @@ def create_app() -> "Quart":
|
||||
])
|
||||
|
||||
# Load orders-specific s-expression components
|
||||
from sexp_components import load_orders_components
|
||||
from sexp.sexp_components import load_orders_components
|
||||
load_orders_components()
|
||||
|
||||
app.register_blueprint(register_fragments())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from quart import Blueprint, g, render_template, redirect, url_for, make_response
|
||||
from quart import Blueprint, g, redirect, url_for, make_response
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
@@ -48,7 +48,7 @@ def register() -> Blueprint:
|
||||
if not order:
|
||||
return await make_response("Order not found", 404)
|
||||
|
||||
from sexp_components import render_order_page, render_order_oob
|
||||
from sexp.sexp_components import render_order_page, render_order_oob
|
||||
|
||||
ctx = await get_template_context()
|
||||
calendar_entries = ctx.get("calendar_entries")
|
||||
@@ -98,11 +98,10 @@ def register() -> Blueprint:
|
||||
await g.s.flush()
|
||||
|
||||
if not hosted_url:
|
||||
html = await render_template(
|
||||
"_types/cart/checkout_error.html",
|
||||
order=order,
|
||||
error="No hosted checkout URL returned from SumUp when trying to reopen payment.",
|
||||
)
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp.sexp_components import render_checkout_error_page
|
||||
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)
|
||||
return await make_response(html, 500)
|
||||
|
||||
return redirect(hosted_url)
|
||||
|
||||
@@ -117,7 +117,7 @@ def register(url_prefix: str) -> Blueprint:
|
||||
orders = result.scalars().all()
|
||||
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import (
|
||||
from sexp.sexp_components import (
|
||||
render_orders_page,
|
||||
render_orders_rows,
|
||||
render_orders_oob,
|
||||
|
||||
0
orders/sexp/__init__.py
Normal file
0
orders/sexp/__init__.py
Normal file
@@ -15,7 +15,7 @@ from shared.sexp.helpers import (
|
||||
search_mobile_html, search_desktop_html, full_page, oob_page,
|
||||
)
|
||||
from shared.sexp.page import HAMBURGER_HTML
|
||||
from shared.infrastructure.urls import market_product_url
|
||||
from shared.infrastructure.urls import market_product_url, cart_url
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -383,3 +383,56 @@ async def render_order_oob(ctx: dict, order: Any,
|
||||
)
|
||||
|
||||
return oob_page(ctx, oobs_html=oobs, filter_html=filt, content_html=main)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Public API: Checkout error
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _checkout_error_filter_html() -> str:
|
||||
return (
|
||||
'<header class="mb-6 sm:mb-8">'
|
||||
'<h1 class="text-xl sm:text-2xl md:text-3xl font-semibold tracking-tight">'
|
||||
'Checkout error</h1>'
|
||||
'<p class="text-xs sm:text-sm text-stone-600">'
|
||||
'We tried to start your payment with SumUp but hit a problem.</p>'
|
||||
'</header>'
|
||||
)
|
||||
|
||||
|
||||
def _checkout_error_content_html(error: str | None, order: Any | None) -> str:
|
||||
err_msg = error or "Unexpected error while creating the hosted checkout session."
|
||||
order_html = ""
|
||||
if order:
|
||||
order_html = (
|
||||
f'<p class="text-xs text-rose-800/80">'
|
||||
f'Order ID: <span class="font-mono">#{order.id}</span></p>'
|
||||
)
|
||||
back_url = cart_url("/")
|
||||
return (
|
||||
'<div class="max-w-full px-3 py-3 space-y-4">'
|
||||
'<div class="rounded-2xl border border-rose-200 bg-rose-50/80 p-4 sm:p-6 text-sm text-rose-900 space-y-2">'
|
||||
f'<p class="font-medium">Something went wrong.</p>'
|
||||
f'<p>{err_msg}</p>'
|
||||
f'{order_html}'
|
||||
'</div>'
|
||||
'<div>'
|
||||
f'<a href="{back_url}"'
|
||||
' class="inline-flex items-center px-3 py-2 text-xs sm:text-sm rounded-full border border-stone-300 bg-white hover:bg-stone-50 transition">'
|
||||
'<i class="fa fa-shopping-cart mr-2" aria-hidden="true"></i>'
|
||||
'Back to cart</a>'
|
||||
'</div>'
|
||||
'</div>'
|
||||
)
|
||||
|
||||
|
||||
async def render_checkout_error_page(ctx: dict, error: str | None = None, order: Any | None = None) -> str:
|
||||
"""Full page: checkout error."""
|
||||
hdr = root_header_html(ctx)
|
||||
hdr += sexp(
|
||||
'(div :id "root-header-child" :class "flex flex-col w-full items-center" (raw! c))',
|
||||
c=_auth_header_html(ctx),
|
||||
)
|
||||
filt = _checkout_error_filter_html()
|
||||
content = _checkout_error_content_html(error, order)
|
||||
return full_page(ctx, header_rows_html=hdr, filter_html=filt, content_html=content)
|
||||
Reference in New Issue
Block a user