diff --git a/events/sexp/sexp_components.py b/events/sexp/sexp_components.py index bbc0749..b56bff1 100644 --- a/events/sexp/sexp_components.py +++ b/events/sexp/sexp_components.py @@ -36,6 +36,28 @@ _oob_header_html = oob_header_html # Post header helpers — thin wrapper over shared post_header_html # --------------------------------------------------------------------------- +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} + + def _post_header_html(ctx: dict, *, oob: bool = False) -> str: """Build the post-level header row — delegates to shared helper.""" return _shared_post_header_html(ctx, oob=oob) @@ -1263,18 +1285,20 @@ async def render_page_summary_cards(entries, has_more, pending_tickets, async def render_calendars_page(ctx: dict) -> str: """Full page: calendars listing.""" content = _calendars_main_panel_html(ctx) - hdr = root_header_html(ctx) - child = _post_header_html(ctx) + _calendars_header_html(ctx) - hdr += render("header-child", inner_html=child) - return full_page(ctx, header_rows_html=hdr, content_html=content) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + return full_page(ctx, header_rows_html=root_hdr + post_hdr + admin_hdr, content_html=content) async def render_calendars_oob(ctx: dict) -> str: """OOB response: calendars listing.""" content = _calendars_main_panel_html(ctx) - oobs = _post_header_html(ctx, oob=True) - oobs += _oob_header_html("post-header-child", "calendars-header-child", - _calendars_header_html(ctx)) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = post_admin_header_html(ctx, slug, oob=True, selected="calendars") return oob_page(ctx, oobs_html=oobs, content_html=content) @@ -1330,18 +1354,24 @@ async def render_day_oob(ctx: dict) -> str: async def render_day_admin_page(ctx: dict) -> str: """Full page: day admin.""" content = _day_admin_main_panel_html(ctx) - hdr = root_header_html(ctx) - child = (_post_header_html(ctx) - + _calendar_header_html(ctx) + _day_header_html(ctx) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + child = (admin_hdr + _calendar_header_html(ctx) + _day_header_html(ctx) + _day_admin_header_html(ctx)) - hdr += render("header-child", inner_html=child) + hdr = root_hdr + post_hdr + render("header-child", inner_html=child) return full_page(ctx, header_rows_html=hdr, content_html=content) async def render_day_admin_oob(ctx: dict) -> str: """OOB response: day admin.""" content = _day_admin_main_panel_html(ctx) - oobs = _calendar_header_html(ctx, oob=True) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = (post_admin_header_html(ctx, slug, oob=True, selected="calendars") + + _calendar_header_html(ctx, oob=True)) oobs += _oob_header_html("day-header-child", "day-admin-header-child", _day_admin_header_html(ctx)) return oob_page(ctx, oobs_html=oobs, content_html=content) @@ -1361,18 +1391,22 @@ def _events_post_admin_header_html(ctx: dict, *, oob: bool = False, async def render_calendar_admin_page(ctx: dict) -> str: """Full page: calendar admin.""" content = _calendar_admin_main_panel_html(ctx) - hdr = root_header_html(ctx) - child = (_post_header_html(ctx) - + _events_post_admin_header_html(ctx, selected="calendars") - + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx)) - hdr += render("header-child", inner_html=child) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + child = admin_hdr + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx) + hdr = root_hdr + post_hdr + render("header-child", inner_html=child) return full_page(ctx, header_rows_html=hdr, content_html=content) async def render_calendar_admin_oob(ctx: dict) -> str: """OOB response: calendar admin.""" content = _calendar_admin_main_panel_html(ctx) - oobs = (_events_post_admin_header_html(ctx, oob=True, selected="calendars") + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = (post_admin_header_html(ctx, slug, oob=True, selected="calendars") + _calendar_header_html(ctx, oob=True)) oobs += _oob_header_html("calendar-header-child", "calendar-admin-header-child", _calendar_admin_header_html(ctx)) @@ -1389,11 +1423,13 @@ async def render_slots_page(ctx: dict) -> str: slots = ctx.get("slots") or [] calendar = ctx.get("calendar") content = render_slots_table(slots, calendar) - hdr = root_header_html(ctx) - child = (_post_header_html(ctx) - + _events_post_admin_header_html(ctx, selected="calendars") - + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx)) - hdr += render("header-child", inner_html=child) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + child = admin_hdr + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx) + hdr = root_hdr + post_hdr + render("header-child", inner_html=child) return full_page(ctx, header_rows_html=hdr, content_html=content) @@ -1402,7 +1438,9 @@ async def render_slots_oob(ctx: dict) -> str: slots = ctx.get("slots") or [] calendar = ctx.get("calendar") content = render_slots_table(slots, calendar) - oobs = (_events_post_admin_header_html(ctx, oob=True, selected="calendars") + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = (post_admin_header_html(ctx, slug, oob=True, selected="calendars") + _calendar_admin_header_html(ctx, oob=True)) return oob_page(ctx, oobs_html=oobs, content_html=content) @@ -2856,11 +2894,14 @@ def _entry_admin_main_panel_html(ctx: dict) -> str: async def render_entry_admin_page(ctx: dict) -> str: """Full page: entry admin.""" content = _entry_admin_main_panel_html(ctx) - hdr = root_header_html(ctx) - child = (_post_header_html(ctx) - + _calendar_header_html(ctx) + _day_header_html(ctx) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + child = (admin_hdr + _calendar_header_html(ctx) + _day_header_html(ctx) + _entry_header_html(ctx) + _entry_admin_header_html(ctx)) - hdr += render("header-child", inner_html=child) + hdr = root_hdr + post_hdr + render("header-child", inner_html=child) nav_html = render("events-admin-placeholder-nav") return full_page(ctx, header_rows_html=hdr, content_html=content, menu_html=nav_html) @@ -2868,7 +2909,10 @@ async def render_entry_admin_page(ctx: dict) -> str: async def render_entry_admin_oob(ctx: dict) -> str: """OOB response: entry admin.""" content = _entry_admin_main_panel_html(ctx) - oobs = _entry_header_html(ctx, oob=True) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = (post_admin_header_html(ctx, slug, oob=True, selected="calendars") + + _entry_header_html(ctx, oob=True)) oobs += _oob_header_html("entry-header-child", "entry-admin-header-child", _entry_admin_header_html(ctx)) nav_html = render("events-admin-placeholder-nav") @@ -2915,11 +2959,14 @@ async def render_slot_page(ctx: dict) -> str: if not slot or not calendar: return "" content = render_slot_main_panel(slot, calendar) - hdr = root_header_html(ctx) - child = (_post_header_html(ctx) - + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + root_hdr = root_header_html(ctx) + post_hdr = _post_header_html(ctx) + admin_hdr = post_admin_header_html(ctx, slug, selected="calendars") + child = (admin_hdr + _calendar_header_html(ctx) + _calendar_admin_header_html(ctx) + _slot_header_html(ctx)) - hdr += render("header-child", inner_html=child) + hdr = root_hdr + post_hdr + render("header-child", inner_html=child) return full_page(ctx, header_rows_html=hdr, content_html=content) @@ -2930,7 +2977,10 @@ async def render_slot_oob(ctx: dict) -> str: if not slot or not calendar: return "" content = render_slot_main_panel(slot, calendar) - oobs = _calendar_admin_header_html(ctx, oob=True) + ctx = await _ensure_container_nav(ctx) + slug = (ctx.get("post") or {}).get("slug", "") + oobs = (post_admin_header_html(ctx, slug, oob=True, selected="calendars") + + _calendar_admin_header_html(ctx, oob=True)) oobs += _oob_header_html("calendar-admin-header-child", "slot-header-child", _slot_header_html(ctx)) return oob_page(ctx, oobs_html=oobs, content_html=content)