feat(profiles): add private notes field per profile, visible only to owner
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String
|
||||
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
|
||||
from sqlalchemy.orm import relationship, validates
|
||||
|
||||
from app.database import Base
|
||||
@@ -61,6 +61,7 @@ class Profile(Base):
|
||||
nickname = Column(String(64), nullable=False)
|
||||
showcase_enabled = Column(default=False, nullable=False)
|
||||
showcase_visible = Column(String(16), nullable=False, default="both")
|
||||
notes = Column(Text, nullable=False, default="")
|
||||
created_at = Column(DateTime, default=_utcnow)
|
||||
|
||||
user = relationship("User", back_populates="profiles")
|
||||
|
||||
@@ -451,6 +451,15 @@ def profile_rename(profile_id: int, nickname: str = Form(...), user: User = Depe
|
||||
return _redirect("/profiles")
|
||||
|
||||
|
||||
@router.post("/profiles/{profile_id}/notes")
|
||||
def profile_notes(profile_id: int, notes: 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.notes = notes
|
||||
db.commit()
|
||||
return _redirect("/profiles")
|
||||
|
||||
|
||||
# ---------- Postcards ----------
|
||||
|
||||
@router.get("/profiles/{profile_id}/postcards", response_class=HTMLResponse)
|
||||
|
||||
@@ -48,6 +48,14 @@
|
||||
<span class="stat-label">国家</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="profile-card-notes" style="padding:0 .75rem">
|
||||
<form method="post" action="/profiles/{{ p.id }}/notes" style="display:flex;flex-direction:column;gap:.3rem">
|
||||
<textarea name="notes" rows="2" placeholder="备注(仅自己可见)" style="width:100%;padding:.4rem .6rem;border:1px solid var(--border);border-radius:6px;font-size:.85rem;resize:vertical;font-family:inherit">{{ p.notes }}</textarea>
|
||||
<div style="display:flex;justify-content:flex-end">
|
||||
<button type="submit" class="btn btn-sm">保存</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="profile-card-footer">
|
||||
<span class="profile-card-date">创建于 {{ p.created_at.strftime('%Y-%m-%d') }}</span>
|
||||
<div class="profile-card-actions">
|
||||
|
||||
Reference in New Issue
Block a user