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>
91 lines
3.0 KiB
Python
91 lines
3.0 KiB
Python
from __future__ import annotations
|
|
|
|
from types import SimpleNamespace
|
|
|
|
from quart import (
|
|
render_template, make_response, Blueprint, g, request
|
|
)
|
|
|
|
from shared.infrastructure.data_client import fetch_data
|
|
from shared.infrastructure.actions import call_action
|
|
from shared.browser.app.authz import require_admin
|
|
from shared.browser.app.utils.htmx import is_htmx_request
|
|
|
|
|
|
def register():
|
|
bp = Blueprint("payments", __name__, url_prefix='/payments')
|
|
|
|
@bp.context_processor
|
|
async def inject_root():
|
|
return {}
|
|
|
|
async def _load_payment_ctx():
|
|
"""Load PageConfig SumUp data for the current page (from blog)."""
|
|
post = (getattr(g, "post_data", None) or {}).get("post", {})
|
|
post_id = post.get("id")
|
|
if not post_id:
|
|
return {}
|
|
|
|
raw_pc = await fetch_data(
|
|
"blog", "page-config",
|
|
params={"container_type": "page", "container_id": post_id},
|
|
required=False,
|
|
)
|
|
pc = SimpleNamespace(**raw_pc) if raw_pc else None
|
|
|
|
return {
|
|
"sumup_configured": bool(pc and getattr(pc, "sumup_api_key", None)),
|
|
"sumup_merchant_code": (getattr(pc, "sumup_merchant_code", None) or "") if pc else "",
|
|
"sumup_checkout_prefix": (getattr(pc, "sumup_checkout_prefix", None) or "") if pc else "",
|
|
}
|
|
|
|
@bp.get("/")
|
|
@require_admin
|
|
async def home(**kwargs):
|
|
pay_ctx = await _load_payment_ctx()
|
|
|
|
from shared.sexp.page import get_template_context
|
|
from sexp.sexp_components import render_payments_page, render_payments_oob
|
|
|
|
ctx = await get_template_context()
|
|
ctx.update(pay_ctx)
|
|
if not is_htmx_request():
|
|
html = await render_payments_page(ctx)
|
|
else:
|
|
html = await render_payments_oob(ctx)
|
|
return await make_response(html)
|
|
|
|
@bp.put("/")
|
|
@require_admin
|
|
async def update_sumup(**kwargs):
|
|
"""Update SumUp credentials for this page (writes to blog's db_blog)."""
|
|
post = (getattr(g, "post_data", None) or {}).get("post", {})
|
|
post_id = post.get("id")
|
|
if not post_id:
|
|
return await make_response("Post not found", 404)
|
|
|
|
form = await request.form
|
|
merchant_code = (form.get("merchant_code") or "").strip()
|
|
api_key = (form.get("api_key") or "").strip()
|
|
checkout_prefix = (form.get("checkout_prefix") or "").strip()
|
|
|
|
payload = {
|
|
"container_type": "page",
|
|
"container_id": post_id,
|
|
"sumup_merchant_code": merchant_code,
|
|
"sumup_checkout_prefix": checkout_prefix,
|
|
}
|
|
if api_key:
|
|
payload["sumup_api_key"] = api_key
|
|
|
|
await call_action("blog", "update-page-config", payload=payload)
|
|
|
|
from shared.sexp.page import get_template_context
|
|
from sexp.sexp_components import render_payments_panel
|
|
ctx = await get_template_context()
|
|
ctx.update(await _load_payment_ctx())
|
|
html = render_payments_panel(ctx)
|
|
return await make_response(html)
|
|
|
|
return bp
|