Monorepo: consolidate 7 repos into one
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m5s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 1m5s
Combines shared, blog, market, cart, events, federation, and account into a single repository. Eliminates submodule sync, sibling model copying at build time, and per-app CI orchestration. Changes: - Remove per-app .git, .gitmodules, .gitea, submodule shared/ dirs - Remove stale sibling model copies from each app - Update all 6 Dockerfiles for monorepo build context (root = .) - Add build directives to docker-compose.yml - Add single .gitea/workflows/ci.yml with change detection - Add .dockerignore for monorepo build context - Create __init__.py for federation and account (cross-app imports)
This commit is contained in:
138
blog/app.py
Normal file
138
blog/app.py
Normal file
@@ -0,0 +1,138 @@
|
||||
from __future__ import annotations
|
||||
import path_setup # noqa: F401 # adds shared/ to sys.path
|
||||
from pathlib import Path
|
||||
|
||||
from quart import g, request
|
||||
from jinja2 import FileSystemLoader, ChoiceLoader
|
||||
from sqlalchemy import select
|
||||
|
||||
from shared.infrastructure.factory import create_base_app
|
||||
from shared.config import config
|
||||
from shared.models import KV
|
||||
|
||||
from bp import (
|
||||
register_blog_bp,
|
||||
register_admin,
|
||||
register_menu_items,
|
||||
register_snippets,
|
||||
register_fragments,
|
||||
)
|
||||
|
||||
|
||||
async def blog_context() -> dict:
|
||||
"""
|
||||
Blog app context processor.
|
||||
|
||||
- cart_count/cart_total: via cart service (shared DB)
|
||||
- cart_mini_html / auth_menu_html / nav_tree_html: pre-fetched fragments
|
||||
"""
|
||||
from shared.infrastructure.context import base_context
|
||||
from shared.services.navigation import get_navigation_tree
|
||||
from shared.services.registry import services
|
||||
from shared.infrastructure.cart_identity import current_cart_identity
|
||||
from shared.infrastructure.fragments import fetch_fragments
|
||||
|
||||
ctx = await base_context()
|
||||
|
||||
# Fallback for _nav.html when nav-tree fragment fetch fails
|
||||
ctx["menu_items"] = await get_navigation_tree(g.s)
|
||||
|
||||
# Cart data via service (replaces cross-app HTTP API)
|
||||
ident = current_cart_identity()
|
||||
summary = await services.cart.cart_summary(
|
||||
g.s, user_id=ident["user_id"], session_id=ident["session_id"],
|
||||
)
|
||||
ctx["cart_count"] = summary.count + summary.calendar_count + summary.ticket_count
|
||||
ctx["cart_total"] = float(summary.total + summary.calendar_total + summary.ticket_total)
|
||||
|
||||
# Pre-fetch cross-app HTML fragments concurrently
|
||||
# (fetch_fragment auto-skips when inside a fragment request to prevent circular deps)
|
||||
user = getattr(g, "user", None)
|
||||
cart_params = {}
|
||||
if ident["user_id"] is not None:
|
||||
cart_params["user_id"] = ident["user_id"]
|
||||
if ident["session_id"] is not None:
|
||||
cart_params["session_id"] = ident["session_id"]
|
||||
|
||||
auth_params = {"email": user.email} if user else {}
|
||||
nav_params = {"app_name": "blog", "path": request.path}
|
||||
|
||||
cart_mini_html, auth_menu_html, nav_tree_html = await fetch_fragments([
|
||||
("cart", "cart-mini", cart_params or None),
|
||||
("account", "auth-menu", auth_params or None),
|
||||
("blog", "nav-tree", nav_params),
|
||||
])
|
||||
ctx["cart_mini_html"] = cart_mini_html
|
||||
ctx["auth_menu_html"] = auth_menu_html
|
||||
ctx["nav_tree_html"] = nav_tree_html
|
||||
|
||||
return ctx
|
||||
|
||||
|
||||
def create_app() -> "Quart":
|
||||
from services import register_domain_services
|
||||
|
||||
app = create_base_app(
|
||||
"blog",
|
||||
context_fn=blog_context,
|
||||
domain_services_fn=register_domain_services,
|
||||
)
|
||||
|
||||
# App-specific templates override shared templates
|
||||
app_templates = str(Path(__file__).resolve().parent / "templates")
|
||||
app.jinja_loader = ChoiceLoader([
|
||||
FileSystemLoader(app_templates),
|
||||
app.jinja_loader,
|
||||
])
|
||||
|
||||
# --- blueprints ---
|
||||
app.register_blueprint(
|
||||
register_blog_bp(
|
||||
url_prefix=config()["blog_root"],
|
||||
title=config()["blog_title"],
|
||||
),
|
||||
url_prefix=config()["blog_root"],
|
||||
)
|
||||
|
||||
app.register_blueprint(register_admin("/settings"))
|
||||
app.register_blueprint(register_menu_items())
|
||||
app.register_blueprint(register_snippets())
|
||||
app.register_blueprint(register_fragments())
|
||||
|
||||
# --- KV admin endpoints ---
|
||||
@app.get("/settings/kv/<key>")
|
||||
async def kv_get(key: str):
|
||||
row = (
|
||||
await g.s.execute(select(KV).where(KV.key == key))
|
||||
).scalar_one_or_none()
|
||||
return {"key": key, "value": (row.value if row else None)}
|
||||
|
||||
@app.post("/settings/kv/<key>")
|
||||
async def kv_set(key: str):
|
||||
data = await request.get_json() or {}
|
||||
val = data.get("value", "")
|
||||
obj = await g.s.get(KV, key)
|
||||
if obj is None:
|
||||
obj = KV(key=key, value=val)
|
||||
g.s.add(obj)
|
||||
else:
|
||||
obj.value = val
|
||||
return {"ok": True, "key": key, "value": val}
|
||||
|
||||
# --- debug: url rules ---
|
||||
@app.get("/__rules")
|
||||
async def dump_rules():
|
||||
rules = []
|
||||
for r in app.url_map.iter_rules():
|
||||
rules.append({
|
||||
"endpoint": r.endpoint,
|
||||
"rule": repr(r.rule),
|
||||
"methods": sorted(r.methods - {"HEAD", "OPTIONS"}),
|
||||
"strict_slashes": r.strict_slashes,
|
||||
})
|
||||
return {"rules": rules}
|
||||
|
||||
return app
|
||||
|
||||
|
||||
app = create_app()
|
||||
Reference in New Issue
Block a user