move instances list to dedicated package/blueprint

This commit is contained in:
rimu 2024-10-12 16:25:20 +13:00
parent 773ba7040c
commit 1bee5a74b7
3 changed files with 3 additions and 116 deletions

View file

@ -93,6 +93,9 @@ def create_app(config_class=Config):
from app.domain import bp as domain_bp
app.register_blueprint(domain_bp)
from app.instance import bp as instance_bp
app.register_blueprint(instance_bp)
from app.topic import bp as topic_bp
app.register_blueprint(topic_bp)

View file

@ -325,47 +325,6 @@ def list_subscribed_communities():
menu_topics=menu_topics(), site=g.site)
@bp.route('/instances', methods=['GET'])
def list_instances():
page = request.args.get('page', 1, type=int)
search = request.args.get('search', '')
filter = request.args.get('filter', '')
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}%"))
title = _('Instances')
if filter:
if filter == 'trusted':
instances = instances.filter(Instance.trusted == True)
title = _('Trusted instances')
elif filter == 'online':
instances = instances.filter(Instance.dormant == False, Instance.gone_forever == False)
title = _('Online instances')
elif filter == 'dormant':
instances = instances.filter(Instance.dormant == True, Instance.gone_forever == False)
title = _('Dormant instances')
elif filter == 'gone_forever':
instances = instances.filter(Instance.gone_forever == True)
title = _('Gone forever instances')
# 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('main.list_instances', page=instances.next_num) if instances.has_next else None
prev_url = url_for('main.list_instances', page=instances.prev_num) if instances.has_prev and page != 1 else None
return render_template('list_instances.html', instances=instances,
title=title, search=search, filter=filter,
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('/modlog', methods=['GET'])
def modlog():
page = request.args.get('page', 1, type=int)

View file

@ -1,75 +0,0 @@
{% 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 %}
{% block app_content %}
<div class="row">
<div class="col-12 col-md-8 position-relative main_pane">
{% if search == '' %}
<h1>{{ title }}</h1>
{% else %}
<h1>{{ title }}</h1>
{% endif %}
<form method="get">
<input type="search" name="search" value="{{ search }}"> <input type="submit" name="submit" value="{{ _('Search') }}">
</form>
<a href="{{ url_for('main.list_instances', filter='online') }}" rel="nofollow noindex">{{ _('Online') }}</a> |
<a href="{{ url_for('main.list_instances', filter='dormant') }}" rel="nofollow noindex">{{ _('Dormant') }}</a> |
<a href="{{ url_for('main.list_instances', filter='gone_forever') }}" rel="nofollow noindex">{{ _('Gone forever') }}</a> |
<a href="{{ url_for('main.list_instances', filter='trusted') }}" rel="nofollow noindex">{{ _('Trusted') }}</a>
{% if instances -%}
<div class="table-responsive-sm pt-4">
<table class="table table-striped">
<tr>
<th>{{ _('Instance') }}</th>
<th>{{ _('Software') }}</th>
<th>{{ _('Version') }}</th>
<th>{{ _('Heard from') }}</th>
<th>{{ _('Sent to') }}</th>
<th>{{ _('Online') }}</th>
</tr>
{% for instance in instances %}
<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>{{ 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>{% if instance.dormant and instance.gone_forever -%}
{{ _('Gone') }}
{% elif instance.dormant -%}
{{ _('Dormant') }}
{% else -%}
{{ _('Online') }}
{% endif -%}
</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" rel="nofollow">
<span aria-hidden="true">&larr;</span> {{ _('Previous page') }}
</a>
{% endif %}
{% if next_url %}
<a href="{{ next_url }}" class="btn btn-primary" rel="nofollow">
{{ _('Next page') }} <span aria-hidden="true">&rarr;</span>
</a>
{% endif %}
</nav>
{% else -%}
<p>{{ _('No results to show.') }}</p>
{% endif %}
</div>
</div>
{% endblock %}