Fix cart badge: include calendar entries + OOB update on add
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 50s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 50s
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user