From d2195c09695c59cccae0c2c5ef126c5d959211df Mon Sep 17 00:00:00 2001 From: giles Date: Wed, 18 Feb 2026 21:49:45 +0000 Subject: [PATCH] Fix cart badge: include calendar entries + OOB update on add - Context processor now sums product + calendar counts from cart API - add_entry route returns OOB cart-mini swap with correct count, querying pending entries from local session (sees uncommitted entry) Co-Authored-By: Claude Opus 4.6 --- app.py | 6 +++--- bp/calendar_entries/routes.py | 31 ++++++++++++++++++++++++++++--- shared | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index 8fd5263..cad4ad8 100644 --- a/app.py +++ b/app.py @@ -27,11 +27,11 @@ async def events_context() -> dict: ctx["menu_items"] = await get_navigation_tree(g.s) - # Cart data from cart API + # Cart data from cart API (includes both product + calendar counts) 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) + ctx["cart_count"] = cart_data.get("count", 0) + cart_data.get("calendar_count", 0) + ctx["cart_total"] = cart_data.get("total", 0) + cart_data.get("calendar_total", 0) else: ctx["cart_count"] = 0 ctx["cart_total"] = 0 diff --git a/bp/calendar_entries/routes.py b/bp/calendar_entries/routes.py index af3a379..da09020 100644 --- a/bp/calendar_entries/routes.py +++ b/bp/calendar_entries/routes.py @@ -3,11 +3,12 @@ from datetime import datetime, timezone from decimal import Decimal from quart import ( - request, render_template, make_response, Blueprint, g, redirect, url_for, jsonify + request, render_template, render_template_string, make_response, + Blueprint, g, redirect, url_for, jsonify, ) -from sqlalchemy import update +from sqlalchemy import update, func as sa_func from models.calendars import CalendarEntry @@ -205,8 +206,32 @@ def register(): entry.ticket_price = ticket_price entry.ticket_count = ticket_count + # Count pending calendar entries from local session (sees the just-added entry) + user_id = getattr(g, "user", None) and g.user.id + cal_filters = [ + CalendarEntry.deleted_at.is_(None), + CalendarEntry.state == "pending", + ] + if user_id: + cal_filters.append(CalendarEntry.user_id == user_id) + + cal_count = await g.s.scalar( + select(sa_func.count()).select_from(CalendarEntry).where(*cal_filters) + ) or 0 + + # Get product cart count from API (committed data only, which is fine) + from shared.infrastructure.internal_api import get as api_get + cart_data = await api_get("cart", "/internal/cart/summary", forward_session=True) + product_count = cart_data.get("count", 0) if cart_data else 0 + total_count = product_count + cal_count + html = await render_template("_types/day/_main_panel.html") - return await make_response(html, 200) + mini_html = await render_template_string( + '{% from "_types/cart/_mini.html" import mini with context %}' + '{{ mini(oob="true") }}', + cart_count=total_count, + ) + return await make_response(html + mini_html, 200) @bp.get("/add/") async def add_form(day: int, month: int, year: int, **kwargs): diff --git a/shared b/shared index 0c0f3c8..e3f8ff6 160000 --- a/shared +++ b/shared @@ -1 +1 @@ -Subproject commit 0c0f3c84167ff61ad469e1f5ad93de7841c59e76 +Subproject commit e3f8ff6e3c29c0506398604fc3aa4262138f484a