fix(dashboard+list): pending status sort first, stats count, badge/recipient/time display
This commit is contained in:
@@ -590,7 +590,7 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db:
|
||||
all_cards.extend(cards)
|
||||
|
||||
total = len(all_cards)
|
||||
sent = sum(1 for c in all_cards if c.status == "sent")
|
||||
sent = sum(1 for c in all_cards if c.status in ("pending", "sent"))
|
||||
delivered = sum(1 for c in all_cards if c.status == "delivered")
|
||||
received = sum(1 for c in all_cards if c.status == "received")
|
||||
countries = len({c.country_to for c in all_cards if c.country_to})
|
||||
@@ -642,7 +642,7 @@ def profile_list(request: Request, user: User = Depends(get_current_user_web), d
|
||||
cards = db.query(Postcard).filter(Postcard.profile_id == p.id).all()
|
||||
extras[p.id] = {
|
||||
"total": len(cards),
|
||||
"sent": sum(1 for c in cards if c.status == "sent"),
|
||||
"sent": sum(1 for c in cards if c.status in ("pending", "sent")),
|
||||
"delivered": sum(1 for c in cards if c.status == "delivered"),
|
||||
"received": sum(1 for c in cards if c.status == "received"),
|
||||
"countries": len({c.country_to for c in cards if c.country_to}),
|
||||
@@ -707,8 +707,8 @@ def postcard_list(
|
||||
# collect existing countries for dropdown
|
||||
all_countries = sorted({pc.country_to for pc in db.query(Postcard.country_to).filter(Postcard.profile_id == profile_id, Postcard.country_to.isnot(None)).all()})
|
||||
|
||||
# status sort order: sent=0, delivered=1, received=2
|
||||
_status_order = {"sent": 0, "delivered": 1, "received": 2}
|
||||
# status sort order: pending=0, sent=1, delivered=2, received=3
|
||||
_status_order = {"pending": 0, "sent": 1, "delivered": 2, "received": 3}
|
||||
postcards.sort(key=lambda pc: (_status_order.get(pc.status, 9), -(pc.send_time or pc.arrival_time or pc.receive_time or pc.created_at).timestamp()))
|
||||
|
||||
# split into sent and received
|
||||
|
||||
Reference in New Issue
Block a user