From: Michael Tremer Date: Fri, 22 Nov 2019 10:45:22 +0000 (+0000) Subject: people: Show number of accounts created this week/month X-Git-Url: http://git.ipfire.org/?p=ipfire.org.git;a=commitdiff_plain;h=e3f34bb57584aaaed2c4926e77e88b91df90e68e people: Show number of accounts created this week/month Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index ff2988c1..8dcb0515 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -160,6 +160,10 @@ class LDAPObject(Object): def objectclasses(self): return self._get_strings("objectClass") + @staticmethod + def _parse_date(s): + return datetime.datetime.strptime(s.decode(), "%Y%m%d%H%M%SZ") + class Accounts(Object): def init(self): @@ -251,10 +255,15 @@ class Accounts(Object): return Account(self.backend, dn, attrs) + @staticmethod + def _format_date(t): + return t.strftime("%Y%m%d%H%M%SZ") + def get_created_after(self, ts): - t = ts.strftime("%Y%m%d%H%M%SZ") + return self._search("(&(objectClass=person)(createTimestamp>=%s))" % self._format_date(ts)) - return self._search("(&(objectClass=person)(createTimestamp>=%s))" % t) + def count_created_after(self, ts): + return self._count("(&(objectClass=person)(createTimestamp>=%s))" % self._format_date(ts)) def search(self, query): accounts = self._search("(&(objectClass=person)(|(cn=*%s*)(uid=*%s*)(displayName=*%s*)(mail=*%s*)))" \ @@ -567,10 +576,6 @@ class Account(LDAPObject): return {} - @staticmethod - def _parse_date(s): - return datetime.datetime.strptime(s.decode(), "%Y%m%d%H%M%SZ") - @property def last_successful_authentication(self): try: diff --git a/src/templates/people/stats.html b/src/templates/people/stats.html index 9b546e32..2cebfd1c 100644 --- a/src/templates/people/stats.html +++ b/src/templates/people/stats.html @@ -7,10 +7,24 @@
-
+

{{ 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") }}