Improve rendering of enabled field for tempmon clients, probes

to make it more clear, when disabled
This commit is contained in:
Lance Edgar 2019-01-29 17:19:04 -06:00
parent d18302314d
commit 933ee88172
2 changed files with 28 additions and 2 deletions

View file

@ -36,6 +36,7 @@ from webhelpers2.html import HTML, tags
from tailbone import forms from tailbone import forms
from tailbone.views.tempmon import MasterView from tailbone.views.tempmon import MasterView
from tailbone.util import raw_datetime
class TempmonClientView(MasterView): class TempmonClientView(MasterView):
@ -103,12 +104,17 @@ class TempmonClientView(MasterView):
g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE) g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE)
# enabled # enabled
g.set_type('enabled', 'boolean') g.set_renderer('enabled', self.render_enabled_grid)
# archived # archived
g.filters['archived'].default_active = True g.filters['archived'].default_active = True
g.filters['archived'].default_verb = 'is_false' 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): def configure_form(self, f):
super(TempmonClientView, self).configure_form(f) super(TempmonClientView, self).configure_form(f)
@ -140,6 +146,8 @@ class TempmonClientView(MasterView):
# enabled # enabled
if self.creating or self.editing: if self.creating or self.editing:
f.set_node('enabled', forms.types.DateTimeBoolean()) f.set_node('enabled', forms.types.DateTimeBoolean())
else:
f.set_renderer('enabled', self.render_enabled_form)
f.set_helptext('enabled', tempmon.Client.enabled.__doc__) f.set_helptext('enabled', tempmon.Client.enabled.__doc__)
# online # online
@ -186,6 +194,11 @@ class TempmonClientView(MasterView):
for a in appliances] for a in appliances]
return HTML.tag('ul', c=items) 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): def delete_instance(self, client):
# bulk-delete all readings first # bulk-delete all readings first
readings = self.Session.query(tempmon.Reading)\ readings = self.Session.query(tempmon.Reading)\

View file

@ -39,6 +39,7 @@ from webhelpers2.html import tags
from tailbone import forms, grids from tailbone import forms, grids
from tailbone.views.tempmon import MasterView from tailbone.views.tempmon import MasterView
from tailbone.util import raw_datetime
class TempmonProbeView(MasterView): class TempmonProbeView(MasterView):
@ -111,7 +112,7 @@ class TempmonProbeView(MasterView):
g.set_enum('appliance_type', self.enum.TEMPMON_APPLIANCE_TYPE) g.set_enum('appliance_type', self.enum.TEMPMON_APPLIANCE_TYPE)
g.set_enum('status', self.enum.TEMPMON_PROBE_STATUS) 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") g.set_label('config_key', "Key")
@ -119,6 +120,11 @@ class TempmonProbeView(MasterView):
g.set_link('config_key') g.set_link('config_key')
g.set_link('description') g.set_link('description')
def render_enabled_grid(self, probe, field):
if probe.enabled:
return "Yes"
return "No"
def configure_form(self, f): def configure_form(self, f):
super(TempmonProbeView, self).configure_form(f) super(TempmonProbeView, self).configure_form(f)
@ -171,6 +177,8 @@ class TempmonProbeView(MasterView):
# enabled # enabled
if self.creating or self.editing: if self.creating or self.editing:
f.set_node('enabled', forms.types.DateTimeBoolean()) f.set_node('enabled', forms.types.DateTimeBoolean())
else:
f.set_renderer('enabled', self.render_enabled_form)
f.set_helptext('enabled', tempmon.Probe.enabled.__doc__) f.set_helptext('enabled', tempmon.Probe.enabled.__doc__)
def objectify(self, form, data=None): def objectify(self, form, data=None):
@ -210,6 +218,11 @@ class TempmonProbeView(MasterView):
url = self.request.route_url('tempmon.appliances.view', uuid=appliance.uuid) url = self.request.route_url('tempmon.appliances.view', uuid=appliance.uuid)
return tags.link_to(text, url) 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): def delete_instance(self, probe):
# bulk-delete all readings first # bulk-delete all readings first
readings = self.Session.query(tempmon.Reading)\ readings = self.Session.query(tempmon.Reading)\