diff --git a/blog/sexp/sexp_components.py b/blog/sexp/sexp_components.py index 5593205..474897c 100644 --- a/blog/sexp/sexp_components.py +++ b/blog/sexp/sexp_components.py @@ -51,36 +51,8 @@ def _blog_header_html(ctx: dict, *, oob: bool = False) -> str: # --------------------------------------------------------------------------- def _post_header_html(ctx: dict, *, oob: bool = False) -> str: - """Build the post-level header row (blog-specific: container-nav wrapping + admin cog).""" - overrides: dict = {} - - # Blog wraps container_nav_html in border styling - container_nav = ctx.get("container_nav_html", "") - if container_nav: - overrides["container_nav_html"] = render("blog-container-nav", - container_nav_html=container_nav, - ) - - # Admin cog link - from quart import url_for as qurl, request - post = ctx.get("post") or {} - slug = post.get("slug", "") - rights = ctx.get("rights") or {} - has_admin = rights.get("admin") if isinstance(rights, dict) else getattr(rights, "admin", False) - if has_admin and slug: - select_colours = ctx.get("select_colours", "") - styles = ctx.get("styles") or {} - nav_btn = styles.get("nav_button", "") if isinstance(styles, dict) else getattr(styles, "nav_button", "") - admin_href = qurl("blog.post.admin.admin", slug=slug) - is_admin_page = "/admin" in request.path - overrides["post_admin_nav_html"] = render("nav-link", - href=admin_href, hx_select="#main-panel", icon="fa fa-cog", - aclass=f"{nav_btn} {select_colours}", - select_colours=select_colours, is_selected=is_admin_page, - ) - - effective_ctx = {**ctx, **overrides} if overrides else ctx - return _shared_post_header_html(effective_ctx, oob=oob) + """Build the post-level header row — delegates to shared helper.""" + return _shared_post_header_html(ctx, oob=oob) # --------------------------------------------------------------------------- diff --git a/cart/sexp/sexp_components.py b/cart/sexp/sexp_components.py index 823b212..5d1509f 100644 --- a/cart/sexp/sexp_components.py +++ b/cart/sexp/sexp_components.py @@ -39,9 +39,32 @@ def _ensure_post_ctx(ctx: dict, page_post: Any) -> dict: return ctx -def _post_header_html(ctx: dict, page_post: Any, *, oob: bool = False) -> str: +async def _ensure_container_nav(ctx: dict) -> dict: + """Fetch container_nav_html if not already present (for post header row).""" + if ctx.get("container_nav_html"): + return ctx + post = ctx.get("post") or {} + post_id = post.get("id") + slug = post.get("slug", "") + if not post_id: + return ctx + from shared.infrastructure.fragments import fetch_fragments + nav_params = { + "container_type": "page", + "container_id": str(post_id), + "post_slug": slug, + } + events_nav, market_nav = await fetch_fragments([ + ("events", "container-nav", nav_params), + ("market", "container-nav", nav_params), + ], required=False) + return {**ctx, "container_nav_html": events_nav + market_nav} + + +async def _post_header_html(ctx: dict, page_post: Any, *, oob: bool = False) -> str: """Build post-level header row from page_post DTO, using shared helper.""" ctx = _ensure_post_ctx(ctx, page_post) + ctx = await _ensure_container_nav(ctx) return _shared_post_header_html(ctx, oob=oob) @@ -794,7 +817,7 @@ async def render_cart_admin_page(ctx: dict, page_post: Any) -> str: """Full page: cart page admin overview.""" content = _cart_admin_main_panel_html(ctx) root_hdr = root_header_html(ctx) - post_hdr = _post_header_html(ctx, page_post) + post_hdr = await _post_header_html(ctx, page_post) admin_hdr = _cart_page_admin_header_html(ctx, page_post) return full_page(ctx, header_rows_html=root_hdr + post_hdr + admin_hdr, content_html=content) @@ -814,7 +837,7 @@ async def render_cart_payments_page(ctx: dict, page_post: Any) -> str: """Full page: payments config.""" content = _cart_payments_main_panel_html(ctx) root_hdr = root_header_html(ctx) - post_hdr = _post_header_html(ctx, page_post) + post_hdr = await _post_header_html(ctx, page_post) admin_hdr = _cart_page_admin_header_html(ctx, page_post, selected="payments") return full_page(ctx, header_rows_html=root_hdr + post_hdr + admin_hdr, content_html=content) diff --git a/events/sexp/sexp_components.py b/events/sexp/sexp_components.py index 6a2bb2f..bbc0749 100644 --- a/events/sexp/sexp_components.py +++ b/events/sexp/sexp_components.py @@ -37,10 +37,8 @@ _oob_header_html = oob_header_html # --------------------------------------------------------------------------- def _post_header_html(ctx: dict, *, oob: bool = False) -> str: - """Build the post-level header row (events-specific: calendar links + admin cog).""" - admin_nav = _post_nav_html(ctx) - effective_ctx = {**ctx, "post_admin_nav_html": admin_nav} if admin_nav else ctx - return _shared_post_header_html(effective_ctx, oob=oob) + """Build the post-level header row — delegates to shared helper.""" + return _shared_post_header_html(ctx, oob=oob) def _post_nav_html(ctx: dict) -> str: diff --git a/shared/sexp/helpers.py b/shared/sexp/helpers.py index 44a741b..56cda57 100644 --- a/shared/sexp/helpers.py +++ b/shared/sexp/helpers.py @@ -89,9 +89,31 @@ def post_header_html(ctx: dict, *, oob: bool = False) -> str: container_nav = ctx.get("container_nav_html", "") if container_nav: - nav_parts.append(container_nav) + nav_parts.append( + '
' + ) + # Admin cog — external link to blog admin (generic across all services) admin_nav = ctx.get("post_admin_nav_html", "") + if not admin_nav: + rights = ctx.get("rights") or {} + has_admin = rights.get("admin") if isinstance(rights, dict) else getattr(rights, "admin", False) + if has_admin and slug: + from quart import request + admin_href = call_url(ctx, "blog_url", f"/{slug}/admin/") + is_admin_page = "/admin" in request.path + sel_cls = "!bg-stone-500 !text-white" if is_admin_page else "" + base_cls = ("justify-center cursor-pointer flex flex-row" + " items-center gap-2 rounded bg-stone-200 text-black p-3") + admin_nav = ( + f'