refactor(model): rename Postcard.country -> country_to for clear semantics - country_from: origin country (where postcard was sent from) - country_to: destination country (where postcard was sent to) - Profile.country remains as user's home country - Updated all routes, schemas, templates, and API endpoints
This commit is contained in:
@@ -190,7 +190,7 @@ def api_public_cards(
|
||||
"cards": [{
|
||||
"image_front": c.image_front,
|
||||
"country_from": c.country_from,
|
||||
"country": c.country,
|
||||
"country_to": c.country_to,
|
||||
"status": c.status,
|
||||
} for c in batch],
|
||||
})
|
||||
@@ -232,7 +232,7 @@ def api_public_cards_user(
|
||||
"cards": [{
|
||||
"image_front": c.image_front,
|
||||
"country_from": c.country_from,
|
||||
"country": c.country,
|
||||
"country_to": c.country_to,
|
||||
} for c in batch],
|
||||
})
|
||||
|
||||
@@ -593,7 +593,7 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db:
|
||||
sent = sum(1 for c in all_cards if c.status == "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 for c in all_cards if c.country})
|
||||
countries = len({c.country_to for c in all_cards if c.country_to})
|
||||
|
||||
# recent postcards across all profiles (last 8), sorted by most recently updated
|
||||
all_cards.sort(key=lambda c: c.updated_at or c.created_at, reverse=True)
|
||||
@@ -611,12 +611,12 @@ def dashboard(request: Request, user: User = Depends(get_current_user_web), db:
|
||||
sent_country_counts: dict[str, int] = {}
|
||||
received_country_counts: dict[str, int] = {}
|
||||
for c in all_cards:
|
||||
if not c.country:
|
||||
if not c.country_to:
|
||||
continue
|
||||
if c.status in ("sent", "delivered"):
|
||||
sent_country_counts[c.country] = sent_country_counts.get(c.country, 0) + 1
|
||||
sent_country_counts[c.country_to] = sent_country_counts.get(c.country_to, 0) + 1
|
||||
elif c.status == "received":
|
||||
received_country_counts[c.country] = received_country_counts.get(c.country, 0) + 1
|
||||
received_country_counts[c.country_to] = received_country_counts.get(c.country_to, 0) + 1
|
||||
sent_country_stats = sorted(sent_country_counts.items(), key=lambda x: -x[1])
|
||||
received_country_stats = sorted(received_country_counts.items(), key=lambda x: -x[1])
|
||||
|
||||
@@ -645,7 +645,7 @@ def profile_list(request: Request, user: User = Depends(get_current_user_web), d
|
||||
"sent": sum(1 for c in cards if c.status == "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 for c in cards if c.country}),
|
||||
"countries": len({c.country_to for c in cards if c.country_to}),
|
||||
}
|
||||
return templates.TemplateResponse("profiles.html", {"request": request, "user": user, "profiles": profiles, "extras": extras})
|
||||
|
||||
@@ -701,11 +701,11 @@ def postcard_list(
|
||||
return _redirect("/profiles")
|
||||
q = db.query(Postcard).filter(Postcard.profile_id == profile_id)
|
||||
if country:
|
||||
q = q.filter(Postcard.country == country)
|
||||
q = q.filter(Postcard.country_to == 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()})
|
||||
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}
|
||||
@@ -777,8 +777,8 @@ def postcard_create(
|
||||
card_number=card_number.strip(),
|
||||
status=status,
|
||||
recipient_name=recipient_name or None,
|
||||
country=(country.strip().upper() if country else None),
|
||||
country_from=(country_from.strip().upper() if country_from else profile.country),
|
||||
country_to=(country.strip().upper() if country else None),
|
||||
send_time=_parse_dt(send_time),
|
||||
arrival_time=_parse_dt(arrival_time),
|
||||
sender_name=sender_name or None,
|
||||
@@ -868,8 +868,8 @@ def postcard_update(
|
||||
pc.card_number = card_number.strip()
|
||||
pc.status = status
|
||||
pc.recipient_name = recipient_name or None
|
||||
pc.country = country or None
|
||||
pc.country_from = country_from.strip().upper() if country_from else pc.country_from
|
||||
pc.country_to = country or None
|
||||
pc.send_time = _parse_dt(send_time)
|
||||
pc.arrival_time = None if status == "sent" else _parse_dt(arrival_time)
|
||||
pc.sender_name = sender_name or None
|
||||
|
||||
Reference in New Issue
Block a user