mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
add upvote history to user profile and search results
This commit is contained in:
parent
bd6c71d8bb
commit
79359d17ad
2 changed files with 22 additions and 2 deletions
|
@ -6,7 +6,7 @@ from sqlalchemy import or_
|
||||||
from app.models import Post
|
from app.models import Post
|
||||||
from app.search import bp
|
from app.search import bp
|
||||||
from app.utils import moderating_communities, joined_communities, render_template, blocked_domains, blocked_instances, \
|
from app.utils import moderating_communities, joined_communities, render_template, blocked_domains, blocked_instances, \
|
||||||
communities_banned_from
|
communities_banned_from, recently_upvoted_posts, recently_downvoted_posts
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/search', methods=['GET', 'POST'])
|
@bp.route('/search', methods=['GET', 'POST'])
|
||||||
|
@ -46,8 +46,18 @@ def run_search():
|
||||||
next_url = url_for('search.run_search', page=posts.next_num, q=q) if posts.has_next else None
|
next_url = url_for('search.run_search', page=posts.next_num, q=q) if posts.has_next else None
|
||||||
prev_url = url_for('search.run_search', page=posts.prev_num, q=q) if posts.has_prev and page != 1 else None
|
prev_url = url_for('search.run_search', page=posts.prev_num, q=q) if posts.has_prev and page != 1 else None
|
||||||
|
|
||||||
|
# Voting history
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
recently_upvoted = recently_upvoted_posts(current_user.id)
|
||||||
|
recently_downvoted = recently_downvoted_posts(current_user.id)
|
||||||
|
else:
|
||||||
|
recently_upvoted = []
|
||||||
|
recently_downvoted = []
|
||||||
|
|
||||||
return render_template('search/results.html', title=_('Search results for %(q)s', q=q), posts=posts, q=q,
|
return render_template('search/results.html', title=_('Search results for %(q)s', q=q), posts=posts, q=q,
|
||||||
next_url=next_url, prev_url=prev_url, show_post_community=True,
|
next_url=next_url, prev_url=prev_url, show_post_community=True,
|
||||||
|
recently_upvoted=recently_upvoted,
|
||||||
|
recently_downvoted=recently_downvoted,
|
||||||
moderating_communities=moderating_communities(current_user.get_id()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
joined_communities=joined_communities(current_user.get_id()),
|
||||||
site=g.site)
|
site=g.site)
|
||||||
|
|
|
@ -19,7 +19,7 @@ from app.user.utils import purge_user_then_delete
|
||||||
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, \
|
||||||
is_image_url, ensure_directory_exists, gibberish, file_get_contents, community_membership, user_filters_home, \
|
is_image_url, ensure_directory_exists, gibberish, file_get_contents, community_membership, user_filters_home, \
|
||||||
user_filters_posts, user_filters_replies, moderating_communities, joined_communities, theme_list, blocked_instances, \
|
user_filters_posts, user_filters_replies, moderating_communities, joined_communities, theme_list, blocked_instances, \
|
||||||
allowlist_html
|
allowlist_html, recently_upvoted_posts, recently_downvoted_posts
|
||||||
from sqlalchemy import desc, or_, text
|
from sqlalchemy import desc, or_, text
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -79,12 +79,22 @@ def show_profile(user):
|
||||||
replies_prev_url = url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not None else user.user_name,
|
replies_prev_url = url_for('activitypub.user_profile', actor=user.ap_id if user.ap_id is not None else user.user_name,
|
||||||
replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None
|
replies_page=post_replies.prev_num) if post_replies.has_prev and replies_page != 1 else None
|
||||||
|
|
||||||
|
# Voting history
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
recently_upvoted = recently_upvoted_posts(current_user.id)
|
||||||
|
recently_downvoted = recently_downvoted_posts(current_user.id)
|
||||||
|
else:
|
||||||
|
recently_upvoted = []
|
||||||
|
recently_downvoted = []
|
||||||
|
|
||||||
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, subscribed=subscribed, upvoted=upvoted,
|
description=description, subscribed=subscribed, upvoted=upvoted,
|
||||||
post_next_url=post_next_url, post_prev_url=post_prev_url,
|
post_next_url=post_next_url, post_prev_url=post_prev_url,
|
||||||
replies_next_url=replies_next_url, replies_prev_url=replies_prev_url,
|
replies_next_url=replies_next_url, replies_prev_url=replies_prev_url,
|
||||||
|
recently_upvoted=recently_upvoted,
|
||||||
|
recently_downvoted=recently_downvoted,
|
||||||
noindex=not user.indexable, show_post_community=True,
|
noindex=not user.indexable, show_post_community=True,
|
||||||
moderating_communities=moderating_communities(current_user.get_id()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id())
|
joined_communities=joined_communities(current_user.get_id())
|
||||||
|
|
Loading…
Add table
Reference in a new issue