From cba60c2aeea05272b373f7aced8b9d48fe049fa9 Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Wed, 8 May 2024 19:55:04 +1200 Subject: [PATCH] language filter on community list #51 --- app/main/routes.py | 12 +++++++----- app/templates/list_communities.html | 10 ++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/main/routes.py b/app/main/routes.py index bfae1160..701a0041 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -29,7 +29,7 @@ from app.utils import render_template, get_setting, gibberish, request_etag_matc blocked_instances, communities_banned_from, topic_tree, recently_upvoted_posts, recently_downvoted_posts, \ generate_image_from_video_url, blocked_users from app.models import Community, CommunityMember, Post, Site, User, utcnow, Domain, Topic, File, Instance, \ - InstanceRole, Notification + InstanceRole, Notification, Language, community_language from PIL import Image import pytesseract @@ -185,20 +185,22 @@ def list_communities(): verification_warning() search_param = request.args.get('search', '') topic_id = int(request.args.get('topic_id', 0)) + language_id = int(request.args.get('language_id', 0)) sort_by = text('community.' + request.args.get('sort_by') if request.args.get('sort_by') else 'community.post_reply_count desc') topics = Topic.query.order_by(Topic.name).all() + languages = Language.query.order_by(Language.name).all() communities = Community.query.filter_by(banned=False) if search_param == '': pass else: communities = communities.filter(or_(Community.title.ilike(f"%{search_param}%"), Community.ap_id.ilike(f"%{search_param}%"))) - #query = search(select(Community), search_param, sort=True) # todo: exclude banned communities from search - #communities = db.session.scalars(query).all() - if topic_id != 0: communities = communities.filter_by(topic_id=topic_id) + if language_id != 0: + communities = communities.join(community_language).filter(community_language.c.language_id == language_id) + if current_user.is_authenticated: banned_from = communities_banned_from(current_user.id) if banned_from: @@ -207,7 +209,7 @@ def list_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, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR, - topics=topics, topic_id=topic_id, sort_by=sort_by, + topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by, low_bandwidth=request.cookies.get('low_bandwidth', '0') == '1', moderating_communities=moderating_communities(current_user.get_id()), joined_communities=joined_communities(current_user.get_id())) diff --git a/app/templates/list_communities.html b/app/templates/list_communities.html index d3e86bc1..945ec211 100644 --- a/app/templates/list_communities.html +++ b/app/templates/list_communities.html @@ -33,6 +33,16 @@ {% endif %} + {% if languages %} +
Language: + +
+ {% endif %}