Contains shared infrastructure for all coop services: - shared/ (factory, urls, user_loader, context, internal_api, jinja_setup) - models/ (User, Order, Calendar, Ticket, Product, Ghost CMS) - db/ (SQLAlchemy async session, base) - suma_browser/app/ (csrf, middleware, errors, authz, redis_cacher, payments, filters, utils) - suma_browser/templates/ (shared base layouts, macros, error pages) - static/ (CSS, JS, fonts, images) - alembic/ (database migrations) - config/ (app-config.yaml) - editor/ (Lexical editor Node.js build) - requirements.txt Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""
|
|
Base template context shared by all apps.
|
|
|
|
This module no longer imports cart or menu_items services directly.
|
|
Each app provides its own context_fn that calls this base and adds
|
|
app-specific variables (cart data, menu_items, etc.).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from quart import request, g, current_app
|
|
|
|
from config import config
|
|
from utils import host_url
|
|
from suma_browser.app.utils import current_route_relative_path
|
|
|
|
|
|
async def base_context() -> dict:
|
|
"""
|
|
Common template variables available in every app.
|
|
|
|
Does NOT include cart, calendar_cart_entries, total, calendar_total,
|
|
or menu_items — those are added by each app's context_fn.
|
|
"""
|
|
is_htmx = request.headers.get("HX-Request") == "true"
|
|
search = request.headers.get("X-Search", "")
|
|
zap_filter = is_htmx and search == ""
|
|
|
|
def base_url():
|
|
return host_url()
|
|
|
|
hx_select = "#main-panel"
|
|
hx_select_search = (
|
|
hx_select
|
|
+ ", #search-mobile, #search-count-mobile, #search-desktop, #search-count-desktop, #menu-items-nav-wrapper"
|
|
)
|
|
|
|
return {
|
|
"is_htmx": is_htmx,
|
|
"request": request,
|
|
"now": datetime.now(),
|
|
"current_local_href": current_route_relative_path(),
|
|
"config": config(),
|
|
"asset_url": current_app.jinja_env.globals.get("asset_url", lambda p: ""),
|
|
"sort_options": [
|
|
("az", "A\u2013Z", "order/a-z.svg"),
|
|
("za", "Z\u2013A", "order/z-a.svg"),
|
|
("price-asc", "\u00a3 low\u2192high", "order/l-h.svg"),
|
|
("price-desc", "\u00a3 high\u2192low", "order/h-l.svg"),
|
|
],
|
|
"zap_filter": zap_filter,
|
|
"print": print,
|
|
"base_url": base_url,
|
|
"base_title": config()["title"],
|
|
"hx_select": hx_select,
|
|
"hx_select_search": hx_select_search,
|
|
}
|