diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Server/Reports/reports/models_new.py | 47 | ||||
-rw-r--r-- | src/lib/Server/Reports/reports/models_old.py | 42 | ||||
-rw-r--r-- | src/lib/Server/Reports/reports/views.py | 5 |
3 files changed, 54 insertions, 40 deletions
diff --git a/src/lib/Server/Reports/reports/models_new.py b/src/lib/Server/Reports/reports/models_new.py index 40236e79b..5410ce37b 100644 --- a/src/lib/Server/Reports/reports/models_new.py +++ b/src/lib/Server/Reports/reports/models_new.py @@ -1,4 +1,4 @@ -'''Django models for BCFG reports''' +"""Django models for Bcfg2 reports.""" from django.db import models from django.db.models import Q from datetime import datetime, timedelta @@ -28,7 +28,7 @@ TYPE_CHOICES = ( (TYPE_EXTRA, 'Extra'), ) class ClientManager(models.Manager): - '''extended client manager functions''' + """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 @@ -53,7 +53,7 @@ class ClientManager(models.Manager): class Client(models.Model): - '''object representing every client we have seen stats for''' + """Object representing every client we have seen stats for.""" creation = models.DateTimeField() name = models.CharField(max_length=128,) current_interaction = models.ForeignKey('Interaction', @@ -70,7 +70,7 @@ class Client(models.Model): pass class Ping(models.Model): - '''represents a ping of a client (sparsely)''' + """Represents a ping of a client (sparsely).""" client = models.ForeignKey(Client, related_name="pings") starttime = models.DateTimeField() endtime = models.DateTimeField() @@ -80,13 +80,17 @@ class Ping(models.Model): get_latest_by = 'endtime' class InteractiveManager(models.Manager): - '''manages interactions objects''' + """Manages interactions objects. - '''returns most recent interaction as of specified timestamp in format: - '2006-01-01 00:00:00' or 'now' or None->'now' ''' + Returns most recent interaction as of specified timestamp in format: + '2006-01-01 00:00:00' or 'now' or None->'now' + + """ def interaction_per_client(self, maxdate = None): - '''Returns the most recent interactions for clients as of a date''' - '''FIXME - check the dates passed in''' + """Returns the most recent interactions for clients as of a date. + FIXME - check the dates passed in. + + """ from django.db import connection cursor = connection.cursor() @@ -105,7 +109,7 @@ class InteractiveManager(models.Manager): class Interaction(models.Model): - '''Models each reconfiguration operation interaction between client and server''' + """Models each reconfiguration operation interaction between client and server.""" client = models.ForeignKey(Client, related_name="interactions",) timestamp = models.DateTimeField()#Timestamp for this record state = models.CharField(max_length=32)#good/bad/modified/etc @@ -166,7 +170,7 @@ class Interaction(models.Model): return Entries_interactions.objects.select_related().filter(interaction=self, type=TYPE_BAD) def bad_entry_count(self): - '''Number of bad entries. Store the count in the interation field to save db queries''' + """Number of bad entries. Store the count in the interation field to save db queries.""" if self.bad_entries < 0: self.bad_entries = Entries_interactions.objects.filter(interaction=self, type=TYPE_BAD).count() self.save() @@ -176,7 +180,7 @@ class Interaction(models.Model): return Entries_interactions.objects.select_related().filter(interaction=self, type=TYPE_MODIFIED) def modified_entry_count(self): - '''Number of modified entries. Store the count in the interation field to save db queries''' + """Number of modified entries. Store the count in the interation field to save db queries.""" if self.modified_entries < 0: self.modified_entries = Entries_interactions.objects.filter(interaction=self, type=TYPE_MODIFIED).count() self.save() @@ -186,7 +190,7 @@ class Interaction(models.Model): return Entries_interactions.objects.select_related().filter(interaction=self, type=TYPE_EXTRA) def extra_entry_count(self): - '''Number of extra entries. Store the count in the interation field to save db queries''' + """Number of extra entries. Store the count in the interation field to save db queries.""" if self.extra_entries < 0: self.extra_entries = Entries_interactions.objects.filter(interaction=self, type=TYPE_EXTRA).count() self.save() @@ -203,7 +207,7 @@ class Interaction(models.Model): unique_together = ("client", "timestamp") class Reason(models.Model): - '''reason why modified or bad entry did not verify, or changed''' + """reason why modified or bad entry did not verify, or changed.""" owner = models.TextField(max_length=128, blank=True) current_owner = models.TextField(max_length=128, blank=True) group = models.TextField(max_length=128, blank=True) @@ -222,7 +226,7 @@ class Reason(models.Model): return "Reason" class Entries(models.Model): - """ Contains all the entries feed by the client """ + """Contains all the entries feed by the client.""" name = models.CharField(max_length=128, db_index=True) kind = models.CharField(max_length=16, choices=KIND_CHOICES, db_index=True) @@ -230,15 +234,18 @@ class Entries(models.Model): return self.name class Entries_interactions(models.Model): - """ Define the relation between the reason, the interaction and the entry """ + """Define the relation between the reason, the interaction and the entry.""" entry = models.ForeignKey(Entries) reason = models.ForeignKey(Reason) interaction = models.ForeignKey(Interaction) type = models.IntegerField(choices=TYPE_CHOICES) class PerformanceManager(models.Manager): - '''Provides ability to effectively query for performance information - It is possible this should move to the view''' + """ + Provides ability to effectively query for performance information + It is possible this should move to the view + + """ #Date format for maxdate: '2006-01-01 00:00:00' def performance_per_client(self, maxdate = None): from django.db import connection @@ -270,7 +277,7 @@ class PerformanceManager(models.Manager): #performance metrics, models a performance-metric-item class Performance(models.Model): - '''Object representing performance data for any interaction''' + """Object representing performance data for any interaction.""" interaction = models.ManyToManyField(Interaction, related_name="performance_items") metric = models.CharField(max_length=128) value = models.DecimalField(max_digits=32, decimal_places=16) @@ -280,7 +287,7 @@ class Performance(models.Model): objects = PerformanceManager() class InternalDatabaseVersion(models.Model): - '''Object that tell us to witch version is the database''' + """Object that tell us to witch version is the database.""" version = models.IntegerField() updated = models.DateTimeField(auto_now_add=True) diff --git a/src/lib/Server/Reports/reports/models_old.py b/src/lib/Server/Reports/reports/models_old.py index 9ff15485a..d3963babb 100644 --- a/src/lib/Server/Reports/reports/models_old.py +++ b/src/lib/Server/Reports/reports/models_old.py @@ -1,4 +1,4 @@ -'''Django models for BCFG reports''' +"""Django models for Bcfg2 reports.""" from django.db import models from django.db.models import Q from datetime import datetime, timedelta @@ -28,12 +28,14 @@ TYPE_CHOICES = ( (TYPE_EXTRA, 'Extra'), ) class ClientManager(models.Manager): - '''extended client manager functions''' + """Extended client manager functions.""" + def active(self, timestamp='now'): - '''returns a set of clients that have been created and have not yet been + """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''' - + string formatted in the fashion: 2006-01-01 00:00:00 + + """ if timestamp == 'now': timestamp = datetime.now() else: @@ -53,7 +55,7 @@ class ClientManager(models.Manager): class Client(models.Model): - '''object representing every client we have seen stats for''' + """Object representing every client we have seen stats for.""" creation = models.DateTimeField() name = models.CharField(maxlength=128, core=True) current_interaction = models.ForeignKey('Interaction', @@ -70,7 +72,7 @@ class Client(models.Model): pass class Ping(models.Model): - '''represents a ping of a client (sparsely)''' + """Represents a ping of a client (sparsely).""" client = models.ForeignKey(Client, related_name="pings") starttime = models.DateTimeField() endtime = models.DateTimeField() @@ -80,10 +82,12 @@ class Ping(models.Model): get_latest_by = 'endtime' class InteractiveManager(models.Manager): - '''manages interactions objects''' + """Manages interactions objects - '''returns most recent interaction as of specified timestamp in format: - '2006-01-01 00:00:00' or 'now' or None->'now' ''' + Returns most recent interaction as of specified timestamp in format: + '2006-01-01 00:00:00' or 'now' or None->'now' + + """ def interaction_per_client(self, maxdate = None): from django.db import connection cursor = connection.cursor() @@ -107,7 +111,7 @@ class InteractiveManager(models.Manager): class Interaction(models.Model): - '''Models each reconfiguration operation interaction between client and server''' + """Models each reconfiguration operation interaction between client and server.""" client = models.ForeignKey(Client, related_name="interactions", core=True) timestamp = models.DateTimeField()#Timestamp for this record state = models.CharField(maxlength=32)#good/bad/modified/etc @@ -181,7 +185,7 @@ class Interaction(models.Model): get_latest_by = 'timestamp' class Reason(models.Model): - '''reason why modified or bad entry did not verify, or changed''' + """Reason why modified or bad entry did not verify, or changed.""" owner = models.TextField(maxlength=128, blank=True) current_owner = models.TextField(maxlength=128, blank=True) group = models.TextField(maxlength=128, blank=True) @@ -200,7 +204,7 @@ class Reason(models.Model): return "Reason" class Entries(models.Model): - """ Contains all the entries feed by the client """ + """Contains all the entries feed by the client.""" name = models.CharField(maxlength=128, core=True, db_index=True) kind = models.CharField(maxlength=16, choices=KIND_CHOICES, db_index=True) @@ -208,15 +212,17 @@ class Entries(models.Model): return self.name class Entries_interactions(models.Model): - """ Define the relation between the reason, the interaction and the entry """ + """Define the relation between the reason, the interaction and the entry.""" entry = models.ForeignKey(Entries) reason = models.ForeignKey(Reason) interaction = models.ForeignKey(Interaction) type = models.IntegerField(choices=TYPE_CHOICES) class PerformanceManager(models.Manager): - '''Provides ability to effectively query for performance information - It is possible this should move to the view''' + """Provides ability to effectively query for performance information. + It is possible this should move to the view. + + """ #Date format for maxdate: '2006-01-01 00:00:00' def performance_per_client(self, maxdate = None): from django.db import connection @@ -248,7 +254,7 @@ class PerformanceManager(models.Manager): #performance metrics, models a performance-metric-item class Performance(models.Model): - '''Object representing performance data for any interaction''' + """Object representing performance data for any interaction.""" interaction = models.ManyToManyField(Interaction, related_name="performance_items") metric = models.CharField(maxlength=128, core=True) value = models.FloatField(max_digits=32, decimal_places=16) @@ -258,7 +264,7 @@ class Performance(models.Model): objects = PerformanceManager() class InternalDatabaseVersion(models.Model): - '''Object that tell us to witch version is the database''' + """Object that tell us to witch version is the database.""" version = models.IntegerField() updated = models.DateTimeField(auto_now_add=True) diff --git a/src/lib/Server/Reports/reports/views.py b/src/lib/Server/Reports/reports/views.py index eea847bf4..230e0a503 100644 --- a/src/lib/Server/Reports/reports/views.py +++ b/src/lib/Server/Reports/reports/views.py @@ -111,10 +111,11 @@ def client_index(request, timestamp = 'now'): 'timestamp_time' : timestamp[11:19]}) def client_detailed_list(request, **kwargs): - ''' + """ Provides a more detailed list view of the clients. Allows for extra filters to be passed in. Somewhat clunky now that dates are allowed. - ''' + + """ context = dict(path=request.path) timestamp = 'now' entry_max = datetime.now() |