Decouple blog UI via widget registry
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 54s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 54s
Replace explicit calendar/market service calls in post routes, auth routes, and listing cards with widget-driven iteration. Zero cross-domain imports remain in blog bp layer. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,10 +8,12 @@ from quart import (
|
||||
Blueprint,
|
||||
abort,
|
||||
url_for,
|
||||
request,
|
||||
)
|
||||
from .services.post_data import post_data
|
||||
from .services.post_operations import toggle_post_like
|
||||
from shared.services.registry import services
|
||||
from shared.services.widget_registry import widgets
|
||||
|
||||
from shared.browser.app.redis_cacher import cache_page, clear_cache
|
||||
|
||||
@@ -62,25 +64,29 @@ def register():
|
||||
async def context():
|
||||
p_data = getattr(g, "post_data", None)
|
||||
if p_data:
|
||||
from .services.entry_associations import get_associated_entries
|
||||
from shared.infrastructure.cart_identity import current_cart_identity
|
||||
|
||||
db_post_id = (g.post_data.get("post") or {}).get("id") # <-- integer
|
||||
calendars = await services.calendar.calendars_for_container(g.s, "page", db_post_id)
|
||||
markets = await services.market.marketplaces_for_container(g.s, "page", db_post_id)
|
||||
db_post_id = (g.post_data.get("post") or {}).get("id")
|
||||
post_slug = (g.post_data.get("post") or {}).get("slug", "")
|
||||
|
||||
# Fetch associated entries for nav display
|
||||
associated_entries = await get_associated_entries(g.s, db_post_id)
|
||||
# Widget-driven container nav — only include widgets with data
|
||||
container_nav_loaded = []
|
||||
for w in widgets.container_nav:
|
||||
wctx = await w.context_fn(
|
||||
g.s, container_type="page", container_id=db_post_id,
|
||||
post_slug=post_slug,
|
||||
)
|
||||
# Include widget if it has any list data
|
||||
if any(v for v in wctx.values() if isinstance(v, list) and v):
|
||||
container_nav_loaded.append({"widget": w, "ctx": wctx})
|
||||
|
||||
ctx = {
|
||||
**p_data,
|
||||
"base_title": f"{config()['title']} {p_data['post']['title']}",
|
||||
"calendars": calendars,
|
||||
"markets": markets,
|
||||
"associated_entries": associated_entries,
|
||||
"container_nav_widgets": container_nav_loaded,
|
||||
}
|
||||
|
||||
# Page cart badge via service (replaces cross-app HTTP API)
|
||||
# Page cart badge via service
|
||||
post_dict = p_data.get("post") or {}
|
||||
if post_dict.get("is_page"):
|
||||
ident = current_cart_identity()
|
||||
@@ -143,24 +149,23 @@ def register():
|
||||
)
|
||||
return html
|
||||
|
||||
@bp.get("/entries/")
|
||||
async def get_entries(slug: str):
|
||||
"""Get paginated associated entries for infinite scroll in nav"""
|
||||
from .services.entry_associations import get_associated_entries
|
||||
from quart import request
|
||||
|
||||
@bp.get("/w/<widget_domain>/")
|
||||
async def widget_paginate(slug: str, widget_domain: str):
|
||||
"""Generic paginated widget endpoint for infinite scroll."""
|
||||
page = int(request.args.get("page", 1))
|
||||
post_id = g.post_data["post"]["id"]
|
||||
|
||||
result = await get_associated_entries(g.s, post_id, page=page, per_page=10)
|
||||
|
||||
html = await render_template(
|
||||
"_types/post/_entry_items.html",
|
||||
entries=result["entries"],
|
||||
page=result["page"],
|
||||
has_more=result["has_more"],
|
||||
)
|
||||
return await make_response(html)
|
||||
for w in widgets.container_nav:
|
||||
if w.domain == widget_domain:
|
||||
ctx = await w.context_fn(
|
||||
g.s, container_type="page", container_id=post_id,
|
||||
post_slug=slug, page=page,
|
||||
)
|
||||
html = await render_template(
|
||||
w.template, ctx=ctx, post=g.post_data["post"],
|
||||
)
|
||||
return await make_response(html)
|
||||
abort(404)
|
||||
|
||||
return bp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user