From c3d36cfb8625e7040f7324017ed5d6199e5aa690 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sun, 12 Nov 2023 20:54:22 +1300 Subject: [PATCH] show upvoted posts on profile --- .../community/_post_reply_teaser.html | 5 +- app/templates/user/show_profile.html | 47 +++++++++++++++---- app/user/routes.py | 13 +++-- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/app/templates/community/_post_reply_teaser.html b/app/templates/community/_post_reply_teaser.html index 1bbf594b..4e7a82fa 100644 --- a/app/templates/community/_post_reply_teaser.html +++ b/app/templates/community/_post_reply_teaser.html @@ -1,3 +1,4 @@
- {{ post_reply.body_html }} -
\ No newline at end of file + {{ post_reply.body_html|safe }} + +
\ No newline at end of file diff --git a/app/templates/user/show_profile.html b/app/templates/user/show_profile.html index 326ba640..636b720b 100644 --- a/app/templates/user/show_profile.html +++ b/app/templates/user/show_profile.html @@ -74,19 +74,32 @@ {% endif %} - {% if len(moderates) > 0 %} + {% if len(subscribed) > 0 or len(moderates) > 0 %}
-

{{ _('Moderates') }}

+

{{ _('Communities') }}

-
    - {% for community in moderates %} -
  1. - {{ community.display_name() }} -
  2. - {% endfor %} -
+ {% if len(subscribed) > 0 %} +

Subscribed to

+ + {% endif %} + {% if len(moderates) > 0 %} +

Moderates

+ + {% endif %}
{% endif %} @@ -120,6 +133,22 @@ {% endif %} + {% if upvoted %} +
+
+

{{ _('Upvoted') }}

+
+
+ + + +
+
+ {% endif %} {% endblock %} diff --git a/app/user/routes.py b/app/user/routes.py index 15975033..ce74d099 100644 --- a/app/user/routes.py +++ b/app/user/routes.py @@ -3,7 +3,7 @@ from flask_login import login_user, logout_user, current_user, login_required from flask_babel import _ from app import db -from app.models import Post, Community, CommunityMember, User, PostReply +from app.models import Post, Community, CommunityMember, User, PostReply, PostVote from app.user import bp from app.user.forms import ProfileForm, SettingsForm from app.utils import get_setting, render_template, markdown_to_html, user_access, markdown_to_text, shorten_string @@ -13,18 +13,21 @@ from sqlalchemy import desc, or_ def show_profile(user): if user.deleted or user.banned and current_user.is_anonymous(): abort(404) - posts = Post.query.filter_by(user_id=user.id).order_by(desc(Post.posted_at)).all() - moderates = Community.query.filter_by(banned=False).join(CommunityMember).filter(or_(CommunityMember.is_moderator, CommunityMember.is_owner)) + posts = Post.query.filter_by(user_id=user.id).order_by(desc(Post.posted_at)).limit(20).all() + moderates = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == user.id)\ + .filter(or_(CommunityMember.is_moderator, CommunityMember.is_owner)) + upvoted = Post.query.join(PostVote).filter(Post.id == PostVote.post_id, PostVote.effect > 0).order_by(desc(Post.posted_at)).limit(10).all() + subscribed = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == user.id).all() if current_user.is_anonymous or user.id != current_user.id: moderates = moderates.filter(Community.private_mods == False) - post_replies = PostReply.query.filter_by(user_id=user.id).order_by(desc(PostReply.posted_at)).all() + post_replies = PostReply.query.filter_by(user_id=user.id).order_by(desc(PostReply.posted_at)).limit(20).all() canonical = user.ap_public_url if user.ap_public_url else None user.about_html = markdown_to_html(user.about) description = shorten_string(markdown_to_text(user.about), 150) if user.about else None return render_template('user/show_profile.html', user=user, posts=posts, post_replies=post_replies, moderates=moderates.all(), canonical=canonical, title=_('Posts by %(user_name)s', user_name=user.user_name), - description=description) + description=description, subscribed=subscribed, upvoted=upvoted) @bp.route('/u//profile', methods=['GET', 'POST'])