All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 3m30s
- Delete events_api.py (dead internal API endpoint) - Remove registration from app.py - Update shared submodule Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
135 lines
4.1 KiB
Python
135 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
import path_setup # noqa: F401 # adds shared_lib to sys.path
|
|
from pathlib import Path
|
|
|
|
from quart import g, abort
|
|
from jinja2 import FileSystemLoader, ChoiceLoader
|
|
|
|
from shared.infrastructure.factory import create_base_app
|
|
|
|
from bp import register_calendars, register_markets, register_payments
|
|
|
|
|
|
async def events_context() -> dict:
|
|
"""
|
|
Events app context processor.
|
|
|
|
- menu_items: direct DB query via glue layer
|
|
- cart_count/cart_total: via cart service (shared DB)
|
|
"""
|
|
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
|
|
|
|
ctx = await base_context()
|
|
|
|
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)
|
|
|
|
return ctx
|
|
|
|
|
|
def create_app() -> "Quart":
|
|
from shared.services.registry import services
|
|
from services import register_domain_services
|
|
|
|
app = create_base_app(
|
|
"events",
|
|
context_fn=events_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,
|
|
])
|
|
|
|
# Calendars nested under post slug: /<slug>/calendars/...
|
|
app.register_blueprint(
|
|
register_calendars(),
|
|
url_prefix="/<slug>/calendars",
|
|
)
|
|
|
|
# Markets nested under post slug: /<slug>/markets/...
|
|
app.register_blueprint(
|
|
register_markets(),
|
|
url_prefix="/<slug>/markets",
|
|
)
|
|
|
|
# Payments nested under post slug: /<slug>/payments/...
|
|
app.register_blueprint(
|
|
register_payments(),
|
|
url_prefix="/<slug>/payments",
|
|
)
|
|
|
|
# --- Auto-inject slug into url_for() calls ---
|
|
@app.url_value_preprocessor
|
|
def pull_slug(endpoint, values):
|
|
if values and "slug" in values:
|
|
g.post_slug = values.pop("slug")
|
|
|
|
@app.url_defaults
|
|
def inject_slug(endpoint, values):
|
|
slug = g.get("post_slug")
|
|
if slug and "slug" not in values:
|
|
if app.url_map.is_endpoint_expecting(endpoint, "slug"):
|
|
values["slug"] = slug
|
|
|
|
# --- Load post data for slug ---
|
|
@app.before_request
|
|
async def hydrate_post():
|
|
slug = getattr(g, "post_slug", None)
|
|
if not slug:
|
|
return
|
|
post = await services.blog.get_post_by_slug(g.s, slug)
|
|
if not post:
|
|
abort(404)
|
|
g.post_data = {
|
|
"post": {
|
|
"id": post.id,
|
|
"title": post.title,
|
|
"slug": post.slug,
|
|
"feature_image": post.feature_image,
|
|
"status": post.status,
|
|
"visibility": post.visibility,
|
|
},
|
|
}
|
|
|
|
@app.context_processor
|
|
async def inject_post():
|
|
post_data = getattr(g, "post_data", None)
|
|
if not post_data:
|
|
return {}
|
|
post_id = post_data["post"]["id"]
|
|
calendars = await services.calendar.calendars_for_container(g.s, "page", post_id)
|
|
markets = await services.market.marketplaces_for_container(g.s, "page", post_id)
|
|
return {
|
|
**post_data,
|
|
"calendars": calendars,
|
|
"markets": markets,
|
|
}
|
|
|
|
# Tickets blueprint — user-facing ticket views and QR codes
|
|
from bp.tickets.routes import register as register_tickets
|
|
app.register_blueprint(register_tickets())
|
|
|
|
# Ticket admin — check-in interface (admin only)
|
|
from bp.ticket_admin.routes import register as register_ticket_admin
|
|
app.register_blueprint(register_ticket_admin())
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|