diff options
author | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-06-26 21:05:19 +0000 |
---|---|---|
committer | Joey Hagedorn <hagedorn@mcs.anl.gov> | 2007-06-26 21:05:19 +0000 |
commit | 197aa7c0997ae91b8b1210b81daf952d6c681cb2 (patch) | |
tree | 27e21db1ae081e7c1190ff42a602300b508255ba /src/lib/Server/Reports/reports/models.py | |
parent | 83d43c6957a5e392cc7d82f14329f8305ef3ca79 (diff) | |
download | bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.tar.gz bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.tar.bz2 bcfg2-197aa7c0997ae91b8b1210b81daf952d6c681cb2.zip |
updates reporting system to filter out 'expired' clients--allowing retired machines to disappear from reports
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@3373 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib/Server/Reports/reports/models.py')
-rw-r--r-- | src/lib/Server/Reports/reports/models.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/Server/Reports/reports/models.py b/src/lib/Server/Reports/reports/models.py index dff68d272..b54d83912 100644 --- a/src/lib/Server/Reports/reports/models.py +++ b/src/lib/Server/Reports/reports/models.py @@ -1,6 +1,8 @@ '''Django models for BCFG reports''' from django.db import models +from django.db.models import Q from datetime import datetime, timedelta +from time import strptime KIND_CHOICES = ( #These are the kinds of config elements @@ -16,6 +18,28 @@ PING_CHOICES = ( ('Up (Y)', 'Y'), ('Down (N)', 'N') ) +class ClientManager(models.Manager): + '''extended client manager functions''' + def active(self,timestamp='now'): + '''returns a set of clients that have been created and have not yet been + expired as of optional timestmamp argument. Timestamp should be a + string formatted in the fashion: 2006-01-01 00:00:00''' + + if timestamp=='now': + timestamp = datetime.now() + else: + print timestamp + try: + timestamp = datetime(*strptime(timestamp, "%Y-%m-%d %H:%M:%S")[0:6]) + except ValueError: + return self.filter(expiration__lt=timestamp, creation__gt=timestamp); + #this is a really hacky way to return an empty QuerySet + #this should return Client.objects.none() in Django development version. + + return self.filter(Q(expiration__gt=timestamp) | Q(expiration__isnull=True), + creation__lt=timestamp) + + class Client(models.Model): '''object representing every client we have seen stats for''' creation = models.DateTimeField() @@ -28,6 +52,8 @@ class Client(models.Model): def __str__(self): return self.name + objects = ClientManager() + class Admin: pass |