mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
show upvoted posts on profile
This commit is contained in:
parent
1d6716f98b
commit
c3d36cfb86
3 changed files with 49 additions and 16 deletions
|
@ -1,3 +1,4 @@
|
||||||
<div class="post_reply_teaser">
|
<div class="post_reply_teaser">
|
||||||
{{ post_reply.body_html }}
|
{{ post_reply.body_html|safe }}
|
||||||
</div>
|
</div>
|
||||||
|
<hr />
|
|
@ -74,19 +74,32 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if len(moderates) > 0 %}
|
{% if len(subscribed) > 0 or len(moderates) > 0 %}
|
||||||
<div class="card mt-3">
|
<div class="card mt-3">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h2>{{ _('Moderates') }}</h2>
|
<h2>{{ _('Communities') }}</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<ol>
|
{% if len(subscribed) > 0 %}
|
||||||
{% for community in moderates %}
|
<h4>Subscribed to</h4>
|
||||||
<li>
|
<ul>
|
||||||
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />{{ community.display_name() }}</a>
|
{% for community in subscribed %}
|
||||||
</li>
|
<li>
|
||||||
{% endfor %}
|
<a href="/c/{{ community.link() }}"><img src="{{ community.icon_image() }}" class="community_icon rounded-circle" loading="lazy" />{{ community.display_name() }}</a>
|
||||||
</ol>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -120,6 +133,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -3,7 +3,7 @@ from flask_login import login_user, logout_user, current_user, login_required
|
||||||
from flask_babel import _
|
from flask_babel import _
|
||||||
|
|
||||||
from app import db
|
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 import bp
|
||||||
from app.user.forms import ProfileForm, SettingsForm
|
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
|
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):
|
def show_profile(user):
|
||||||
if user.deleted or user.banned and current_user.is_anonymous():
|
if user.deleted or user.banned and current_user.is_anonymous():
|
||||||
abort(404)
|
abort(404)
|
||||||
posts = Post.query.filter_by(user_id=user.id).order_by(desc(Post.posted_at)).all()
|
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(or_(CommunityMember.is_moderator, CommunityMember.is_owner))
|
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:
|
if current_user.is_anonymous or user.id != current_user.id:
|
||||||
moderates = moderates.filter(Community.private_mods == False)
|
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
|
canonical = user.ap_public_url if user.ap_public_url else None
|
||||||
user.about_html = markdown_to_html(user.about)
|
user.about_html = markdown_to_html(user.about)
|
||||||
description = shorten_string(markdown_to_text(user.about), 150) if user.about else None
|
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,
|
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',
|
moderates=moderates.all(), canonical=canonical, title=_('Posts by %(user_name)s',
|
||||||
user_name=user.user_name),
|
user_name=user.user_name),
|
||||||
description=description)
|
description=description, subscribed=subscribed, upvoted=upvoted)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/u/<actor>/profile', methods=['GET', 'POST'])
|
@bp.route('/u/<actor>/profile', methods=['GET', 'POST'])
|
||||||
|
|
Loading…
Reference in a new issue