]> git.ipfire.org Git - ipfire.org.git/commitdiff
users: Merge stats from people
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Jun 2023 20:12:03 +0000 (20:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 24 Jun 2023 20:12:03 +0000 (20:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/templates/people/stats.html [deleted file]
src/templates/users/index.html
src/web/__init__.py
src/web/people.py

index 0bb18b3349eededec53da019e6a09bccdffd39db..f05467d04937a536263b22bdca21c1d9b51e9b9c 100644 (file)
@@ -268,7 +268,6 @@ templates_people_DATA = \
        src/templates/people/index.html \
        src/templates/people/passwd.html \
        src/templates/people/sip.html \
-       src/templates/people/stats.html \
        src/templates/people/subscribed.html \
        src/templates/people/unsubscribe.html \
        src/templates/people/unsubscribed.html \
diff --git a/src/templates/people/stats.html b/src/templates/people/stats.html
deleted file mode 100644 (file)
index fa41d7b..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-{% extends "../base.html" %}
-
-{% block title %}{{ _("Statistics") }}{% end block %}
-
-{% block container %}
-       <div class="header">
-               <div class="container">
-                       <h1>{{ _("Statistics") }}</h1>
-               </div>
-       </div>
-
-       {% set total_accounts = len(backend.accounts) %}
-
-       <div class="container">
-               <section>
-                       <div class="row">
-                               <div class="col-12 col-lg-3">
-                                       <div class="card mb-3">
-                                               <div class="card-body text-center">
-                                                       <h1>{{ total_accounts }}</h1>
-                                                       <h5>{{ _("Total Accounts") }}</h5>
-
-                                                       <hr>
-
-                                                       {% set t = now - datetime.timedelta(days=7) %}
-
-                                                       <h1>{{ backend.accounts.count_created_after(t) }}</h1>
-                                                       <h5 class="mb-0">{{ _("Created This Week") }}</h5>
-
-                                                       <hr>
-
-                                                       {% set t = now - datetime.timedelta(days=30) %}
-
-                                                       <h1>{{ backend.accounts.count_created_after(t) }}</h1>
-                                                       <h5 class="mb-0">{{ _("Created This Month") }}</h5>
-
-                                                       {% set pending_registrations = backend.accounts.pending_registrations %}
-                                                       {% if pending_registrations %}
-                                                               <hr>
-
-                                                               <h1>{{ pending_registrations }}</h1>
-                                                               <h5 class="mb-0">{{ _("Pending Registrations") }}</h5>
-                                                       {% end %}
-                                               </div>
-                                       </div>
-                               </div>
-
-                               <div class="col-12 col-lg-9">
-                                       <div class="card">
-                                               <ul class="list-group list-group-flush">
-                                                       {% set countries = backend.accounts.countries %}
-
-                                                       {% for country in sorted(countries, key=lambda c: countries[c], reverse=True) %}
-                                                               <li class="list-group-item d-flex justify-content-between align-items-center">
-                                                                       <span>
-                                                                               <span class="flag-icon flag-icon-{{ country.alpha2.lower() }} small mr-1"></span>
-                                                                               {{ country.apolitical_name }}
-                                                                       </span>
-
-                                                                       <span class="badge bg-primary" title="{{ countries[country] }}">
-                                                                               {{ "%.1f%%" % (countries[country] * 100 / total_accounts) }}
-                                                                       </span>
-                                                               </li>
-                                                       {% end %}
-                                               </ul>
-                                       </div>
-                               </div>
-                       </div>
-               </section>
-       </div>
-{% end block %}
index c933bd51af03f0dedd2b97dc15d18822cfcd0c5e..6fba6d3d05c19c1f624546e588551229d2a8df0b 100644 (file)
                                </div>
                        </section>
                {% end %}
+
+               {% if current_user and current_user.is_staff() %}
+                       {% set total_accounts = len(backend.accounts) %}
+                       {% set countries = backend.accounts.countries %}
+
+                       {# Stats #}
+
+                       <section class="section">
+                               <div class="container">
+                                       <div class="level">
+                                               <div class="level-item has-text-centered">
+                                                       <div>
+                                                               <p class="heading">{{ _("Total Accounts") }}</p>
+                                                               <p class="title">
+                                                                       {{ total_accounts }}
+                                                               </p>
+                                                       </div>
+                                               </div>
+
+                                               {% set t = now - datetime.timedelta(days=7) %}
+
+                                               <div class="level-item has-text-centered">
+                                                       <div>
+                                                               <p class="heading">{{ _("Created This Week") }}</p>
+                                                               <p class="title">
+                                                                       {{ backend.accounts.count_created_after(t) }}
+                                                               </p>
+                                                       </div>
+                                               </div>
+
+                                               {% set t = now - datetime.timedelta(days=30) %}
+
+                                               <div class="level-item has-text-centered">
+                                                       <div>
+                                                               <p class="heading">{{ _("Created This Month") }}</p>
+                                                               <p class="title">
+                                                                       {{ backend.accounts.count_created_after(t) }}
+                                                               </p>
+                                                       </div>
+                                               </div>
+
+                                               {% set pending_registrations = backend.accounts.pending_registrations %}
+                                               {% if pending_registrations %}
+                                                       <div class="level-item has-text-centered">
+                                                               <div>
+                                                                       <p class="heading">{{ _("Pending Registrations") }}</p>
+                                                                       <p class="title">
+                                                                               {{ pending_registrations }}
+                                                                       </p>
+                                                               </div>
+                                                       </div>
+                                               {% end %}
+                                       </div>
+                               </div>
+                       </section>
+
+                       {# Countries #}
+
+                       <section class="section">
+                               <div class="container">
+                                       <h4 class="title is-4">{{ _("Origin") }}</h4>
+
+                                       <nav class="panel">
+                                               {% for country in sorted(countries, key=lambda c: countries[c], reverse=True) %}
+                                                       {% set percentage = countries[country] / total_accounts %}
+
+                                                       <div class="panel-block is-justify-content-space-between">
+                                                               <span>
+                                                                       <span class="panel-icon">
+                                                                               <i class="flag-icon flag-icon-{{ country.alpha2.lower() }}"
+                                                                                       aria-hidden="true"></i>
+                                                                       </span>
+
+                                                                       {{ country.apolitical_name }}
+                                                               </span>
+
+                                                               <span class="tag">
+                                                                       {{ "%.1f%%" % (percentage * 100) }}
+                                                               </span>
+                                                       </div>
+                                               {% end %}
+                                       </div>
+                               </div>
+                       </section>
+               {% end %}
        {% end %}
 {% end block %}
index 19ef51a3b8f5c33503113e591f234bbf416fc889..f1b66394910300195d01fd6d24c598485531718c 100644 (file)
@@ -321,9 +321,6 @@ class Application(tornado.web.Application):
                        (r"/password\-reset", auth.PasswordResetInitiationHandler),
                        (r"/password\-reset/([a-z_][a-z0-9_-]{0,31})/(\w+)", auth.PasswordResetHandler),
 
-                       # Stats
-                       (r"/stats", people.StatsHandler),
-
                        # Serve any static files
                        (r"/static/(.*)", tornado.web.StaticFileHandler, { "path" : self.settings.get("static_path") }),
 
index 7f12d87b83e6857fe9262fe446bb4db2e8854630..b4d688954fc01378d58c21e19c67018544b7a0a0 100644 (file)
@@ -90,16 +90,6 @@ class GroupHandler(auth.CacheMixin, base.BaseHandler):
                self.render("people/group.html", group=group)
 
 
-class StatsHandler(auth.CacheMixin, base.BaseHandler):
-       @tornado.web.authenticated
-       def get(self):
-               # Only staff can see stats
-               if not self.current_user.is_staff():
-                       raise tornado.web.HTTPError(403)
-
-               self.render("people/stats.html")
-
-
 class SubscribeHandler(auth.CacheMixin, base.BaseHandler):
        @tornado.web.authenticated
        def post(self):