From 1bee5a74b7deb455977cc528a67310692d70113e Mon Sep 17 00:00:00 2001 From: rimu <3310831+rimu@users.noreply.github.com> Date: Sat, 12 Oct 2024 16:25:20 +1300 Subject: [PATCH] move instances list to dedicated package/blueprint --- app/__init__.py | 3 ++ app/main/routes.py | 41 ----------------- app/templates/list_instances.html | 75 ------------------------------- 3 files changed, 3 insertions(+), 116 deletions(-) delete mode 100644 app/templates/list_instances.html diff --git a/app/__init__.py b/app/__init__.py index 48a6802c..d3784cbd 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -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) diff --git a/app/main/routes.py b/app/main/routes.py index d80c1d00..50f6cb66 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -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) diff --git a/app/templates/list_instances.html b/app/templates/list_instances.html deleted file mode 100644 index 201212f8..00000000 --- a/app/templates/list_instances.html +++ /dev/null @@ -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 %} -
{{ _('Instance') }} | -{{ _('Software') }} | -{{ _('Version') }} | -{{ _('Heard from') }} | -{{ _('Sent to') }} | -{{ _('Online') }} | -
---|---|---|---|---|---|
{{ instance.domain }} | -{{ instance.software }} | -{{ instance.version if instance.version }} | -{{ arrow.get(instance.last_seen).humanize(locale=locale) if instance.last_seen }} | -{{ arrow.get(instance.last_successful_send).humanize(locale=locale) if instance.last_successful_send }} | -{% if instance.dormant and instance.gone_forever -%} - {{ _('Gone') }} - {% elif instance.dormant -%} - {{ _('Dormant') }} - {% else -%} - {{ _('Online') }} - {% endif -%} - | -
{{ _('No results to show.') }}
- {% endif %} -