From 933ee881721e8651a0a6dff009500ec06552d2ac Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 29 Jan 2019 17:19:04 -0600 Subject: [PATCH] Improve rendering of `enabled` field for tempmon clients, probes to make it more clear, when disabled --- tailbone/views/tempmon/clients.py | 15 ++++++++++++++- tailbone/views/tempmon/probes.py | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tailbone/views/tempmon/clients.py b/tailbone/views/tempmon/clients.py index f455d0f8..1952c56d 100644 --- a/tailbone/views/tempmon/clients.py +++ b/tailbone/views/tempmon/clients.py @@ -36,6 +36,7 @@ from webhelpers2.html import HTML, tags from tailbone import forms from tailbone.views.tempmon import MasterView +from tailbone.util import raw_datetime class TempmonClientView(MasterView): @@ -103,12 +104,17 @@ class TempmonClientView(MasterView): g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE) # enabled - g.set_type('enabled', 'boolean') + g.set_renderer('enabled', self.render_enabled_grid) # archived g.filters['archived'].default_active = True g.filters['archived'].default_verb = 'is_false' + def render_enabled_grid(self, client, field): + if client.enabled: + return "Yes" + return "No" + def configure_form(self, f): super(TempmonClientView, self).configure_form(f) @@ -140,6 +146,8 @@ class TempmonClientView(MasterView): # enabled if self.creating or self.editing: f.set_node('enabled', forms.types.DateTimeBoolean()) + else: + f.set_renderer('enabled', self.render_enabled_form) f.set_helptext('enabled', tempmon.Client.enabled.__doc__) # online @@ -186,6 +194,11 @@ class TempmonClientView(MasterView): for a in appliances] return HTML.tag('ul', c=items) + def render_enabled_form(self, client, field): + if client.enabled: + return raw_datetime(self.rattail_config, client.enabled) + return "No" + def delete_instance(self, client): # bulk-delete all readings first readings = self.Session.query(tempmon.Reading)\ diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index 1e81f56f..205d4c52 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -39,6 +39,7 @@ from webhelpers2.html import tags from tailbone import forms, grids from tailbone.views.tempmon import MasterView +from tailbone.util import raw_datetime class TempmonProbeView(MasterView): @@ -111,7 +112,7 @@ class TempmonProbeView(MasterView): g.set_enum('appliance_type', self.enum.TEMPMON_APPLIANCE_TYPE) g.set_enum('status', self.enum.TEMPMON_PROBE_STATUS) - g.set_type('enabled', 'boolean') + g.set_renderer('enabled', self.render_enabled_grid) g.set_label('config_key', "Key") @@ -119,6 +120,11 @@ class TempmonProbeView(MasterView): g.set_link('config_key') g.set_link('description') + def render_enabled_grid(self, probe, field): + if probe.enabled: + return "Yes" + return "No" + def configure_form(self, f): super(TempmonProbeView, self).configure_form(f) @@ -171,6 +177,8 @@ class TempmonProbeView(MasterView): # enabled if self.creating or self.editing: f.set_node('enabled', forms.types.DateTimeBoolean()) + else: + f.set_renderer('enabled', self.render_enabled_form) f.set_helptext('enabled', tempmon.Probe.enabled.__doc__) def objectify(self, form, data=None): @@ -210,6 +218,11 @@ class TempmonProbeView(MasterView): url = self.request.route_url('tempmon.appliances.view', uuid=appliance.uuid) return tags.link_to(text, url) + def render_enabled_form(self, probe, field): + if probe.enabled: + return raw_datetime(self.rattail_config, probe.enabled) + return "No" + def delete_instance(self, probe): # bulk-delete all readings first readings = self.Session.query(tempmon.Reading)\