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 decimal import Decimal
|
||||
from pathlib import Path
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from quart import Blueprint, g, request, render_template, redirect, url_for, make_response
|
||||
from quart import Blueprint, g, request, redirect, url_for, make_response
|
||||
from sqlalchemy import select
|
||||
|
||||
from shared.models.market import CartItem
|
||||
@@ -150,11 +150,10 @@ def register(url_prefix: str) -> Blueprint:
|
||||
try:
|
||||
page_config = await resolve_page_config(g.s, cart, calendar_entries, tickets)
|
||||
except ValueError as e:
|
||||
html = await render_template(
|
||||
"_types/cart/checkout_error.html",
|
||||
order=None,
|
||||
error=str(e),
|
||||
)
|
||||
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=str(e))
|
||||
return await make_response(html, 400)
|
||||
|
||||
ident = current_cart_identity()
|
||||
@@ -208,11 +207,10 @@ def register(url_prefix: str) -> Blueprint:
|
||||
hosted_url = result.get("sumup_hosted_url")
|
||||
|
||||
if not hosted_url:
|
||||
html = await render_template(
|
||||
"_types/cart/checkout_error.html",
|
||||
order=None,
|
||||
error="No hosted checkout URL returned from SumUp.",
|
||||
)
|
||||
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.")
|
||||
return await make_response(html, 500)
|
||||
|
||||
return redirect(hosted_url)
|
||||
|
||||
@@ -15,7 +15,7 @@ def register(url_prefix: str) -> Blueprint:
|
||||
async def overview():
|
||||
from quart import g
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import render_overview_page, render_overview_oob
|
||||
from sexp.sexp_components import render_overview_page, render_overview_oob
|
||||
|
||||
page_groups = await get_cart_grouped_by_page(g.s)
|
||||
ctx = await get_template_context()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from quart import Blueprint, g, render_template, redirect, make_response, url_for
|
||||
from quart import Blueprint, g, redirect, make_response, url_for
|
||||
|
||||
from shared.browser.app.utils.htmx import is_htmx_request
|
||||
from shared.infrastructure.actions import call_action
|
||||
@@ -41,7 +41,7 @@ def register(url_prefix: str) -> Blueprint:
|
||||
)
|
||||
|
||||
from shared.sexp.page import get_template_context
|
||||
from sexp_components import render_page_cart_page, render_page_cart_oob
|
||||
from sexp.sexp_components import render_page_cart_page, render_page_cart_oob
|
||||
|
||||
ctx = await get_template_context()
|
||||
if not is_htmx_request():
|
||||
@@ -109,11 +109,10 @@ def register(url_prefix: str) -> Blueprint:
|
||||
hosted_url = result.get("sumup_hosted_url")
|
||||
|
||||
if not hosted_url:
|
||||
html = await render_template(
|
||||
"_types/cart/checkout_error.html",
|
||||
order=None,
|
||||
error="No hosted checkout URL returned from SumUp.",
|
||||
)
|
||||
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.")
|
||||
return await make_response(html, 500)
|
||||
|
||||
return redirect(hosted_url)
|
||||
|
||||
@@ -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, func, or_, cast, String, exists
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
@@ -56,7 +56,7 @@ def register() -> Blueprint:
|
||||
if not order:
|
||||
return await make_response("Order not found", 404)
|
||||
from shared.sexp.page import get_template_context
|
||||
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")
|
||||
@@ -120,11 +120,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)
|
||||
|
||||
@@ -137,7 +137,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
cart/sexp/__init__.py
Normal file
0
cart/sexp/__init__.py
Normal file
@@ -13,7 +13,7 @@ from shared.sexp.helpers import (
|
||||
call_url, root_header_html, search_desktop_html,
|
||||
search_mobile_html, full_page, oob_page,
|
||||
)
|
||||
from shared.infrastructure.urls import market_product_url
|
||||
from shared.infrastructure.urls import market_product_url, cart_url
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -34,7 +34,7 @@ def _cart_header_html(ctx: dict, *, oob: bool = False) -> str:
|
||||
def _page_cart_header_html(ctx: dict, page_post: Any, *, oob: bool = False) -> str:
|
||||
"""Build the per-page cart header row."""
|
||||
slug = page_post.slug if page_post else ""
|
||||
title = (page_post.title or "")[:160]
|
||||
title = ((page_post.title if page_post else None) or "")[:160]
|
||||
img_html = ""
|
||||
if page_post and page_post.feature_image:
|
||||
img_html = (
|
||||
@@ -803,3 +803,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=_cart_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