diff --git a/app/blueprints/users.py b/app/blueprints/users.py index 7ee3ace..a3008e1 100644 --- a/app/blueprints/users.py +++ b/app/blueprints/users.py @@ -1,14 +1,23 @@ from flask import Blueprint, render_template, request, redirect, url_for from flask_login import login_required, current_user from ..extensions import db -from ..models import User, Profile, Notification +from ..models import User, Profile, Notification, Follow bp = Blueprint("users", __name__, url_prefix="/users") @bp.route("/") def profile(user_id): user = User.query.get_or_404(user_id) - return render_template("users/profile.html", user=user) + followers_count = Follow.query.filter_by(followee_id=user.id).count() + following_count = Follow.query.filter_by(follower_id=user.id).count() + is_following = False + try: + from flask_login import current_user + if current_user.is_authenticated: + is_following = Follow.query.filter_by(follower_id=current_user.id, followee_id=user.id).first() is not None + except Exception: + pass + return render_template("users/profile.html", user=user, followers_count=followers_count, following_count=following_count, is_following=is_following) @bp.route("/me/edit", methods=["GET", "POST"]) @login_required diff --git a/app/static/theme.css b/app/static/theme.css index e84aff0..c8388a0 100644 --- a/app/static/theme.css +++ b/app/static/theme.css @@ -9,6 +9,10 @@ body { background: #f8fafc; } .container { max-width: 1100px; } .navbar { border-radius: var(--radius); box-shadow: var(--shadow); } +.nav-menu a { padding: 8px 14px; border-radius: 999px; } +.nav-menu a:hover { background: #f1f5ff; } +.nav-user { display:flex; align-items:center; gap:12px; } +.avatar { width: 32px; height: 32px; border-radius: 50%; background: #e5e7eb; display:inline-flex; align-items:center; justify-content:center; font-weight:600; color:#4b5563; } .card { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); } .btn { border-radius: var(--radius-sm); } .form-control, .form-select, textarea { border-radius: var(--radius-sm); } diff --git a/app/templates/base.html b/app/templates/base.html index 8270e37..b55aa89 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -11,22 +11,29 @@ diff --git a/app/templates/posts/detail.html b/app/templates/posts/detail.html index 17a03d2..98321f2 100644 --- a/app/templates/posts/detail.html +++ b/app/templates/posts/detail.html @@ -3,7 +3,18 @@ {% block content %}
-

{{ post.title }}

+
+
+ {{ post.user.username[:1]|upper }} +
+

{{ post.title }}

+ {{ post.user.username }} +
+
+ {% if current_user.is_authenticated and current_user.id != post.user.id %} + 关注作者 + {% endif %} +

{{ post.description }}

{{ post.visibility.value }}
diff --git a/app/templates/users/profile.html b/app/templates/users/profile.html index f9d3b9a..bd198f2 100644 --- a/app/templates/users/profile.html +++ b/app/templates/users/profile.html @@ -1,19 +1,37 @@ {% extends 'base.html' %} {% block title %}主页{% endblock %} {% block content %} -
-

{{ user.username }}

- {% if current_user.is_authenticated and current_user.id != user.id %} - 关注 - {% endif %} +
+
+
+ {{ user.username[:1]|upper }} +

{{ user.username }}

+
+ {% if current_user.is_authenticated and current_user.id != user.id %} + {% if is_following %} + 已关注 + {% else %} + 关注 + {% endif %} + {% endif %} +
+
粉丝 {{ followers_count }} · 关注 {{ following_count }}
+

{{ user.profile.bio }}

-

{{ user.profile.bio }}


-
作品
-
+
作品
+
{% for p in user.posts %} -
- {{ p.title }} +
+ {% set first = p.images[0] if p.images %} + {% if first %} + + {{ p.title }} + + {% endif %} +
{% endfor %}