fix(dashboard+list): pending status sort first, stats count, badge/recipient/time display

This commit is contained in:
2026-07-15 19:36:31 +08:00
parent abec829117
commit ad85b85e1e
2 changed files with 7 additions and 7 deletions

View File

@@ -590,7 +590,7 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db:
all_cards.extend(cards) all_cards.extend(cards)
total = len(all_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") delivered = sum(1 for c in all_cards if c.status == "delivered")
received = sum(1 for c in all_cards if c.status == "received") 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}) 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() cards = db.query(Postcard).filter(Postcard.profile_id == p.id).all()
extras[p.id] = { extras[p.id] = {
"total": len(cards), "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"), "delivered": sum(1 for c in cards if c.status == "delivered"),
"received": sum(1 for c in cards if c.status == "received"), "received": sum(1 for c in cards if c.status == "received"),
"countries": len({c.country_to for c in cards if c.country_to}), "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 # 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()}) 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 sort order: pending=0, sent=1, delivered=2, received=3
_status_order = {"sent": 0, "delivered": 1, "received": 2} _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())) 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 # split into sent and received

View File

@@ -115,7 +115,7 @@ new Chart(document.getElementById('chart-received'), {
</div> </div>
<div class="recent-info"> <div class="recent-info">
<strong>{{ pc.card_number }}</strong> <strong>{{ pc.card_number }}</strong>
<span class="badge badge-{{ pc.status }}">{{ {'sent':'已寄出','delivered':'已送达','received':'已收到'}.get(pc.status) if user.language=='zh' else {'sent':'Sent','delivered':'Delivered','received':'Received'}.get(pc.status) }}</span> <span class="badge badge-{{ pc.status }}">{{ {'pending':'待寄出','sent':'已寄出','delivered':'已送达','received':'已收到'}.get(pc.status) if user.language=='zh' else {'pending':'Pending','sent':'Sent','delivered':'Delivered','received':'Received'}.get(pc.status) }}</span>
</div> </div>
<div style="margin-left:auto;text-align:right;display:flex;gap:1rem;align-items:center"> <div style="margin-left:auto;text-align:right;display:flex;gap:1rem;align-items:center">
<div> <div>
@@ -125,7 +125,7 @@ new Chart(document.getElementById('chart-received'), {
{% endif %} {% endif %}
</div> </div>
<div class="recent-meta" style="margin-left:0"> <div class="recent-meta" style="margin-left:0">
{% if pc.status in ('sent','delivered') %} {% if pc.status in ('pending','sent','delivered') %}
<span>→ {{ pc.recipient_name or '-' }}</span> <span>→ {{ pc.recipient_name or '-' }}</span>
{% else %} {% else %}
<span>← {{ pc.sender_name or '-' }}</span> <span>← {{ pc.sender_name or '-' }}</span>
@@ -134,7 +134,7 @@ new Chart(document.getElementById('chart-received'), {
</div> </div>
<div class="recent-meta" style="margin-left:0"> <div class="recent-meta" style="margin-left:0">
<span class="recent-time"> <span class="recent-time">
{% if pc.status == 'sent' and pc.send_time %} {% if pc.status in ('pending','sent') and pc.send_time %}
{% set delta = (now.date() - pc.send_time.date()).days %} {% set delta = (now.date() - pc.send_time.date()).days %}
{% if delta == 0 %}{{ 'dash.today'|t(user.language) }}{% elif delta == 1 %}{{ 'dash.yesterday'|t(user.language) }}{% else %}{{ delta }}{{ 'dash.days_ago'|t(user.language) }}{% endif %} {% if delta == 0 %}{{ 'dash.today'|t(user.language) }}{% elif delta == 1 %}{{ 'dash.yesterday'|t(user.language) }}{% else %}{{ delta }}{{ 'dash.days_ago'|t(user.language) }}{% endif %}
{% elif pc.status == 'delivered' and pc.arrival_time %} {% elif pc.status == 'delivered' and pc.arrival_time %}