mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
sortable admin community list
This commit is contained in:
parent
5e365a73ff
commit
979f3cef91
2 changed files with 90 additions and 37 deletions
|
@ -884,17 +884,21 @@ def admin_communities():
|
|||
|
||||
page = request.args.get('page', 1, type=int)
|
||||
search = request.args.get('search', '')
|
||||
sort_by = request.args.get('sort_by', 'title ASC')
|
||||
|
||||
communities = Community.query
|
||||
if search:
|
||||
communities = communities.filter(Community.title.ilike(f"%{search}%"))
|
||||
communities = communities.order_by(Community.title).paginate(page=page, per_page=1000, error_out=False)
|
||||
communities = communities.order_by(text('"community".' + sort_by))
|
||||
communities = communities.paginate(page=page, per_page=1000, error_out=False)
|
||||
|
||||
next_url = url_for('admin.admin_communities', page=communities.next_num) if communities.has_next else None
|
||||
prev_url = url_for('admin.admin_communities', page=communities.prev_num) if communities.has_prev and page != 1 else None
|
||||
next_url = url_for('admin.admin_communities', page=communities.next_num, search=search, sort_by=sort_by) if communities.has_next else None
|
||||
prev_url = url_for('admin.admin_communities', page=communities.prev_num, search=search, sort_by=sort_by) if communities.has_prev and page != 1 else None
|
||||
|
||||
return render_template('admin/communities.html', title=_('Communities'), next_url=next_url, prev_url=prev_url,
|
||||
communities=communities, moderating_communities=moderating_communities(current_user.get_id()),
|
||||
communities=communities,
|
||||
search=search, sort_by=sort_by,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(),
|
||||
site=g.site)
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
<h1>{{ title }}</h1>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<form method="get">
|
||||
<input type="search" name="search"> <input type="submit" name="submit" value="Search">
|
||||
<form id="searchCommunities" method="get">
|
||||
<input type="search" name="search" placeholder="{{ _('Search') }}" value="{{ search }}">
|
||||
<input type="submit" name="submit" value="Search">
|
||||
</form>
|
||||
Result Filter:
|
||||
<a href="{{ url_for('admin.admin_communities') }}">All</a> |
|
||||
|
@ -27,39 +28,87 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Topic</th>
|
||||
<th># Posts</th>
|
||||
<th title="{{ _('Local members') }}"># Members</th>
|
||||
<th>Retention</th>
|
||||
<th>Layout</th>
|
||||
<th title="{{ _('Posts can be popular.') }}">Popular</th>
|
||||
<th title="{{ _('Posts show in the All feed.') }}">All</th>
|
||||
<th title="{{ _('Content warning, NSFW or NSFL set for community.') }}">Warning</th>
|
||||
<th>{{ _('Active') }}</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
{% for community in communities.items %}
|
||||
<div class="table-responsive-md mt-4">
|
||||
<table class="communities_table table table-striped table-hover w-100">
|
||||
<tr>
|
||||
<td>{{ render_communityname(community, add_domain=False) }}{% if community.banned %} (banned){% endif %}<br />
|
||||
!<a href="/c/{{ community.link() }}">{{ community.name }}</a><wbr />@<a href="{{ community.ap_profile_id }}">{{ community.ap_domain }}</a></td>
|
||||
<td>{{ community.topic.name }}</td>
|
||||
<td>{{ community.post_count }}</td>
|
||||
<td>{{ community.subscriptions_count }}</td>
|
||||
<td>{{ community.content_retention if community.content_retention != -1 }}</td>
|
||||
<td>{{ community.default_layout if community.default_layout }}</td>
|
||||
<th>{{ '✓'|safe if community.show_popular else '✗'|safe }}</th>
|
||||
<th>{{ '✓'|safe if community.show_all else '✗'|safe }}</th>
|
||||
<th>{{ '⚠'|safe if community.nsfw or community.nsfl or community.content_warning else ''|safe }}</th>
|
||||
<td>{{ arrow.get(community.last_active).humanize(locale=locale) }}</td>
|
||||
<td><a href="{{ url_for('admin.admin_community_edit', community_id=community.id) }}">Edit</a> |
|
||||
<a href="{{ url_for('admin.admin_community_delete', community_id=community.id) }}" class="confirm_first">Delete</a>
|
||||
</td>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="title{{' DESC' if sort_by == 'title ASC' else ' ASC' }}" class="btn" title="{{ _('Sort by name') }}">
|
||||
{{ _('Community') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'title DESC' }}{{ 'fe fe-chevron-down' if sort_by == 'title ASC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="topic_id{{' ASC' if sort_by == 'topic_id DESC' else ' DESC' }}" class="btn" title="{{ _('Topic') }}">
|
||||
{{ _('Topic') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'topic_id ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'topic_id DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="post_count{{' ASC' if sort_by == 'post_count DESC' else ' DESC' }}" class="btn" title="{{ _('Sort by post count') }}">
|
||||
{{ _('Posts') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'post_count ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'post_count DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="subscriptions_count{{' ASC' if sort_by == 'subscriptions_count DESC' else ' DESC' }}" class="btn" title="{{ _('Number of known subscribers') }}">
|
||||
{{ _('Members') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'subscriptions_count ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'subscriptions_count DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="content_retention{{' ASC' if sort_by == 'content_retention DESC' else ' DESC' }}" class="btn" title="{{ _('Content retention duration') }}">
|
||||
{{ _('Retention') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'content_retention ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'content_retention DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>{{ _('Layout') }}</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="show_popular{{' ASC' if sort_by == 'show_popular DESC' else ' DESC' }}" class="btn" title="{{ _('Posts can be popular.') }}">
|
||||
{{ _('Popular') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'show_popular ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'show_popular DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="show_all{{' ASC' if sort_by == 'show_all DESC' else ' DESC' }}" class="btn" title="{{ _('Posts show in the All feed.') }}">
|
||||
{{ _('All') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'show_all ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'show_all DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="{{'nsfl ASC, nsfw ASC' if sort_by == 'nsfl DESC, nsfw DESC' else 'nsfl DESC, nsfw DESC' }}" class="btn" title="{{ _('Content warning, NSFW or NSFL set for community.') }}">
|
||||
{{ _('Warning') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'nsfl ASC, nsfw ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'nsfl DESC, nsfw DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>
|
||||
<button form="searchCommunities" name="sort_by" value="last_active{{' ASC' if sort_by == 'last_active DESC' else ' DESC' }}" class="btn" title="{{ _('Sort by recent activity') }}">
|
||||
{{ _('Active') }}
|
||||
<span class="{{ 'fe fe-chevron-up' if sort_by == 'last_active ASC' }}{{ 'fe fe-chevron-down' if sort_by == 'last_active DESC' }}"></span>
|
||||
</button>
|
||||
</th>
|
||||
<th>{{ _('Actions') }}</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% for community in communities.items %}
|
||||
<tr>
|
||||
<td>{{ render_communityname(community, add_domain=False) }}{% if community.banned %} (banned){% endif %}<br />
|
||||
!<a href="/c/{{ community.link() }}">{{ community.name }}</a><wbr />@<a href="{{ community.ap_profile_id }}">{{ community.ap_domain }}</a></td>
|
||||
<td><span title="{{ _('Topic') }}">{{ community.topic.name }}</span></td>
|
||||
<td><span title="{{ _('Number of posts') }}">{{ community.post_count }}</span></td>
|
||||
<td><span title="{{ _('Number of known subscribers') }}">{{ community.subscriptions_count }}</span></td>
|
||||
<td><span title="{{ _('Content retention duration') }}">{{ community.content_retention if community.content_retention != -1 }}</span></td>
|
||||
<td><span title="{{ _('Layout') }}">{{ community.default_layout if community.default_layout }}</span></td>
|
||||
<td><span title="{{ _('Posts can be popular.') }}">{{ '✓'|safe if community.show_popular else '✗'|safe }}</span></td>
|
||||
<td><span title="{{ _('Posts show in the All feed.') }}">{{ '✓'|safe if community.show_all else '✗'|safe }}</span></td>
|
||||
<td><span title="{{ _('Content warning, NSFW or NSFL set for community.') }}">{{ '⚠'|safe if community.nsfw or community.nsfl or community.content_warning else ''|safe }}</span></td>
|
||||
<td><span title="{{ _('Last activity') }}">{{ arrow.get(community.last_active).humanize(locale=locale) }}</span></td>
|
||||
<td><a href="{{ url_for('admin.admin_community_edit', community_id=community.id) }}">{{ _('Edit') }}</a>,
|
||||
<a href="{{ url_for('community.community_moderate', actor=community.link()) }}">{{ _('Moderate') }}</a>,
|
||||
<a href="{{ url_for('admin.admin_community_delete', community_id=community.id) }}" class="confirm_first">{{ _('Delete') }}</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
<nav aria-label="Pagination" class="mt-4" role="navigation">
|
||||
{% if prev_url %}
|
||||
<a href="{{ prev_url }}" class="btn btn-primary">
|
||||
|
|
Loading…
Reference in a new issue