mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
Merge branch 'main' into hono4kami/392
This commit is contained in:
commit
4cc4cb2e7b
3 changed files with 150 additions and 134 deletions
|
@ -116,36 +116,6 @@ def home_page(sort, view_filter):
|
||||||
posts = posts.order_by(desc(Post.last_active))
|
posts = posts.order_by(desc(Post.last_active))
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
if view_filter == 'subscribed' and current_user.is_authenticated and sort == 'new':
|
|
||||||
# use python list instead of DB query
|
|
||||||
posts = posts.all()
|
|
||||||
|
|
||||||
# exclude extra cross-posts from feed
|
|
||||||
already_seen = []
|
|
||||||
limit = 100 if not low_bandwidth else 50
|
|
||||||
#i = -1 # option 1: don't exclude cross-posts
|
|
||||||
#i = min(limit - 1, len(posts) - 1) # option 2: exclude cross-posts from the first page only
|
|
||||||
i = min((limit * 10) - 1, len(posts) - 1) # option 3: exclude cross-posts across a 'magic number' of pages
|
|
||||||
#i = len(posts) - 1 # option 4: exclude all cross-posts ever
|
|
||||||
while i >= 0:
|
|
||||||
if not posts[i].cross_posts:
|
|
||||||
i -= 1
|
|
||||||
continue
|
|
||||||
if posts[i].id in already_seen:
|
|
||||||
posts.pop(i)
|
|
||||||
else:
|
|
||||||
already_seen.extend(posts[i].cross_posts)
|
|
||||||
i -= 1
|
|
||||||
|
|
||||||
# paginate manually (can't use paginate())
|
|
||||||
start = (page - 1) * limit
|
|
||||||
end = start + limit
|
|
||||||
posts = posts[start:end]
|
|
||||||
next_page = page + 1 if len(posts) == limit else None
|
|
||||||
previous_page = page - 1 if page != 1 else None
|
|
||||||
next_url = url_for('main.index', page=next_page, sort=sort, view_filter=view_filter) if next_page else None
|
|
||||||
prev_url = url_for('main.index', page=previous_page, sort=sort, view_filter=view_filter) if previous_page else None
|
|
||||||
else:
|
|
||||||
posts = posts.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False)
|
posts = posts.paginate(page=page, per_page=100 if current_user.is_authenticated and not low_bandwidth else 50, error_out=False)
|
||||||
next_url = url_for('main.index', page=posts.next_num, sort=sort, view_filter=view_filter) if posts.has_next else None
|
next_url = url_for('main.index', page=posts.next_num, sort=sort, view_filter=view_filter) if posts.has_next else None
|
||||||
prev_url = url_for('main.index', page=posts.prev_num, sort=sort, view_filter=view_filter) if posts.has_prev and page != 1 else None
|
prev_url = url_for('main.index', page=posts.prev_num, sort=sort, view_filter=view_filter) if posts.has_prev and page != 1 else None
|
||||||
|
@ -250,7 +220,6 @@ def list_communities():
|
||||||
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
||||||
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
||||||
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
|
||||||
menu_topics=menu_topics(), site=g.site)
|
menu_topics=menu_topics(), site=g.site)
|
||||||
|
|
||||||
|
|
||||||
|
@ -302,11 +271,11 @@ def list_local_communities():
|
||||||
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
||||||
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
||||||
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
|
||||||
menu_topics=menu_topics(), site=g.site)
|
menu_topics=menu_topics(), site=g.site)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/communities/subscribed', methods=['GET'])
|
@bp.route('/communities/subscribed', methods=['GET'])
|
||||||
|
@login_required
|
||||||
def list_subscribed_communities():
|
def list_subscribed_communities():
|
||||||
verification_warning()
|
verification_warning()
|
||||||
search_param = request.args.get('search', '')
|
search_param = request.args.get('search', '')
|
||||||
|
@ -317,8 +286,16 @@ def list_subscribed_communities():
|
||||||
sort_by = request.args.get('sort_by', 'post_reply_count desc')
|
sort_by = request.args.get('sort_by', 'post_reply_count desc')
|
||||||
topics = Topic.query.order_by(Topic.name).all()
|
topics = Topic.query.order_by(Topic.name).all()
|
||||||
languages = Language.query.order_by(Language.name).all()
|
languages = Language.query.order_by(Language.name).all()
|
||||||
if current_user.is_authenticated:
|
# get all the communities
|
||||||
communities = Community.query.filter_by(banned=False).join(CommunityMember).filter(CommunityMember.user_id == current_user.id)
|
all_communities = Community.query.filter_by(banned=False)
|
||||||
|
# get the user's joined communities
|
||||||
|
user_joined_communities = joined_communities(current_user.id)
|
||||||
|
# get the joined community ids list
|
||||||
|
joined_ids = []
|
||||||
|
for jc in user_joined_communities:
|
||||||
|
joined_ids.append(jc.id)
|
||||||
|
# filter down to just the joined communities
|
||||||
|
communities = all_communities.filter(Community.id.in_(joined_ids))
|
||||||
|
|
||||||
if search_param == '':
|
if search_param == '':
|
||||||
pass
|
pass
|
||||||
|
@ -343,18 +320,12 @@ def list_subscribed_communities():
|
||||||
next_url = url_for('main.list_subscribed_communities', page=communities.next_num, sort_by=sort_by, language_id=language_id) if communities.has_next else None
|
next_url = url_for('main.list_subscribed_communities', page=communities.next_num, sort_by=sort_by, language_id=language_id) if communities.has_next else None
|
||||||
prev_url = url_for('main.list_subscribed_communities', page=communities.prev_num, sort_by=sort_by, language_id=language_id) if communities.has_prev and page != 1 else None
|
prev_url = url_for('main.list_subscribed_communities', page=communities.prev_num, sort_by=sort_by, language_id=language_id) if communities.has_prev and page != 1 else None
|
||||||
|
|
||||||
else:
|
|
||||||
communities = []
|
|
||||||
next_url = None
|
|
||||||
prev_url = None
|
|
||||||
|
|
||||||
return render_template('list_communities.html', communities=communities, search=search_param, title=_('Joined Communities'),
|
return render_template('list_communities.html', communities=communities, search=search_param, title=_('Joined Communities'),
|
||||||
SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
||||||
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
|
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
|
||||||
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
next_url=next_url, prev_url=prev_url, current_user=current_user,
|
||||||
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
topics=topics, languages=languages, topic_id=topic_id, language_id=language_id, sort_by=sort_by,
|
||||||
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
low_bandwidth=low_bandwidth, moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
joined_communities=joined_communities(current_user.get_id()),
|
|
||||||
menu_topics=menu_topics(), site=g.site)
|
menu_topics=menu_topics(), site=g.site)
|
||||||
|
|
||||||
|
|
||||||
|
@ -369,7 +340,6 @@ def list_not_subscribed_communities():
|
||||||
sort_by = request.args.get('sort_by', 'post_reply_count desc')
|
sort_by = request.args.get('sort_by', 'post_reply_count desc')
|
||||||
topics = Topic.query.order_by(Topic.name).all()
|
topics = Topic.query.order_by(Topic.name).all()
|
||||||
languages = Language.query.order_by(Language.name).all()
|
languages = Language.query.order_by(Language.name).all()
|
||||||
if current_user.is_authenticated:
|
|
||||||
# get all communities
|
# get all communities
|
||||||
all_communities = Community.query.filter_by(banned=False)
|
all_communities = Community.query.filter_by(banned=False)
|
||||||
# get the user's joined communities
|
# get the user's joined communities
|
||||||
|
@ -408,11 +378,6 @@ def list_not_subscribed_communities():
|
||||||
next_url = url_for('main.list_not_subscribed_communities', page=communities.next_num, sort_by=sort_by, language_id=language_id) if communities.has_next else None
|
next_url = url_for('main.list_not_subscribed_communities', page=communities.next_num, sort_by=sort_by, language_id=language_id) if communities.has_next else None
|
||||||
prev_url = url_for('main.list_not_subscribed_communities', page=communities.prev_num, sort_by=sort_by, language_id=language_id) if communities.has_prev and page != 1 else None
|
prev_url = url_for('main.list_not_subscribed_communities', page=communities.prev_num, sort_by=sort_by, language_id=language_id) if communities.has_prev and page != 1 else None
|
||||||
|
|
||||||
else:
|
|
||||||
communities = []
|
|
||||||
next_url = None
|
|
||||||
prev_url = None
|
|
||||||
|
|
||||||
return render_template('list_communities.html', communities=communities, search=search_param, title=_('Not Joined Communities'),
|
return render_template('list_communities.html', communities=communities, search=search_param, title=_('Not Joined Communities'),
|
||||||
SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
SUBSCRIPTION_PENDING=SUBSCRIPTION_PENDING, SUBSCRIPTION_MEMBER=SUBSCRIPTION_MEMBER,
|
||||||
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
|
SUBSCRIPTION_OWNER=SUBSCRIPTION_OWNER, SUBSCRIPTION_MODERATOR=SUBSCRIPTION_MODERATOR,
|
||||||
|
|
|
@ -39,7 +39,7 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||||
function setupPostTeaserHandler() {
|
function setupPostTeaserHandler() {
|
||||||
document.querySelectorAll('.post_teaser_clickable').forEach(div => {
|
document.querySelectorAll('.post_teaser_clickable').forEach(div => {
|
||||||
div.onclick = function() {
|
div.onclick = function() {
|
||||||
const firstAnchor = this.parentElement.querySelector('a');
|
const firstAnchor = this.parentElement.querySelector('h3 a');
|
||||||
if (firstAnchor) {
|
if (firstAnchor) {
|
||||||
window.location.href = firstAnchor.href;
|
window.location.href = firstAnchor.href;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,27 +27,46 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
|
<form
|
||||||
|
id="searchCommunities"
|
||||||
|
method="get"
|
||||||
|
>
|
||||||
{% if topics -%}
|
{% if topics -%}
|
||||||
<form method="get" style="display:inline;">Topic:
|
<div style="display:inline;">
|
||||||
<select name="topic_id" class="form-control-sm submit_on_change" aria-label="{{ _('Choose a topic to filter communities by') }}">
|
Topic:
|
||||||
|
<select name="topic_id"
|
||||||
|
class="form-control-sm submit_on_change"
|
||||||
|
aria-label="{{ _('Choose a topic to filter communities by') }}"
|
||||||
|
>
|
||||||
<option value="0">All</option>
|
<option value="0">All</option>
|
||||||
{% for topic in topics -%}
|
{% for topic in topics -%}
|
||||||
<option value="{{ topic.id }}" {{ 'selected' if topic.id == topic_id }}>{{ topic.name }}</option>
|
<option value="{{ topic.id }}" {{ 'selected' if topic.id == topic_id }}>{{ topic.name }}
|
||||||
|
</option>
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
</select>
|
</select>
|
||||||
</form>
|
</div>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
{% if languages -%}
|
{% if languages -%}
|
||||||
<form method="get" style="display:inline;">Language:
|
<div style="display:inline;">
|
||||||
<select name="language_id" class="form-control-sm submit_on_change" aria-label="{{ _('Choose a language to filter communities by') }}">
|
Language:
|
||||||
|
<select name="language_id"
|
||||||
|
class="form-control-sm submit_on_change"
|
||||||
|
aria-label="{{ _('Choose a language to filter communities by') }}">
|
||||||
<option value="0">All</option>
|
<option value="0">All</option>
|
||||||
{% for language in languages -%}
|
{% for language in languages -%}
|
||||||
<option value="{{ language.id }}" {{ 'selected' if language.id == language_id }}>{{ language.name }}</option>
|
<option value="{{ language.id }}" {{ 'selected' if language.id == language_id }}>{{ language.name }}
|
||||||
|
</option>
|
||||||
{% endfor -%}
|
{% endfor -%}
|
||||||
</select>
|
</select>
|
||||||
</form>
|
</div>
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
<form method="get" style="display:inline;"><input type="search" name="search" placeholder="{{ _('Search') }}" value="{{ search }}"></form>
|
<div style="display:inline;">
|
||||||
|
<input type="search"
|
||||||
|
name="search"
|
||||||
|
placeholder="{{ _('Search') }}"
|
||||||
|
value="{{ search }}">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-auto">
|
<div class="col-auto">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
|
@ -67,24 +86,56 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th> </th>
|
<th> </th>
|
||||||
<th {% if not low_bandwidth -%}colspan="2"{% endif -%} scope="col">
|
<th {% if not low_bandwidth -%}colspan="2"{% endif -%} scope="col">
|
||||||
<a href="?sort_by=title{{ ' asc' if sort_by == 'title desc' else ' desc' }}" title="{{ _('Sort by name') }}" rel="nofollow">{{ _('Community') }}
|
<button
|
||||||
|
form="searchCommunities"
|
||||||
|
hx-boost="true"
|
||||||
|
name="sort_by"
|
||||||
|
value="title{{ ' asc' if sort_by == 'title desc' else ' desc' }}"
|
||||||
|
title="{{ _('Sort by name') }}"
|
||||||
|
class="btn"
|
||||||
|
>
|
||||||
|
{{ _('Community') }}
|
||||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'title asc' }}{{ 'fe fe-chevron-down' if sort_by == 'title desc' }}"></span>
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'title asc' }}{{ 'fe fe-chevron-down' if sort_by == 'title desc' }}"></span>
|
||||||
</a>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<a href="?sort_by=post_count{{ ' asc' if sort_by == 'post_count desc' else ' desc' }}" title="{{ _('Sort by post count') }}" rel="nofollow">{{ _('Posts') }}
|
<button
|
||||||
|
form="searchCommunities"
|
||||||
|
hx-boost="true"
|
||||||
|
name="sort_by"
|
||||||
|
value="post_count{{ ' asc' if sort_by == 'post_count desc' else ' desc' }}"
|
||||||
|
title="{{ _('Sort by post count') }}"
|
||||||
|
class="btn"
|
||||||
|
>
|
||||||
|
{{ _('Posts') }}
|
||||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'post_count asc' }}{{ 'fe fe-chevron-down' if sort_by == 'post_count desc' }}"></span>
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'post_count asc' }}{{ 'fe fe-chevron-down' if sort_by == 'post_count desc' }}"></span>
|
||||||
</a>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<a href="?sort_by=post_reply_count{{ ' asc' if sort_by == 'post_reply_count desc' else ' desc' }}" title="{{ _('Sort by reply count') }}" rel="nofollow">{{ _('Comments') }}
|
<button
|
||||||
|
form="searchCommunities"
|
||||||
|
hx-boost="true"
|
||||||
|
name="sort_by"
|
||||||
|
value="post_reply_count{{ ' asc' if sort_by == 'post_reply_count desc' else ' desc' }}"
|
||||||
|
title="{{ _('Comments') }}"
|
||||||
|
class="btn"
|
||||||
|
>
|
||||||
|
{{ _('Comments') }}
|
||||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'post_reply_count asc' }}{{ 'fe fe-chevron-down' if sort_by == 'post_reply_count desc' }}"></span>
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'post_reply_count asc' }}{{ 'fe fe-chevron-down' if sort_by == 'post_reply_count desc' }}"></span>
|
||||||
</a>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
<th scope="col">
|
<th scope="col">
|
||||||
<a href="?sort_by=last_active{{ ' asc' if sort_by == 'last_active desc' else ' desc' }}" title="{{ _('Sort by recent activity') }}" rel="nofollow">{{ _('Active') }}
|
<button
|
||||||
|
form="searchCommunities"
|
||||||
|
hx-boost="true"
|
||||||
|
name="sort_by"
|
||||||
|
value="last_active{{ ' asc' if sort_by == 'last_active desc' else ' desc' }}"
|
||||||
|
title="{{ _('Sort by recent activity') }}"
|
||||||
|
class="btn"
|
||||||
|
>
|
||||||
|
{{ _('Active') }}
|
||||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_active asc' }}{{ 'fe fe-chevron-down' if sort_by == 'last_active desc' }}"></span>
|
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_active asc' }}{{ 'fe fe-chevron-down' if sort_by == 'last_active desc' }}"></span>
|
||||||
</a>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
Loading…
Add table
Reference in a new issue