diff --git a/tailbone/forms/types.py b/tailbone/forms/types.py index de7e117c..366794f4 100644 --- a/tailbone/forms/types.py +++ b/tailbone/forms/types.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -27,6 +27,7 @@ Form Schema Types from __future__ import unicode_literals, absolute_import import re +import datetime import six @@ -63,6 +64,18 @@ class JQueryTime(colander.Time): return colander.timeparse(cstruct, formats[0]) +class DateTimeBoolean(colander.Boolean): + """ + Schema type which presents the user with a "boolean" whereas the underlying + node is really a datetime (assumed to be "naive" UTC, and allow nulls). + """ + + def deserialize(self, node, cstruct): + value = super(DateTimeBoolean, self).deserialize(node, cstruct) + if value: # else return None + return datetime.datetime.utcnow() + + class GPCType(colander.SchemaType): """ Schema type for product GPC data. diff --git a/tailbone/templates/tempmon/probes/view.mako b/tailbone/templates/tempmon/probes/view.mako index 8bf3fd2e..1befd1e4 100644 --- a/tailbone/templates/tempmon/probes/view.mako +++ b/tailbone/templates/tempmon/probes/view.mako @@ -5,31 +5,36 @@ ## page body ############################## - +
-
+
-
-

General

-
-
- ${self.render_main_fields(form)} +
+ +
+

General

+
+
+ ${self.render_main_fields(form)} +
+
-## % if image_url: -## ${h.image(image_url, "Probe Image", id='probe-image', width=150, height=150)} -## % endif + +
+
+ ${self.left_column()} +
+
+ ${self.right_column()} +
+
+
-
- ${self.left_column()} -
- -
- ${self.right_column()} -
+
    + ${self.context_menu_items()} +
diff --git a/tailbone/views/tempmon/clients.py b/tailbone/views/tempmon/clients.py index d38d38f2..f455d0f8 100644 --- a/tailbone/views/tempmon/clients.py +++ b/tailbone/views/tempmon/clients.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -34,6 +34,7 @@ from rattail_tempmon.db import model as tempmon import colander from webhelpers2.html import HTML, tags +from tailbone import forms from tailbone.views.tempmon import MasterView @@ -101,6 +102,9 @@ class TempmonClientView(MasterView): # disk_type g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE) + # enabled + g.set_type('enabled', 'boolean') + # archived g.filters['archived'].default_active = True g.filters['archived'].default_verb = 'is_false' @@ -134,6 +138,8 @@ class TempmonClientView(MasterView): f.set_type('notes', 'text') # enabled + if self.creating or self.editing: + f.set_node('enabled', forms.types.DateTimeBoolean()) f.set_helptext('enabled', tempmon.Client.enabled.__doc__) # online @@ -145,6 +151,18 @@ class TempmonClientView(MasterView): # archived f.set_helptext('archived', tempmon.Client.archived.__doc__) + def objectify(self, form, data=None): + + # this is a hack to prevent updates to the 'enabled' timestamp, when + # simple edits are being done to the client. i.e. we do want to set + # the timestamp when it was previously null, but not otherwise. + if self.editing: + data = dict(data or form.validated) + if data['enabled'] and form.model_instance.enabled: + data['enabled'] = form.model_instance.enabled + + return super(TempmonClientView, self).objectify(form, data=data) + def unique_config_key(self, node, value): query = self.Session.query(tempmon.Client)\ .filter(tempmon.Client.config_key == value) diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index 479d6c31..1e81f56f 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -37,7 +37,7 @@ import colander from deform import widget as dfwidget from webhelpers2.html import tags -from tailbone import grids +from tailbone import forms, grids from tailbone.views.tempmon import MasterView @@ -168,6 +168,23 @@ class TempmonProbeView(MasterView): if self.creating or self.editing: f.remove_fields('status') + # enabled + if self.creating or self.editing: + f.set_node('enabled', forms.types.DateTimeBoolean()) + f.set_helptext('enabled', tempmon.Probe.enabled.__doc__) + + def objectify(self, form, data=None): + + # this is a hack to prevent updates to the 'enabled' timestamp, when + # simple edits are being done to the probe. i.e. we do want to set the + # timestamp when it was previously null, but not otherwise. + if self.editing: + data = dict(data or form.validated) + if data['enabled'] and form.model_instance.enabled: + data['enabled'] = form.model_instance.enabled + + return super(TempmonProbeView, self).objectify(form, data=data) + def unique_config_key(self, node, value): query = self.Session.query(tempmon.Probe)\ .filter(tempmon.Probe.config_key == value)