feat: always display country code in uppercase (model validates + oninput)

This commit is contained in:
2026-07-05 21:22:57 +08:00
parent 08684493f4
commit 2bd914532e
3 changed files with 8 additions and 4 deletions

View File

@@ -1,8 +1,8 @@
import uuid
from datetime import datetime, timezone
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, event
from sqlalchemy.orm import relationship, validates
from app.database import Base
@@ -72,3 +72,7 @@ class Postcard(Base):
updated_at = Column(DateTime, default=_utcnow, onupdate=_utcnow)
profile = relationship("Profile", back_populates="postcards")
@validates("country")
def _upper_country(self, key, value):
return value.strip().upper() if value else None

View File

@@ -221,7 +221,7 @@ def postcard_create(
card_number=card_number,
status=status,
recipient_name=recipient_name or None,
country=country or None,
country=(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,

View File

@@ -19,7 +19,7 @@
<label>收件人 *</label>
<input type="text" name="recipient_name" id="input-recipient" value="{{ postcard.recipient_name if postcard else '' }}">
<label>国家/地区 *</label>
<input type="text" name="country" id="input-country" value="{{ postcard.country if postcard else '' }}" maxlength="2" placeholder="JP" style="width:80px;text-transform:uppercase">
<input type="text" name="country" id="input-country" value="{{ postcard.country if postcard else '' }}" maxlength="2" placeholder="JP" style="width:80px;text-transform:uppercase" oninput="this.value=this.value.toUpperCase()">
<label>寄出时间 *</label>
<input type="date" name="send_time" id="input-send-time" value="{{ postcard.send_time.strftime('%Y-%m-%d') if postcard and postcard.send_time else '' }}">
<label id="label-arrival">到达时间</label>