]> git.ipfire.org Git - ipfire.org.git/commitdiff
people: Show number of accounts created this week/month
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Nov 2019 10:45:22 +0000 (10:45 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 22 Nov 2019 10:45:22 +0000 (10:45 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/templates/people/stats.html

index ff2988c1a4879ae91fb5c3bd4ae2d965f64451eb..8dcb051576a964ca0fee53ae35a55ed169dfd1da 100644 (file)
@@ -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:
index 9b546e3202a89e49cf047c020f06ad3e844406cb..2cebfd1c58788f7020713bfcfad5fa0a78c99cf5 100644 (file)
@@ -7,10 +7,24 @@
 
        <div class="row">
                <div class="col-12 col-lg-3">
-                       <div class="card">
+                       <div class="card mb-3">
                                <div class="card-body text-center">
                                        <h1>{{ len(backend.accounts) }}</h1>
-                                       <h5 class="mb-0">{{ _("Total Accounts") }}</h5>
+                                       <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>
                                </div>
                        </div>
                </div>