From d7850d200f3871f3fd540a224930bc3fd019bd06 Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Sun, 5 Jul 2026 19:00:25 +0800 Subject: [PATCH] feat: add profile rename, all postcard fields required --- app/routers/web.py | 9 +++++++++ app/static/style.css | 2 ++ app/templates/postcard_form.html | 32 +++++++++++++++++--------------- app/templates/profiles.html | 4 ++++ 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/app/routers/web.py b/app/routers/web.py index 7767853..e97328c 100644 --- a/app/routers/web.py +++ b/app/routers/web.py @@ -139,6 +139,15 @@ def profile_delete(profile_id: int, user: User = Depends(get_current_user_web), return _redirect("/profiles") +@router.post("/profiles/{profile_id}/rename") +def profile_rename(profile_id: int, nickname: str = Form(...), user: User = Depends(get_current_user_web), db: Session = Depends(get_db)): + p = db.query(Profile).filter(Profile.id == profile_id, Profile.user_id == user.id).first() + if p: + p.nickname = nickname + db.commit() + return _redirect("/profiles") + + # ---------- Postcards ---------- @router.get("/profiles/{profile_id}/postcards", response_class=HTMLResponse) diff --git a/app/static/style.css b/app/static/style.css index 76ba0b5..72c485d 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -53,6 +53,8 @@ input[type="text"] + label, input[type="password"] + label, input[type="datetime .form-row .btn { white-space: nowrap; flex-shrink: 0; } .filter-bar .form-row select { flex: 0 0 auto; width: auto; } .inline-form { margin-bottom: 1.25rem; } +.rename-form { display: inline-flex; gap: .35rem; align-items: center; margin-right: .5rem; } +.rename-form input[type="text"] { width: 120px; flex: none; } /* Buttons */ .btn { display: inline-block; padding: .5rem 1rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font-size: .9rem; text-align: center; white-space: nowrap; } diff --git a/app/templates/postcard_form.html b/app/templates/postcard_form.html index 20945d3..fb2a7e1 100644 --- a/app/templates/postcard_form.html +++ b/app/templates/postcard_form.html @@ -9,28 +9,28 @@ -
- - - - - - - - + + + + + + + +
@@ -41,8 +41,10 @@ diff --git a/app/templates/profiles.html b/app/templates/profiles.html index 575a93c..beaf5c3 100644 --- a/app/templates/profiles.html +++ b/app/templates/profiles.html @@ -19,6 +19,10 @@ {{ p.nickname }} {{ p.created_at.strftime('%Y-%m-%d %H:%M') }} +
+ + +