From 915f1047d669143bc65aeb3163617d7b322f3719 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Fri, 18 Mar 2022 23:29:41 -0700 Subject: [PATCH] show active nodes by default --- xmrnodes/app.py | 33 ++++++++++++++++++++++++--------- xmrnodes/templates/index.html | 11 ++++++++++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/xmrnodes/app.py b/xmrnodes/app.py index 96ef7f6..26454a3 100644 --- a/xmrnodes/app.py +++ b/xmrnodes/app.py @@ -12,7 +12,7 @@ import requests import click from flask import Flask, request, redirect, jsonify from flask import render_template, flash, url_for -from urllib.parse import urlparse +from urllib.parse import urlparse, urlencode from xmrnodes.helpers import determine_crypto, is_onion, make_request from xmrnodes.helpers import retrieve_peers, rw_cache @@ -36,13 +36,20 @@ def index(): nettype = request.args.get("nettype", "mainnet") crypto = request.args.get("crypto", "monero") onion = request.args.get("onion", False) + show_all = "true" == request.args.get("all", "false") nodes = Node.select().where( - Node.validated==True - ).where( - Node.nettype==nettype - ).where( - Node.crypto==crypto - ).order_by( + Node.validated == True, + Node.nettype == nettype, + Node.crypto == crypto + ) + + nodes_all = nodes.count() + nodes_unhealthy = nodes.where(Node.available == False).count() + + if not show_all: + nodes = nodes.where(Node.available == True) + + nodes = nodes.order_by( Node.datetime_entered.desc() ) if onion: @@ -54,8 +61,10 @@ def index(): return render_template( "index.html", nodes=nodes, - nodes_healthy=[n for n in nodes if n.available], - nodes_unhealthy=[n for n in nodes if not n.available], + nodes_all=nodes_all, + nodes_unhealthy=nodes_unhealthy, + nettype=nettype, + crypto=crypto, form=form ) @@ -313,5 +322,11 @@ def hours_elapsed(d): diff = now - d return diff.total_seconds() / 60 / 60 +@app.template_filter("pop_arg") +def trim_arg(all_args, arg_to_trim): + d = all_args.to_dict() + d.pop(arg_to_trim) + return urlencode(d) + if __name__ == "__main__": app.run() diff --git a/xmrnodes/templates/index.html b/xmrnodes/templates/index.html index 91e1675..a8b0ae8 100644 --- a/xmrnodes/templates/index.html +++ b/xmrnodes/templates/index.html @@ -40,7 +40,16 @@
{% if nodes %}
-

Currently tracking {{ nodes | length }} nodes in the database. Of those, {{ nodes_unhealthy | length }} nodes failed their last check-in.

+

+ Tracking {{ nodes_all }} {{ nettype }} {{ crypto | capitalize }} nodes in the database. Of those, {{ nodes_unhealthy }} nodes failed their last check-in. +

+

Showing {{ nodes | length }} nodes. + {% if 'all' not in request.args %} + Show All + {% else %} + Show Active + {% endif %} +