feat(ui): redesign postcards list with tabs, row layout, country dropdown filter
This commit is contained in:
@@ -203,7 +203,6 @@ def profile_rename(profile_id: int, nickname: str = Form(...), user: User = Depe
|
||||
def postcard_list(
|
||||
request: Request,
|
||||
profile_id: int,
|
||||
status: str = "",
|
||||
country: str = "",
|
||||
user: User = Depends(get_current_user_web),
|
||||
db: Session = Depends(get_db),
|
||||
@@ -212,14 +211,24 @@ def postcard_list(
|
||||
if not profile:
|
||||
return _redirect("/profiles")
|
||||
q = db.query(Postcard).filter(Postcard.profile_id == profile_id)
|
||||
if status:
|
||||
q = q.filter(Postcard.status == status)
|
||||
if country:
|
||||
q = q.filter(Postcard.country.ilike(f"%{country}%"))
|
||||
postcards = q.order_by(Postcard.created_at.desc()).all()
|
||||
q = q.filter(Postcard.country == country)
|
||||
postcards = q.all()
|
||||
|
||||
# collect existing countries for dropdown
|
||||
all_countries = sorted({pc.country for pc in db.query(Postcard.country).filter(Postcard.profile_id == profile_id, Postcard.country.isnot(None)).all()})
|
||||
|
||||
# status sort order: sent=0, delivered=1, received=2
|
||||
_status_order = {"sent": 0, "delivered": 1, "received": 2}
|
||||
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
|
||||
sent = [pc for pc in postcards if pc.status in ("sent", "delivered")]
|
||||
received = [pc for pc in postcards if pc.status == "received"]
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"postcards.html",
|
||||
{"request": request, "user": user, "profile": profile, "postcards": postcards, "status": status, "country": country},
|
||||
{"request": request, "user": user, "profile": profile, "sent": sent, "received": received, "countries": all_countries, "country": country},
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user