From: Michael Tremer Date: Sat, 24 Jun 2023 20:12:03 +0000 (+0000) Subject: users: Merge stats from people X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dfd7b78ec91887bfbcb42338d85aa67563192954;p=ipfire.org.git users: Merge stats from people Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index 0bb18b33..f05467d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index fa41d7be..00000000 --- a/src/templates/people/stats.html +++ /dev/null @@ -1,71 +0,0 @@ -{% extends "../base.html" %} - -{% block title %}{{ _("Statistics") }}{% end block %} - -{% block container %} -
-
-

{{ _("Statistics") }}

-
-
- - {% set total_accounts = len(backend.accounts) %} - -
-
-
-
-
-
-

{{ total_accounts }}

-
{{ _("Total Accounts") }}
- -
- - {% set t = now - datetime.timedelta(days=7) %} - -

{{ backend.accounts.count_created_after(t) }}

-
{{ _("Created This Week") }}
- -
- - {% set t = now - datetime.timedelta(days=30) %} - -

{{ backend.accounts.count_created_after(t) }}

-
{{ _("Created This Month") }}
- - {% set pending_registrations = backend.accounts.pending_registrations %} - {% if pending_registrations %} -
- -

{{ pending_registrations }}

-
{{ _("Pending Registrations") }}
- {% end %} -
-
-
- -
-
-
    - {% set countries = backend.accounts.countries %} - - {% for country in sorted(countries, key=lambda c: countries[c], reverse=True) %} -
  • - - - {{ country.apolitical_name }} - - - - {{ "%.1f%%" % (countries[country] * 100 / total_accounts) }} - -
  • - {% end %} -
-
-
-
-
-
-{% end block %} diff --git a/src/templates/users/index.html b/src/templates/users/index.html index c933bd51..6fba6d3d 100644 --- a/src/templates/users/index.html +++ b/src/templates/users/index.html @@ -77,5 +77,90 @@ {% end %} + + {% if current_user and current_user.is_staff() %} + {% set total_accounts = len(backend.accounts) %} + {% set countries = backend.accounts.countries %} + + {# Stats #} + +
+
+
+
+
+

{{ _("Total Accounts") }}

+

+ {{ total_accounts }} +

+
+
+ + {% set t = now - datetime.timedelta(days=7) %} + +
+
+

{{ _("Created This Week") }}

+

+ {{ backend.accounts.count_created_after(t) }} +

+
+
+ + {% set t = now - datetime.timedelta(days=30) %} + +
+
+

{{ _("Created This Month") }}

+

+ {{ backend.accounts.count_created_after(t) }} +

+
+
+ + {% set pending_registrations = backend.accounts.pending_registrations %} + {% if pending_registrations %} +
+
+

{{ _("Pending Registrations") }}

+

+ {{ pending_registrations }} +

+
+
+ {% end %} +
+
+
+ + {# Countries #} + +
+
+

{{ _("Origin") }}

+ +
+ +
+ {% end %} {% end %} {% end block %} diff --git a/src/web/__init__.py b/src/web/__init__.py index 19ef51a3..f1b66394 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -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") }), diff --git a/src/web/people.py b/src/web/people.py index 7f12d87b..b4d68895 100644 --- a/src/web/people.py +++ b/src/web/people.py @@ -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):