Rebrand sexp → sx across web platform (173 files)
Rename all sexp directories, files, identifiers, and references to sx. artdag/ excluded (separate media processing DSL). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
0
orders/sx/__init__.py
Normal file
0
orders/sx/__init__.py
Normal file
38
orders/sx/checkout.sx
Normal file
38
orders/sx/checkout.sx
Normal file
@@ -0,0 +1,38 @@
|
||||
;; Checkout error components
|
||||
|
||||
(defcomp ~orders-checkout-error-header ()
|
||||
(header :class "mb-6 sm:mb-8"
|
||||
(h1 :class "text-xl sm:text-2xl md:text-3xl font-semibold tracking-tight" "Checkout error")
|
||||
(p :class "text-xs sm:text-sm text-stone-600" "We tried to start your payment with SumUp but hit a problem.")))
|
||||
|
||||
(defcomp ~orders-checkout-error-order-id (&key oid)
|
||||
(p :class "text-xs text-rose-800/80" "Order ID: " (span :class "font-mono" oid)))
|
||||
|
||||
(defcomp ~orders-checkout-error-pay-btn (&key url)
|
||||
(a :href url :class "inline-flex items-center px-3 py-2 text-xs sm:text-sm rounded-full border border-emerald-600 bg-emerald-600 text-white hover:bg-emerald-700 transition"
|
||||
(i :class "fa fa-credit-card mr-2" :aria-hidden "true") "Open payment page"))
|
||||
|
||||
(defcomp ~orders-checkout-error-content (&key msg order back-url)
|
||||
(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"
|
||||
(p :class "font-medium" "Something went wrong.")
|
||||
(p msg)
|
||||
order)
|
||||
(div
|
||||
(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") "Back to cart"))))
|
||||
|
||||
(defcomp ~orders-detail-filter (&key created status list-url recheck-url csrf pay)
|
||||
(header :class "mb-6 sm:mb-8 flex flex-col sm:flex-row sm:items-center justify-between gap-3 sm:gap-4"
|
||||
(div :class "space-y-1"
|
||||
(p :class "text-xs sm:text-sm text-stone-600" "Placed " created " \u00b7 Status: " status))
|
||||
(div :class "flex w-full sm:w-auto justify-start sm:justify-end gap-2"
|
||||
(a :href list-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-solid fa-list mr-2" :aria-hidden "true") "All orders")
|
||||
(form :method "post" :action recheck-url :class "inline"
|
||||
(input :type "hidden" :name "csrf_token" :value csrf)
|
||||
(button :type "submit"
|
||||
: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-solid fa-rotate mr-2" :aria-hidden "true") "Re-check status"))
|
||||
pay)))
|
||||
54
orders/sx/detail.sx
Normal file
54
orders/sx/detail.sx
Normal file
@@ -0,0 +1,54 @@
|
||||
;; Order detail components
|
||||
|
||||
(defcomp ~orders-item-image (&key src alt)
|
||||
(img :src src :alt alt :class "w-full h-full object-contain object-center" :loading "lazy" :decoding "async"))
|
||||
|
||||
(defcomp ~orders-item-no-image ()
|
||||
(div :class "w-full h-full flex items-center justify-center text-[9px] text-stone-400" "No image"))
|
||||
|
||||
(defcomp ~orders-item-row (&key href img title pid qty price)
|
||||
(li (a :class "w-full py-2 flex gap-3" :href href
|
||||
(div :class "w-12 h-12 sm:w-14 sm:h-14 rounded-md bg-stone-100 flex-shrink-0 overflow-hidden" img)
|
||||
(div :class "flex-1 flex justify-between gap-3"
|
||||
(div
|
||||
(p :class "font-medium" title)
|
||||
(p :class "text-[11px] text-stone-500" "Product ID: " pid))
|
||||
(div :class "text-right whitespace-nowrap"
|
||||
(p "Qty: " qty)
|
||||
(p price))))))
|
||||
|
||||
(defcomp ~orders-items-section (&key items)
|
||||
(div :class "rounded-2xl border border-stone-200 bg-white/80 p-4 sm:p-6"
|
||||
(h2 :class "text-sm sm:text-base font-semibold mb-3" "Items")
|
||||
(ul :class "divide-y divide-stone-100 text-xs sm:text-sm" items)))
|
||||
|
||||
(defcomp ~orders-calendar-item (&key name pill state ds cost)
|
||||
(li :class "px-4 py-3 flex items-start justify-between text-sm"
|
||||
(div
|
||||
(div :class "font-medium flex items-center gap-2"
|
||||
name
|
||||
(span :class pill state))
|
||||
(div :class "text-xs text-stone-500" ds))
|
||||
(div :class "ml-4 font-medium" cost)))
|
||||
|
||||
(defcomp ~orders-calendar-section (&key items)
|
||||
(section :class "mt-6 space-y-3"
|
||||
(h2 :class "text-base sm:text-lg font-semibold" "Calendar bookings in this order")
|
||||
(ul :class "divide-y divide-stone-200 rounded-2xl border border-stone-200 bg-white/80" items)))
|
||||
|
||||
(defcomp ~orders-detail-panel (&key summary items calendar)
|
||||
(div :class "max-w-full px-3 py-3 space-y-4"
|
||||
summary items calendar))
|
||||
|
||||
(defcomp ~orders-detail-header-stack (&key auth orders order)
|
||||
(div :id "root-header-child" :class "flex flex-col w-full items-center"
|
||||
auth
|
||||
(div :id "auth-header-child" :class "flex flex-col w-full items-center"
|
||||
orders
|
||||
(div :id "orders-header-child" :class "flex flex-col w-full items-center"
|
||||
order))))
|
||||
|
||||
(defcomp ~orders-header-child-oob (&key inner)
|
||||
(div :id "orders-header-child" :sx-swap-oob "outerHTML"
|
||||
:class "flex flex-col w-full items-center"
|
||||
inner))
|
||||
60
orders/sx/list.sx
Normal file
60
orders/sx/list.sx
Normal file
@@ -0,0 +1,60 @@
|
||||
;; Orders list components
|
||||
|
||||
(defcomp ~orders-row-desktop (&key oid created desc total pill status url)
|
||||
(tr :class "hidden sm:table-row border-t border-stone-100 hover:bg-stone-50/60"
|
||||
(td :class "px-3 py-2 align-top" (span :class "font-mono text-[11px] sm:text-xs" oid))
|
||||
(td :class "px-3 py-2 align-top text-stone-700 text-xs sm:text-sm" created)
|
||||
(td :class "px-3 py-2 align-top text-stone-700 text-xs sm:text-sm" desc)
|
||||
(td :class "px-3 py-2 align-top text-stone-700 text-xs sm:text-sm" total)
|
||||
(td :class "px-3 py-2 align-top" (span :class pill status))
|
||||
(td :class "px-3 py-0.5 align-top text-right"
|
||||
(a :href url :class "inline-flex items-center px-3 py-1.5 text-xs sm:text-sm rounded-full border border-stone-300 bg-white hover:bg-stone-50 transition" "View"))))
|
||||
|
||||
(defcomp ~orders-row-mobile (&key oid created total pill status url)
|
||||
(tr :class "sm:hidden border-t border-stone-100"
|
||||
(td :colspan "5" :class "px-3 py-3"
|
||||
(div :class "flex flex-col gap-2 text-xs"
|
||||
(div :class "flex items-center justify-between gap-2"
|
||||
(span :class "font-mono text-[11px] text-stone-700" oid)
|
||||
(span :class pill status))
|
||||
(div :class "text-[11px] text-stone-500 break-words" created)
|
||||
(div :class "flex items-center justify-between gap-2"
|
||||
(div :class "font-medium text-stone-800" total)
|
||||
(a :href url :class "inline-flex items-center px-2 py-1 text-[11px] rounded-full border border-stone-300 bg-white hover:bg-stone-50 transition shrink-0" "View"))))))
|
||||
|
||||
(defcomp ~orders-end-row ()
|
||||
(tr (td :colspan "5" :class "px-3 py-4 text-center text-xs text-stone-400" "End of results")))
|
||||
|
||||
(defcomp ~orders-empty-state ()
|
||||
(div :class "max-w-full px-3 py-3 space-y-3"
|
||||
(div :class "rounded-2xl border border-dashed border-stone-300 bg-white/80 p-4 sm:p-6 text-sm text-stone-700"
|
||||
"No orders yet.")))
|
||||
|
||||
(defcomp ~orders-table (&key rows)
|
||||
(div :class "max-w-full px-3 py-3 space-y-3"
|
||||
(div :class "overflow-x-auto rounded-2xl border border-stone-200 bg-white/80"
|
||||
(table :class "min-w-full text-xs sm:text-sm"
|
||||
(thead :class "bg-stone-50 border-b border-stone-200 text-stone-600"
|
||||
(tr
|
||||
(th :class "px-3 py-2 text-left font-medium" "Order")
|
||||
(th :class "px-3 py-2 text-left font-medium" "Created")
|
||||
(th :class "px-3 py-2 text-left font-medium" "Description")
|
||||
(th :class "px-3 py-2 text-left font-medium" "Total")
|
||||
(th :class "px-3 py-2 text-left font-medium" "Status")
|
||||
(th :class "px-3 py-2 text-left font-medium" "")))
|
||||
(tbody rows)))))
|
||||
|
||||
(defcomp ~orders-summary (&key search-mobile)
|
||||
(header :class "mb-6 sm:mb-8 flex flex-col sm:flex-row sm:items-center justify-between gap-3 sm:gap-4"
|
||||
(div :class "space-y-1" (p :class "text-xs sm:text-sm text-stone-600" "Recent orders placed via the checkout."))
|
||||
(div :class "md:hidden" search-mobile)))
|
||||
|
||||
;; Header child wrapper
|
||||
(defcomp ~orders-header-child (&key inner)
|
||||
(div :id "root-header-child" :class "flex flex-col w-full items-center"
|
||||
inner))
|
||||
|
||||
(defcomp ~orders-auth-header-child-oob (&key inner)
|
||||
(div :id "auth-header-child" :sx-swap-oob "outerHTML"
|
||||
:class "flex flex-col w-full items-center"
|
||||
inner))
|
||||
393
orders/sx/sx_components.py
Normal file
393
orders/sx/sx_components.py
Normal file
@@ -0,0 +1,393 @@
|
||||
"""
|
||||
Orders service s-expression page components.
|
||||
|
||||
Each function renders a complete page section (full page, OOB, or pagination)
|
||||
using shared s-expression components. Called from route handlers in place
|
||||
of ``render_template()``.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from shared.sx.jinja_bridge import load_service_components
|
||||
from shared.sx.helpers import (
|
||||
call_url, root_header_sx,
|
||||
full_page_sx, header_child_sx, oob_page_sx,
|
||||
sx_call, SxExpr,
|
||||
search_mobile_sx, search_desktop_sx,
|
||||
)
|
||||
from shared.infrastructure.urls import market_product_url, cart_url
|
||||
|
||||
# Load orders-specific .sx components at import time
|
||||
load_service_components(os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Header helpers (shared auth + orders-specific) — sx-native
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _auth_nav_sx(ctx: dict) -> str:
|
||||
"""Auth section desktop nav items as sx."""
|
||||
parts = [
|
||||
sx_call("nav-link",
|
||||
href=call_url(ctx, "account_url", "/newsletters/"),
|
||||
label="newsletters",
|
||||
select_colours=ctx.get("select_colours", ""),
|
||||
),
|
||||
]
|
||||
account_nav = ctx.get("account_nav")
|
||||
if account_nav:
|
||||
parts.append(str(account_nav))
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
|
||||
def _auth_header_sx(ctx: dict, *, oob: bool = False) -> str:
|
||||
"""Build the account section header row as sx."""
|
||||
return sx_call(
|
||||
"menu-row-sx",
|
||||
id="auth-row", level=1, colour="sky",
|
||||
link_href=call_url(ctx, "account_url", "/"),
|
||||
link_label="account", icon="fa-solid fa-user",
|
||||
nav=SxExpr(_auth_nav_sx(ctx)),
|
||||
child_id="auth-header-child", oob=oob,
|
||||
)
|
||||
|
||||
|
||||
def _orders_header_sx(ctx: dict, list_url: str) -> str:
|
||||
"""Build the orders section header row as sx."""
|
||||
return sx_call(
|
||||
"menu-row-sx",
|
||||
id="orders-row", level=2, colour="sky",
|
||||
link_href=list_url, link_label="Orders", icon="fa fa-gbp",
|
||||
child_id="orders-header-child",
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Orders list rendering
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _status_pill_cls(status: str) -> str:
|
||||
"""Return Tailwind classes for order status pill."""
|
||||
sl = status.lower()
|
||||
if sl == "paid":
|
||||
return "border-emerald-300 bg-emerald-50 text-emerald-700"
|
||||
if sl in ("failed", "cancelled"):
|
||||
return "border-rose-300 bg-rose-50 text-rose-700"
|
||||
return "border-stone-300 bg-stone-50 text-stone-700"
|
||||
|
||||
|
||||
def _order_row_data(order: Any, detail_url: str) -> dict:
|
||||
"""Extract display data from an order model object."""
|
||||
status = order.status or "pending"
|
||||
pill = _status_pill_cls(status)
|
||||
created = order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else "\u2014"
|
||||
total = f"{order.currency or 'GBP'} {order.total_amount or 0:.2f}"
|
||||
return dict(
|
||||
oid=f"#{order.id}", created=created,
|
||||
desc=order.description or "", total=total,
|
||||
pill_desktop=f"inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] sm:text-xs {pill}",
|
||||
pill_mobile=f"inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] {pill}",
|
||||
status=status, url=detail_url,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def _orders_rows_sx(orders: list, page: int, total_pages: int,
|
||||
url_for_fn: Any, qs_fn: Any) -> str:
|
||||
"""S-expression wire format for order rows (client renders)."""
|
||||
from shared.utils import route_prefix
|
||||
pfx = route_prefix()
|
||||
|
||||
parts = []
|
||||
for o in orders:
|
||||
d = _order_row_data(o, pfx + url_for_fn("orders.order.order_detail", order_id=o.id))
|
||||
parts.append(sx_call("orders-row-desktop",
|
||||
oid=d["oid"], created=d["created"],
|
||||
desc=d["desc"], total=d["total"],
|
||||
pill=d["pill_desktop"], status=d["status"],
|
||||
url=d["url"]))
|
||||
parts.append(sx_call("orders-row-mobile",
|
||||
oid=d["oid"], created=d["created"],
|
||||
total=d["total"], pill=d["pill_mobile"],
|
||||
status=d["status"], url=d["url"]))
|
||||
|
||||
if page < total_pages:
|
||||
next_url = pfx + url_for_fn("orders.list_orders") + qs_fn(page=page + 1)
|
||||
parts.append(sx_call("infinite-scroll",
|
||||
url=next_url, page=page,
|
||||
total_pages=total_pages,
|
||||
id_prefix="orders", colspan=5))
|
||||
else:
|
||||
parts.append(sx_call("orders-end-row"))
|
||||
|
||||
return "(<> " + " ".join(parts) + ")"
|
||||
|
||||
|
||||
def _orders_main_panel_sx(orders: list, rows_sx: str) -> str:
|
||||
"""Main panel with table or empty state (sx)."""
|
||||
if not orders:
|
||||
return sx_call("orders-empty-state")
|
||||
return sx_call("orders-table", rows=SxExpr(rows_sx))
|
||||
|
||||
|
||||
def _orders_summary_sx(ctx: dict) -> str:
|
||||
"""Filter section for orders list (sx)."""
|
||||
return sx_call("orders-summary", search_mobile=SxExpr(search_mobile_sx(ctx)))
|
||||
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Public API: orders list
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
async def render_orders_page(ctx: dict, orders: list, page: int,
|
||||
total_pages: int, search: str | None,
|
||||
search_count: int, url_for_fn: Any,
|
||||
qs_fn: Any) -> str:
|
||||
"""Full page: orders list (sx wire format)."""
|
||||
from shared.utils import route_prefix
|
||||
|
||||
ctx["search"] = search
|
||||
ctx["search_count"] = search_count
|
||||
list_url = route_prefix() + url_for_fn("orders.list_orders")
|
||||
|
||||
rows = _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
|
||||
main = _orders_main_panel_sx(orders, rows)
|
||||
|
||||
hdr = root_header_sx(ctx)
|
||||
inner = "(<> " + _auth_header_sx(ctx) + " " + _orders_header_sx(ctx, list_url) + ")"
|
||||
hdr = "(<> " + hdr + " " + header_child_sx(inner) + ")"
|
||||
|
||||
return full_page_sx(ctx, header_rows=hdr,
|
||||
filter=_orders_summary_sx(ctx),
|
||||
aside=search_desktop_sx(ctx),
|
||||
content=main)
|
||||
|
||||
|
||||
async def render_orders_rows(ctx: dict, orders: list, page: int,
|
||||
total_pages: int, url_for_fn: Any,
|
||||
qs_fn: Any) -> str:
|
||||
"""Pagination: just the table rows (sx wire format)."""
|
||||
return _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
|
||||
|
||||
|
||||
|
||||
async def render_orders_oob(ctx: dict, orders: list, page: int,
|
||||
total_pages: int, search: str | None,
|
||||
search_count: int, url_for_fn: Any,
|
||||
qs_fn: Any) -> str:
|
||||
"""OOB response for HTMX navigation to orders list (sx)."""
|
||||
from shared.utils import route_prefix
|
||||
|
||||
ctx["search"] = search
|
||||
ctx["search_count"] = search_count
|
||||
list_url = route_prefix() + url_for_fn("orders.list_orders")
|
||||
|
||||
rows = _orders_rows_sx(orders, page, total_pages, url_for_fn, qs_fn)
|
||||
main = _orders_main_panel_sx(orders, rows)
|
||||
|
||||
auth_hdr = _auth_header_sx(ctx, oob=True)
|
||||
auth_child_oob = sx_call("orders-auth-header-child-oob",
|
||||
inner=SxExpr(_orders_header_sx(ctx, list_url)))
|
||||
root_hdr = root_header_sx(ctx, oob=True)
|
||||
oobs = "(<> " + auth_hdr + " " + auth_child_oob + " " + root_hdr + ")"
|
||||
|
||||
return oob_page_sx(oobs=oobs,
|
||||
filter=_orders_summary_sx(ctx),
|
||||
aside=search_desktop_sx(ctx),
|
||||
content=main)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Single order detail
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _order_items_sx(order: Any) -> str:
|
||||
"""Render order items list as sx."""
|
||||
if not order or not order.items:
|
||||
return ""
|
||||
items = []
|
||||
for item in order.items:
|
||||
prod_url = market_product_url(item.product_slug)
|
||||
if item.product_image:
|
||||
img = sx_call(
|
||||
"orders-item-image",
|
||||
src=item.product_image, alt=item.product_title or "Product image",
|
||||
)
|
||||
else:
|
||||
img = sx_call("orders-item-no-image")
|
||||
|
||||
items.append(sx_call(
|
||||
"orders-item-row",
|
||||
href=prod_url, img=SxExpr(img),
|
||||
title=item.product_title or "Unknown product",
|
||||
pid=str(item.product_id),
|
||||
qty=str(item.quantity),
|
||||
price=f"{item.currency or order.currency or 'GBP'} {item.unit_price or 0:.2f}",
|
||||
))
|
||||
|
||||
items_sx = "(<> " + " ".join(items) + ")"
|
||||
return sx_call("orders-items-section", items=SxExpr(items_sx))
|
||||
|
||||
|
||||
def _calendar_items_sx(calendar_entries: list | None) -> str:
|
||||
"""Render calendar bookings for an order as sx."""
|
||||
if not calendar_entries:
|
||||
return ""
|
||||
items = []
|
||||
for e in calendar_entries:
|
||||
st = e.state or ""
|
||||
pill = (
|
||||
"bg-emerald-100 text-emerald-800" if st == "confirmed"
|
||||
else "bg-amber-100 text-amber-800" if st == "provisional"
|
||||
else "bg-blue-100 text-blue-800" if st == "ordered"
|
||||
else "bg-stone-100 text-stone-700"
|
||||
)
|
||||
ds = e.start_at.strftime("%-d %b %Y, %H:%M") if e.start_at else ""
|
||||
if e.end_at:
|
||||
ds += f" \u2013 {e.end_at.strftime('%-d %b %Y, %H:%M')}"
|
||||
items.append(sx_call(
|
||||
"orders-calendar-item",
|
||||
name=e.name,
|
||||
pill=f"inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium {pill}",
|
||||
state=st.capitalize(), ds=ds,
|
||||
cost=f"\u00a3{e.cost or 0:.2f}",
|
||||
))
|
||||
|
||||
items_sx = "(<> " + " ".join(items) + ")"
|
||||
return sx_call("orders-calendar-section", items=SxExpr(items_sx))
|
||||
|
||||
|
||||
def _order_main_sx(order: Any, calendar_entries: list | None) -> str:
|
||||
"""Main panel for single order detail (sx)."""
|
||||
summary = sx_call(
|
||||
"order-summary-card",
|
||||
order_id=order.id,
|
||||
created_at=order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else None,
|
||||
description=order.description, status=order.status, currency=order.currency,
|
||||
total_amount=f"{order.total_amount:.2f}" if order.total_amount else None,
|
||||
)
|
||||
items = _order_items_sx(order)
|
||||
calendar = _calendar_items_sx(calendar_entries)
|
||||
return sx_call(
|
||||
"orders-detail-panel",
|
||||
summary=SxExpr(summary),
|
||||
items=SxExpr(items) if items else None,
|
||||
calendar=SxExpr(calendar) if calendar else None,
|
||||
)
|
||||
|
||||
|
||||
def _order_filter_sx(order: Any, list_url: str, recheck_url: str,
|
||||
pay_url: str, csrf_token: str) -> str:
|
||||
"""Filter section for single order detail (sx)."""
|
||||
created = order.created_at.strftime("%-d %b %Y, %H:%M") if order.created_at else "\u2014"
|
||||
status = order.status or "pending"
|
||||
|
||||
pay = ""
|
||||
if status != "paid":
|
||||
pay = sx_call("orders-checkout-error-pay-btn", url=pay_url)
|
||||
|
||||
return sx_call(
|
||||
"orders-detail-filter",
|
||||
created=created, status=status,
|
||||
list_url=list_url, recheck_url=recheck_url,
|
||||
csrf=csrf_token,
|
||||
pay=SxExpr(pay) if pay else None,
|
||||
)
|
||||
|
||||
|
||||
async def render_order_page(ctx: dict, order: Any,
|
||||
calendar_entries: list | None,
|
||||
url_for_fn: Any) -> str:
|
||||
"""Full page: single order detail (sx wire format)."""
|
||||
from shared.utils import route_prefix
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
|
||||
pfx = route_prefix()
|
||||
detail_url = pfx + url_for_fn("orders.order.order_detail", order_id=order.id)
|
||||
list_url = pfx + url_for_fn("orders.list_orders")
|
||||
recheck_url = pfx + url_for_fn("orders.order.order_recheck", order_id=order.id)
|
||||
pay_url = pfx + url_for_fn("orders.order.order_pay", order_id=order.id)
|
||||
|
||||
main = _order_main_sx(order, calendar_entries)
|
||||
filt = _order_filter_sx(order, list_url, recheck_url, pay_url, generate_csrf_token())
|
||||
|
||||
# Header stack: root -> auth -> orders -> order
|
||||
hdr = root_header_sx(ctx)
|
||||
order_row = sx_call(
|
||||
"menu-row-sx",
|
||||
id="order-row", level=3, colour="sky", link_href=detail_url,
|
||||
link_label="Order", icon="fa fa-gbp",
|
||||
)
|
||||
detail_header = sx_call(
|
||||
"orders-detail-header-stack",
|
||||
auth=SxExpr(_auth_header_sx(ctx)),
|
||||
orders=SxExpr(_orders_header_sx(ctx, list_url)),
|
||||
order=SxExpr(order_row),
|
||||
)
|
||||
hdr = "(<> " + hdr + " " + detail_header + ")"
|
||||
|
||||
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=main)
|
||||
|
||||
|
||||
async def render_order_oob(ctx: dict, order: Any,
|
||||
calendar_entries: list | None,
|
||||
url_for_fn: Any) -> str:
|
||||
"""OOB response for single order detail (sx)."""
|
||||
from shared.utils import route_prefix
|
||||
from shared.browser.app.csrf import generate_csrf_token
|
||||
|
||||
pfx = route_prefix()
|
||||
detail_url = pfx + url_for_fn("orders.order.order_detail", order_id=order.id)
|
||||
list_url = pfx + url_for_fn("orders.list_orders")
|
||||
recheck_url = pfx + url_for_fn("orders.order.order_recheck", order_id=order.id)
|
||||
pay_url = pfx + url_for_fn("orders.order.order_pay", order_id=order.id)
|
||||
|
||||
main = _order_main_sx(order, calendar_entries)
|
||||
filt = _order_filter_sx(order, list_url, recheck_url, pay_url, generate_csrf_token())
|
||||
|
||||
order_row_oob = sx_call(
|
||||
"menu-row-sx",
|
||||
id="order-row", level=3, colour="sky", link_href=detail_url,
|
||||
link_label="Order", icon="fa fa-gbp", oob=True,
|
||||
)
|
||||
header_child_oob = sx_call("orders-header-child-oob",
|
||||
inner=SxExpr(order_row_oob))
|
||||
root_hdr = root_header_sx(ctx, oob=True)
|
||||
oobs = "(<> " + header_child_oob + " " + root_hdr + ")"
|
||||
|
||||
return oob_page_sx(oobs=oobs, filter=filt, content=main)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Public API: Checkout error
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def _checkout_error_filter_sx() -> str:
|
||||
return sx_call("orders-checkout-error-header")
|
||||
|
||||
|
||||
def _checkout_error_content_sx(error: str | None, order: Any | None) -> str:
|
||||
err_msg = error or "Unexpected error while creating the hosted checkout session."
|
||||
order_sx = ""
|
||||
if order:
|
||||
order_sx = sx_call("orders-checkout-error-order-id", oid=f"#{order.id}")
|
||||
back_url = cart_url("/")
|
||||
return sx_call(
|
||||
"orders-checkout-error-content",
|
||||
msg=err_msg,
|
||||
order=SxExpr(order_sx) if order_sx else None,
|
||||
back_url=back_url,
|
||||
)
|
||||
|
||||
|
||||
async def render_checkout_error_page(ctx: dict, error: str | None = None, order: Any | None = None) -> str:
|
||||
"""Full page: checkout error (sx wire format)."""
|
||||
hdr = root_header_sx(ctx)
|
||||
inner = _auth_header_sx(ctx)
|
||||
hdr = "(<> " + hdr + " " + header_child_sx(inner) + ")"
|
||||
filt = _checkout_error_filter_sx()
|
||||
content = _checkout_error_content_sx(error, order)
|
||||
return full_page_sx(ctx, header_rows=hdr, filter=filt, content=content)
|
||||
Reference in New Issue
Block a user