Fetch nav-tree fragment from blog, drop local menu_items query
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 55s

Navigation is now rendered by blog as an HTML fragment. This app
fetches it with its own app_name and path for correct highlighting.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
giles
2026-02-24 11:39:39 +00:00
parent 641178855d
commit e0046403d8
2 changed files with 9 additions and 6 deletions

13
app.py
View File

@@ -4,7 +4,7 @@ import path_setup # noqa: F401 # adds shared/ to sys.path
from decimal import Decimal from decimal import Decimal
from pathlib import Path from pathlib import Path
from quart import g, abort from quart import g, abort, request
from jinja2 import FileSystemLoader, ChoiceLoader from jinja2 import FileSystemLoader, ChoiceLoader
from sqlalchemy import select from sqlalchemy import select
@@ -45,16 +45,21 @@ async def cart_context() -> dict:
- cart / calendar_cart_entries / total / calendar_total: direct DB - cart / calendar_cart_entries / total / calendar_total: direct DB
(cart app owns this data) (cart app owns this data)
- cart_count: derived from cart + calendar entries (for _mini.html) - cart_count: derived from cart + calendar entries (for _mini.html)
- menu_items: via shared.services.navigation - nav_tree_html: fetched from blog as fragment
When g.page_post exists, cart and calendar_cart_entries are page-scoped. When g.page_post exists, cart and calendar_cart_entries are page-scoped.
Global cart_count / cart_total stay global for cart-mini. Global cart_count / cart_total stay global for cart-mini.
""" """
from shared.infrastructure.context import base_context from shared.infrastructure.context import base_context
from shared.services.navigation import get_navigation_tree from shared.infrastructure.fragments import fetch_fragment
ctx = await base_context() ctx = await base_context()
ctx["nav_tree_html"] = await fetch_fragment(
"blog", "nav-tree",
params={"app_name": "cart", "path": request.path},
)
# Cart app owns cart data — use g.cart from _load_cart # Cart app owns cart data — use g.cart from _load_cart
all_cart = getattr(g, "cart", None) or [] all_cart = getattr(g, "cart", None) or []
all_cal = await get_calendar_cart_entries(g.s) all_cal = await get_calendar_cart_entries(g.s)
@@ -86,8 +91,6 @@ async def cart_context() -> dict:
ctx["calendar_total"] = calendar_total ctx["calendar_total"] = calendar_total
ctx["ticket_total"] = ticket_total ctx["ticket_total"] = ticket_total
ctx["menu_items"] = await get_navigation_tree(g.s)
return ctx return ctx

2
shared

Submodule shared updated: 0d40dfaeca...7e650a0ee3