show upvoted posts on profile

This commit is contained in:
rimu 2023-11-12 20:54:22 +13:00
parent 1d6716f98b
commit c3d36cfb86
3 changed files with 49 additions and 16 deletions

View file

@ -1,3 +1,4 @@
<div class="post_reply_teaser">
{{ post_reply.body_html }}
</div>
{{ post_reply.body_html|safe }}
</div>
<hr />

View file

@ -74,19 +74,32 @@
</div>
</div>
{% endif %}
{% if len(moderates) > 0 %}
{% if len(subscribed) > 0 or len(moderates) > 0 %}
<div class="card mt-3">
<div class="card-header">
<h2>{{ _('Moderates') }}</h2>
<h2>{{ _('Communities') }}</h2>
</div>
<div class="card-body">
<ol>
{% for community in moderates %}
<li>
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />{{ community.display_name() }}</a>
</li>
{% endfor %}
</ol>
{% if len(subscribed) > 0 %}
<h4>Subscribed to</h4>
<ul>
{% for community in subscribed %}
<li>
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />{{ community.display_name() }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if len(moderates) > 0 %}
<h4>Moderates</h4>
<ul>
{% for community in moderates %}
<li>
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />{{ community.display_name() }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endif %}
@ -120,6 +133,22 @@
</div>
</div>
{% endif %}
{% if upvoted %}
<div class="card mt-3">
<div class="card-header">
<h2>{{ _('Upvoted') }}</h2>
</div>
<div class="card-body">
<ul>
{% for post in upvoted %}
<li><a href="{{ url_for('community.show_post', post_id=post.id) }}">{{ post.title }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
</div>
</div>
{% endblock %}

View file

@ -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/<actor>/profile', methods=['GET', 'POST'])