mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
sort communities list
This commit is contained in:
parent
8da67fec30
commit
9aada76655
4 changed files with 26 additions and 20 deletions
|
@ -5,12 +5,11 @@ from sqlalchemy import or_, desc
|
|||
|
||||
from app import db, constants, cache
|
||||
from app.activitypub.signature import RsaKeys, post_request
|
||||
from app.activitypub.util import default_context
|
||||
from app.activitypub.util import default_context, notify_about_post
|
||||
from app.community.forms import SearchRemoteCommunity, AddLocalCommunity, CreatePostForm, ReportCommunityForm, \
|
||||
DeleteCommunityForm
|
||||
from app.community.util import search_for_community, community_url_exists, actor_to_community, \
|
||||
opengraph_parse, url_to_thumbnail_file, save_post, save_icon_file, save_banner_file, send_to_remote_instance, \
|
||||
notify_about_post
|
||||
opengraph_parse, url_to_thumbnail_file, save_post, save_icon_file, save_banner_file, send_to_remote_instance
|
||||
from app.constants import SUBSCRIPTION_MEMBER, SUBSCRIPTION_OWNER, POST_TYPE_LINK, POST_TYPE_ARTICLE, POST_TYPE_IMAGE, \
|
||||
SUBSCRIPTION_PENDING
|
||||
from app.models import User, Community, CommunityMember, CommunityJoinRequest, CommunityBan, Post, \
|
||||
|
|
|
@ -389,13 +389,3 @@ def send_to_remote_instance_task(instance_id: int, community_id: int, payload):
|
|||
instance.dormant = True
|
||||
db.session.commit()
|
||||
|
||||
|
||||
def notify_about_post(post: Post):
|
||||
people_to_notify = CommunityMember.query.filter_by(community_id=post.community_id, notify_new_posts=True, is_banned=False)
|
||||
for person in people_to_notify:
|
||||
if person.user_id != post.user_id:
|
||||
new_notification = Notification(title=shorten_string(post.title, 25), url=f"/post/{post.id}", user_id=person.user_id, author_id=post.user_id)
|
||||
db.session.add(new_notification)
|
||||
user = User.query.get(person.user_id) # todo: make this more efficient by doing a join with CommunityMember at the start of the function
|
||||
user.unread_notifications += 1
|
||||
db.session.commit()
|
||||
|
|
|
@ -11,7 +11,7 @@ from flask import g, session, flash, request, current_app, url_for, redirect, ma
|
|||
from flask_moment import moment
|
||||
from flask_login import current_user
|
||||
from flask_babel import _, get_locale
|
||||
from sqlalchemy import select, desc
|
||||
from sqlalchemy import select, desc, text
|
||||
from sqlalchemy_searchable import search
|
||||
from app.utils import render_template, get_setting, gibberish, request_etag_matches, return_304, blocked_domains, \
|
||||
ap_datetime, ip_address, retrieve_block_list, shorten_string, markdown_to_text
|
||||
|
@ -137,6 +137,7 @@ def list_communities():
|
|||
verification_warning()
|
||||
search_param = request.args.get('search', '')
|
||||
topic_id = int(request.args.get('topic_id', 0))
|
||||
sort_by = text('community.' + request.args.get('sort_by') if request.args.get('sort_by') else 'community.title')
|
||||
topics = Topic.query.order_by(Topic.name).all()
|
||||
if search_param == '':
|
||||
pass
|
||||
|
@ -150,9 +151,9 @@ def list_communities():
|
|||
if topic_id != 0:
|
||||
communities = communities.filter_by(topic_id=topic_id)
|
||||
|
||||
return render_template('list_communities.html', communities=communities.all(), search=search_param, title=_('Communities'),
|
||||
return render_template('list_communities.html', communities=communities.order_by(sort_by).all(), search=search_param, title=_('Communities'),
|
||||
SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
||||
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, topics=topics, topic_id=topic_id)
|
||||
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, topics=topics, topic_id=topic_id, sort_by=sort_by)
|
||||
|
||||
|
||||
@bp.route('/communities/local', methods=['GET'])
|
||||
|
|
|
@ -45,10 +45,26 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col"> </th>
|
||||
<th scope="col" colspan="2">{{ _('Community') }}</th>
|
||||
<th scope="col">{{ _('Posts') }}</th>
|
||||
<th scope="col">{{ _('Comments') }}</th>
|
||||
<th scope="col">{{ _('Active') }}</th>
|
||||
<th scope="col" colspan="2">
|
||||
<a href="?sort_by=title{{ ' desc' if sort_by.text == 'community.title' }}" title="{{ _('Sort by name') }}" class="no-underline" rel="nofollow">{{ _('Community') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by.text == 'community.title' }}{{ 'fe fe-chevron-down' if sort_by.text == 'community.title desc' }}"></span>
|
||||
</a>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<a href="?sort_by=post_count{{ ' desc' if sort_by.text == 'community.post_count' }}" title="{{ _('Sort by post count') }}" class="no-underline" rel="nofollow">{{ _('Posts') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by.text == 'community.post_count' }}{{ 'fe fe-chevron-down' if sort_by.text == 'community.post_count desc' }}"></span>
|
||||
</a>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<a href="?sort_by=post_reply_count{{ ' desc' if sort_by.text == 'community.post_reply_count' }}" title="{{ _('Sort by reply count') }}" class="no-underline" rel="nofollow">{{ _('Comments') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by.text == 'community.post_reply_count' }}{{ 'fe fe-chevron-down' if sort_by.text == 'community.post_reply_count desc' }}"></span>
|
||||
</a>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<a href="?sort_by=last_active{{ ' desc' if sort_by.text == 'community.last_active' }}" title="{{ _('Sort by recent activity') }}" class="no-underline" rel="nofollow">{{ _('Active') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by.text == 'community.last_active' }}{{ 'fe fe-chevron-down' if sort_by.text == 'community.last_active desc' }}"></span>
|
||||
</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
|
Loading…
Add table
Reference in a new issue