All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m41s
Replace Python GET page handlers with declarative defpage definitions in .sx files across all 8 apps (sx docs, orders, account, market, cart, federation, events, blog). Each app now has sxc/pages/ with setup functions, layout registrations, page helpers, and .sx defpage declarations. Core infrastructure: add g I/O primitive, PageDef support for auth/layout/ data/content/filter/aside/menu slots, post_author auth level, and custom layout registration. Remove ~1400 lines of render_*_page/render_*_oob boilerplate. Update all endpoint references in routes, sx_components, and templates to defpage_* naming. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
from __future__ import annotations
|
|
|
|
from quart import (
|
|
make_response, Blueprint, g, request
|
|
)
|
|
|
|
from shared.infrastructure.actions import call_action
|
|
from shared.infrastructure.data_client import fetch_data
|
|
from shared.browser.app.authz import require_admin
|
|
from shared.sx.helpers import sx_response
|
|
|
|
|
|
def register():
|
|
bp = Blueprint("page_admin", __name__)
|
|
|
|
@bp.before_request
|
|
async def _prepare_page_data():
|
|
"""Pre-render admin content for defpage routes."""
|
|
endpoint = request.endpoint or ""
|
|
if request.method != "GET":
|
|
return
|
|
if endpoint.endswith("defpage_cart_admin"):
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _cart_admin_main_panel_sx
|
|
ctx = await get_template_context()
|
|
g.cart_admin_content = _cart_admin_main_panel_sx(ctx)
|
|
elif endpoint.endswith("defpage_cart_payments"):
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _cart_payments_main_panel_sx
|
|
ctx = await get_template_context()
|
|
g.cart_payments_content = _cart_payments_main_panel_sx(ctx)
|
|
|
|
@bp.put("/payments/")
|
|
@require_admin
|
|
async def update_sumup(**kwargs):
|
|
"""Update SumUp credentials for this page (writes to blog's db_blog)."""
|
|
page_post = getattr(g, "page_post", None)
|
|
if not page_post:
|
|
return await make_response("Page 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": page_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)
|
|
|
|
# Re-fetch page config to get fresh data
|
|
from types import SimpleNamespace
|
|
raw_pc = await fetch_data(
|
|
"blog", "page-config",
|
|
params={"container_type": "page", "container_id": page_post.id},
|
|
required=False,
|
|
)
|
|
g.page_config = SimpleNamespace(**raw_pc) if raw_pc else None
|
|
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import render_cart_payments_panel
|
|
ctx = await get_template_context()
|
|
html = render_cart_payments_panel(ctx)
|
|
return sx_response(html)
|
|
|
|
return bp
|