Make post header row generic: admin cog + container_nav in shared helper

Move admin cog generation and container_nav border wrapping from
blog-specific wrapper into shared post_header_html so all services
render identical post header rows. Blog, events, cart all delegate
to the shared helper now. Cart admin pages fetch container_nav_html
via fragments. Village Hall always links to blog.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-28 22:37:24 +00:00
parent 2e4fbd5777
commit f628b35fc3
4 changed files with 53 additions and 38 deletions

View File

@@ -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)
# ---------------------------------------------------------------------------