From 9a6c0d8b2833c231710d506fc7160e29654bd214 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sat, 9 Sep 2023 23:59:00 -0700 Subject: [PATCH] stats; Add total ban count to the stats page Signed-off-by: Alek Ratzloff --- chanbans/http.py | 6 ++++++ chanbans/templates/stats.html | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/chanbans/http.py b/chanbans/http.py index a15a1d6..94b7e2a 100644 --- a/chanbans/http.py +++ b/chanbans/http.py @@ -35,6 +35,11 @@ def static_url(resource: str): return f"{config.STATIC_ROOT}/{resource}" +def stats_table_total(): + return sum(row['bans'] for row in stats_table_data()) + + +@functools.cache def stats_table_data(): with get_db() as db: curs = db.execute("SELECT board, count(*) as bans FROM bans GROUP BY board") @@ -50,6 +55,7 @@ _env.globals.update( "route_url": route_url, "static_url": static_url, "stats_table_data": stats_table_data, + "stats_table_total": stats_table_total, } ) diff --git a/chanbans/templates/stats.html b/chanbans/templates/stats.html index 9708761..654cfcc 100644 --- a/chanbans/templates/stats.html +++ b/chanbans/templates/stats.html @@ -23,6 +23,10 @@ + + Total + {{stats_table_total()}} + {% for row in stats_table_data() %}