Migrate all apps to defpage declarative page routes
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m41s
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>
This commit is contained in:
@@ -219,7 +219,7 @@ async def execute_page(
|
||||
if page_def.menu_expr is not None:
|
||||
menu_sx = await _eval_slot(page_def.menu_expr, env, ctx, async_eval, async_eval_to_sx)
|
||||
|
||||
# Resolve layout → header rows
|
||||
# Resolve layout → header rows + mobile menu fallback
|
||||
tctx = await get_template_context()
|
||||
header_rows = ""
|
||||
oob_headers = ""
|
||||
@@ -261,6 +261,8 @@ async def execute_page(
|
||||
if layout is not None:
|
||||
header_rows = await layout.full_headers(tctx, **layout_kwargs)
|
||||
oob_headers = await layout.oob_headers(tctx, **layout_kwargs)
|
||||
if not menu_sx:
|
||||
menu_sx = await layout.mobile_menu(tctx, **layout_kwargs)
|
||||
|
||||
# Branch on request type
|
||||
is_htmx = is_htmx_request()
|
||||
@@ -288,17 +290,22 @@ async def execute_page(
|
||||
# Blueprint mounting
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def mount_pages(bp: Any, service_name: str) -> None:
|
||||
"""Mount all registered PageDef routes onto a Quart Blueprint.
|
||||
def mount_pages(bp: Any, service_name: str,
|
||||
names: set[str] | list[str] | None = None) -> None:
|
||||
"""Mount registered PageDef routes onto a Quart Blueprint.
|
||||
|
||||
For each PageDef, adds a GET route with appropriate auth/cache
|
||||
decorators. Coexists with existing Python routes on the same blueprint.
|
||||
|
||||
If *names* is given, only mount pages whose name is in the set.
|
||||
"""
|
||||
from quart import make_response
|
||||
|
||||
pages = get_all_pages(service_name)
|
||||
|
||||
for page_def in pages.values():
|
||||
if names is not None and page_def.name not in names:
|
||||
continue
|
||||
_mount_one_page(bp, service_name, page_def)
|
||||
|
||||
|
||||
@@ -347,6 +354,9 @@ def _apply_auth(fn: Any, auth: str | list) -> Any:
|
||||
if auth == "admin":
|
||||
from shared.browser.app.authz import require_admin
|
||||
return require_admin(fn)
|
||||
if auth == "post_author":
|
||||
from shared.browser.app.authz import require_post_author
|
||||
return require_post_author(fn)
|
||||
if isinstance(auth, list) and auth and auth[0] == "rights":
|
||||
from shared.browser.app.authz import require_rights
|
||||
return require_rights(*auth[1:])(fn)
|
||||
|
||||
Reference in New Issue
Block a user