This repository has been archived on 2026-02-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
market/app.py
giles dc7c989834
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
feat: add shared library as git submodule
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 23:41:50 +00:00

56 lines
1.4 KiB
Python

from __future__ import annotations
import path_setup # noqa: F401 # adds shared_lib to sys.path
from quart import g
from shared.factory import create_base_app
from config import config
from suma_browser.app.bp import register_market_bp
async def market_context() -> dict:
"""
Market app context processor.
- menu_items: fetched from coop internal API
- cart_count/cart_total: fetched from cart internal API
"""
from shared.context import base_context
from shared.internal_api import get as api_get, dictobj
ctx = await base_context()
# Menu items from coop API (wrapped for attribute access in templates)
menu_data = await api_get("coop", "/internal/menu-items")
ctx["menu_items"] = dictobj(menu_data) if menu_data else []
# Cart data from cart API
cart_data = await api_get("cart", "/internal/cart/summary", forward_session=True)
if cart_data:
ctx["cart_count"] = cart_data.get("count", 0)
ctx["cart_total"] = cart_data.get("total", 0)
else:
ctx["cart_count"] = 0
ctx["cart_total"] = 0
return ctx
def create_app() -> "Quart":
app = create_base_app("market", context_fn=market_context)
# Market blueprint at root (was /market in monolith)
app.register_blueprint(
register_market_bp(
url_prefix="/",
title=config()["coop_title"],
),
url_prefix="/",
)
return app
app = create_app()