Some checks failed
Build and Deploy / build-and-deploy (push) Failing after 16s
Defpages are now declared with absolute paths in .sx files and auto-mounted directly on the Quart app, removing ~850 lines of blueprint mount_pages calls, before_request hooks, and g.* wrapper boilerplate. A new page = one defpage declaration, nothing else. Infrastructure: - async_eval awaits coroutine results from callable dispatch - auto_mount_pages() mounts all registered defpages on the app - g._defpage_ctx pattern passes helper data to layout context Migrated: sx, account, orders, federation, cart, market, events, blog Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
138 lines
5.0 KiB
Python
138 lines
5.0 KiB
Python
"""Cart defpage setup — registers layouts, page helpers, and loads .sx pages."""
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
def setup_cart_pages() -> None:
|
|
"""Register cart-specific layouts, page helpers, and load page definitions."""
|
|
_register_cart_layouts()
|
|
_register_cart_helpers()
|
|
_load_cart_page_files()
|
|
|
|
|
|
def _load_cart_page_files() -> None:
|
|
import os
|
|
from shared.sx.pages import load_page_dir
|
|
load_page_dir(os.path.dirname(__file__), "cart")
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Layouts
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _register_cart_layouts() -> None:
|
|
from shared.sx.layouts import register_custom_layout
|
|
register_custom_layout("cart-page", _cart_page_full, _cart_page_oob)
|
|
register_custom_layout("cart-admin", _cart_admin_full, _cart_admin_oob)
|
|
|
|
|
|
def _cart_page_full(ctx: dict, **kw: Any) -> str:
|
|
from shared.sx.helpers import root_header_sx, sx_call, SxExpr
|
|
from sx.sx_components import _cart_header_sx, _page_cart_header_sx
|
|
|
|
page_post = ctx.get("page_post")
|
|
root_hdr = root_header_sx(ctx)
|
|
child = _cart_header_sx(ctx)
|
|
page_hdr = _page_cart_header_sx(ctx, page_post)
|
|
nested = sx_call(
|
|
"header-child-sx",
|
|
inner=SxExpr("(<> " + child + " " + sx_call("header-child-sx", id="cart-header-child", inner=SxExpr(page_hdr)) + ")"),
|
|
)
|
|
return "(<> " + root_hdr + " " + nested + ")"
|
|
|
|
|
|
def _cart_page_oob(ctx: dict, **kw: Any) -> str:
|
|
from shared.sx.helpers import root_header_sx, sx_call, SxExpr
|
|
from sx.sx_components import _cart_header_sx, _page_cart_header_sx
|
|
|
|
page_post = ctx.get("page_post")
|
|
child_oob = sx_call("oob-header-sx",
|
|
parent_id="cart-header-child",
|
|
row=SxExpr(_page_cart_header_sx(ctx, page_post)))
|
|
cart_hdr_oob = _cart_header_sx(ctx, oob=True)
|
|
root_hdr_oob = root_header_sx(ctx, oob=True)
|
|
return "(<> " + child_oob + " " + cart_hdr_oob + " " + root_hdr_oob + ")"
|
|
|
|
|
|
async def _cart_admin_full(ctx: dict, **kw: Any) -> str:
|
|
from shared.sx.helpers import root_header_sx
|
|
from sx.sx_components import _post_header_sx, _cart_page_admin_header_sx
|
|
|
|
page_post = ctx.get("page_post")
|
|
selected = kw.get("selected", "")
|
|
root_hdr = root_header_sx(ctx)
|
|
post_hdr = await _post_header_sx(ctx, page_post)
|
|
admin_hdr = _cart_page_admin_header_sx(ctx, page_post, selected=selected)
|
|
return "(<> " + root_hdr + " " + post_hdr + " " + admin_hdr + ")"
|
|
|
|
|
|
async def _cart_admin_oob(ctx: dict, **kw: Any) -> str:
|
|
from sx.sx_components import _cart_page_admin_header_sx
|
|
|
|
page_post = ctx.get("page_post")
|
|
selected = kw.get("selected", "")
|
|
return _cart_page_admin_header_sx(ctx, page_post, oob=True, selected=selected)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Page helpers
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _register_cart_helpers() -> None:
|
|
from shared.sx.pages import register_page_helpers
|
|
|
|
register_page_helpers("cart", {
|
|
"overview-content": _h_overview_content,
|
|
"page-cart-content": _h_page_cart_content,
|
|
"cart-admin-content": _h_cart_admin_content,
|
|
"cart-payments-content": _h_cart_payments_content,
|
|
})
|
|
|
|
|
|
async def _h_overview_content(**kw):
|
|
from quart import g
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _overview_main_panel_sx
|
|
from bp.cart.services import get_cart_grouped_by_page
|
|
page_groups = await get_cart_grouped_by_page(g.s)
|
|
ctx = await get_template_context()
|
|
return _overview_main_panel_sx(page_groups, ctx)
|
|
|
|
|
|
async def _h_page_cart_content(page_slug=None, **kw):
|
|
from quart import g
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _page_cart_main_panel_sx
|
|
from bp.cart.services import total, calendar_total, ticket_total
|
|
from bp.cart.services.page_cart import (
|
|
get_cart_for_page, get_calendar_entries_for_page, get_tickets_for_page,
|
|
)
|
|
from bp.cart.services.ticket_groups import group_tickets
|
|
|
|
post = g.page_post
|
|
cart = await get_cart_for_page(g.s, post.id)
|
|
cal_entries = await get_calendar_entries_for_page(g.s, post.id)
|
|
page_tickets = await get_tickets_for_page(g.s, post.id)
|
|
ticket_groups = group_tickets(page_tickets)
|
|
|
|
ctx = await get_template_context()
|
|
return _page_cart_main_panel_sx(
|
|
ctx, cart, cal_entries, page_tickets, ticket_groups,
|
|
total, calendar_total, ticket_total,
|
|
)
|
|
|
|
|
|
async def _h_cart_admin_content(page_slug=None, **kw):
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _cart_admin_main_panel_sx
|
|
ctx = await get_template_context()
|
|
return _cart_admin_main_panel_sx(ctx)
|
|
|
|
|
|
async def _h_cart_payments_content(page_slug=None, **kw):
|
|
from shared.sx.page import get_template_context
|
|
from sx.sx_components import _cart_payments_main_panel_sx
|
|
ctx = await get_template_context()
|
|
return _cart_payments_main_panel_sx(ctx)
|