mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-03 00:31:25 -08:00
Merge pull request 'Adding admin.instances page' (#319) from JollyDevelopment/pyfedi:jollydev/admin-instances-overview into main
Reviewed-on: https://codeberg.org/rimu/pyfedi/pulls/319
This commit is contained in:
commit
f284be0b39
4 changed files with 183 additions and 1 deletions
|
@ -962,4 +962,92 @@ def admin_permissions():
|
|||
joined_communities=joined_communities(current_user.get_id()),
|
||||
menu_topics=menu_topics(),
|
||||
site=g.site
|
||||
)
|
||||
)
|
||||
|
||||
@bp.route('/instances', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@permission_required('change instance settings')
|
||||
def admin_instances():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
search = request.args.get('search', '')
|
||||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
|
||||
if search:
|
||||
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
|
||||
|
||||
# Pagination
|
||||
instances = instances.paginate(page=page,
|
||||
per_page=250 if current_user.is_authenticated and not low_bandwidth else 50,
|
||||
error_out=False)
|
||||
next_url = url_for('admin.admin_instances', page=instances.next_num) if instances.has_next else None
|
||||
prev_url = url_for('admin.admin_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
|
||||
|
||||
return render_template('admin/instances.html', instances=instances,
|
||||
title=_('Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
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)
|
||||
|
||||
@bp.route('/instances/dormant', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@permission_required('change instance settings')
|
||||
def admin_instances_dormant():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
search = request.args.get('search', '')
|
||||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
|
||||
instances = instances.filter(Instance.dormant == True)
|
||||
|
||||
if search:
|
||||
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
|
||||
|
||||
# Pagination
|
||||
instances = instances.paginate(page=page,
|
||||
per_page=250 if current_user.is_authenticated and not low_bandwidth else 50,
|
||||
error_out=False)
|
||||
next_url = url_for('admin.admin_instances', page=instances.next_num) if instances.has_next else None
|
||||
prev_url = url_for('admin.admin_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
|
||||
|
||||
return render_template('admin/instances.html', instances=instances,
|
||||
title=_('Dormant Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
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)
|
||||
|
||||
@bp.route('/instances/gone-forever', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@permission_required('change instance settings')
|
||||
def admin_instances_gone_forever():
|
||||
page = request.args.get('page', 1, type=int)
|
||||
search = request.args.get('search', '')
|
||||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||
|
||||
instances = Instance.query.order_by(Instance.domain)
|
||||
|
||||
instances = instances.filter(Instance.gone_forever == True)
|
||||
|
||||
if search:
|
||||
instances = instances.filter(Instance.domain.ilike(f"%{search}%"))
|
||||
|
||||
# Pagination
|
||||
instances = instances.paginate(page=page,
|
||||
per_page=250 if current_user.is_authenticated and not low_bandwidth else 50,
|
||||
error_out=False)
|
||||
next_url = url_for('admin.admin_instances', page=instances.next_num) if instances.has_next else None
|
||||
prev_url = url_for('admin.admin_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
|
||||
|
||||
return render_template('admin/instances.html', instances=instances,
|
||||
title=_('Gone Forever Instances'), search=search,
|
||||
next_url=next_url, prev_url=prev_url,
|
||||
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)
|
|
@ -84,6 +84,20 @@ class Instance(db.Model):
|
|||
def votes_are_public(self):
|
||||
return self.software.lower() == 'lemmy' or self.software.lower() == 'mbin' or self.software.lower() == 'kbin'
|
||||
|
||||
# the db execute returns a cursorresult. the all() returns a list with one item in it.
|
||||
# the [0] gets the one sqlalchemy Row object, the Row.count then is the number we show
|
||||
def post_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM post WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def post_replies_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM post_reply WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def known_communities_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM community WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def known_users_count(self):
|
||||
return db.session.execute(text(f'SELECT count(*) FROM "user" WHERE instance_id = {self.id}')).all()[0].count
|
||||
|
||||
def __repr__(self):
|
||||
return '<Instance {}>'.format(self.domain)
|
||||
|
||||
|
|
79
app/templates/admin/instances.html
Normal file
79
app/templates/admin/instances.html
Normal file
|
@ -0,0 +1,79 @@
|
|||
{% if theme() and file_exists('app/templates/themes/' + theme() + '/base.html') %}
|
||||
{% extends 'themes/' + theme() + '/base.html' %}
|
||||
{% else %}
|
||||
{% extends "base.html" %}
|
||||
{% endif %}
|
||||
{% from 'bootstrap/form.html' import render_form %}
|
||||
{% set active_child = 'admin_instances' %}
|
||||
|
||||
{% block app_content %}
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1>{{ title }}</h1>
|
||||
<form method="get">
|
||||
<input type="search" name="search"> <input type="submit" name="submit" value="Search">
|
||||
</form>
|
||||
Status Filter:
|
||||
<a href="{{ url_for('admin.admin_instances') }}">Online</a> |
|
||||
<a href="{{ url_for('admin.admin_instances_dormant') }}">Dormant</a> |
|
||||
<a href="{{ url_for('admin.admin_instances_gone_forever') }}">Gone Forever</a> |
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>Domain</th>
|
||||
<th>Software</th>
|
||||
<th>Version</th>
|
||||
<th title="{{ _('Known Communities') }}">Communities</td>
|
||||
<th title="{{ _('Known Users') }}">Users</td>
|
||||
<th>Posts</th>
|
||||
<th>Post Replies</th>
|
||||
<th>Vote Weight</th>
|
||||
<th title="{{ _('When an Activity was received from them') }}">Seen</th>
|
||||
<th title="{{ _('When we successfully sent them an Activity') }}">Sent</th>
|
||||
<th title="{{ _('How many times we failed to send (reset to 0 after every successful send)') }}">Failed</th>
|
||||
<th title="{{ _('Instance Status - Online/Dormant/Gone Forever') }}">Status</th>
|
||||
</tr>
|
||||
{% for instance in instances.items %}
|
||||
<tr>
|
||||
<td><a href="https://{{ instance.domain }}" rel="noopener nofollow noindex noreferrer">{{ instance.domain }}</a></td>
|
||||
<td>{{ instance.software }}</td>
|
||||
<td>{{ instance.version if instance.version }}</td>
|
||||
<td>{{ instance.known_communities_count() }}</td>
|
||||
<td>{{ instance.known_users_count() }}</td>
|
||||
<td>{{ instance.post_count() }}</td>
|
||||
<td>{{ instance.post_replies_count() }}</td>
|
||||
<td>{{ instance.vote_weight }}</td>
|
||||
<td>{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }}</td>
|
||||
<td>{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }}</td>
|
||||
<td>{{ instance.failures }}</td>
|
||||
{% if instance.gone_forever %}
|
||||
<td>Gone Forever</td>
|
||||
{% elif instance.dormant %}
|
||||
<td>Dormant</td>
|
||||
{% else %}
|
||||
<td>Online</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<nav aria-label="Pagination" class="mt-4" role="navigation">
|
||||
{% if prev_url %}
|
||||
<a href="{{ prev_url }}" class="btn btn-primary">
|
||||
<span aria-hidden="true">←</span> {{ _('Previous page') }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if next_url %}
|
||||
<a href="{{ next_url }}" class="btn btn-primary">
|
||||
{{ _('Next page') }} <span aria-hidden="true">→</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{% include 'admin/_nav.html' %}
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
{% endblock %}
|
|
@ -206,6 +206,7 @@
|
|||
<ul class="dropdown-menu">
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_site' }}" href="{{ url_for('admin.admin_site') }}">{{ _('Site profile') }}</a></li>
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_misc' }}" href="{{ url_for('admin.admin_misc') }}">{{ _('Misc settings') }}</a></li>
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_instances' }}" href="{{ url_for('admin.admin_instances') }}">{{ _('Instances') }}</a></li>
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_communities' }}" href="{{ url_for('admin.admin_communities') }}">{{ _('Communities') }}</a></li>
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_topics' }}" href="{{ url_for('admin.admin_topics') }}">{{ _('Topics') }}</a></li>
|
||||
<li><a class="dropdown-item{{ ' active' if active_child == 'admin_users' }}" href="{{ url_for('admin.admin_users', local_remote='local') }}">{{ _('Users') }}</a></li>
|
||||
|
|
Loading…
Add table
Reference in a new issue