]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/accounts.py
people: Show number of accounts created this week/month
[ipfire.org.git] / src / backend / accounts.py
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: