Update tempmon UI now that enabled flags are really datetime in DB

This commit is contained in:
Lance Edgar 2019-01-25 19:36:13 -06:00
parent 90e1baef50
commit eb78d79bb3
4 changed files with 75 additions and 22 deletions

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar # Copyright © 2010-2019 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -27,6 +27,7 @@ Form Schema Types
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import re import re
import datetime
import six import six
@ -63,6 +64,18 @@ class JQueryTime(colander.Time):
return colander.timeparse(cstruct, formats[0]) 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): class GPCType(colander.SchemaType):
""" """
Schema type for product GPC data. Schema type for product GPC data.

View file

@ -5,31 +5,36 @@
## page body ## page body
############################## ##############################
<ul id="context-menu"> <div style="display: flex; justify-content: space-between;">
${self.context_menu_items()}
</ul>
<div class="form-wrapper"> <div class="form-wrapper">
<div style="display: flex; flex-direction: column;">
<div class="panel" id="probe-main"> <div class="panel" id="probe-main">
<h2>General</h2> <h2>General</h2>
<div class="panel-body"> <div class="panel-body">
<div style="clear: none; float: left;"> <div>
${self.render_main_fields(form)} ${self.render_main_fields(form)}
</div> </div>
## % if image_url:
## ${h.image(image_url, "Probe Image", id='probe-image', width=150, height=150)}
## % endif
</div> </div>
</div> </div>
<div style="display: flex;">
<div class="panel-wrapper"> <div class="panel-wrapper">
${self.left_column()} ${self.left_column()}
</div> </div>
<div class="panel-wrapper" style="margin-left: 1em;"> <!-- right column -->
<div class="panel-wrapper">
${self.right_column()} ${self.right_column()}
</div> </div>
</div>
</div>
</div>
<ul id="context-menu">
${self.context_menu_items()}
</ul>
</div> </div>

View file

@ -2,7 +2,7 @@
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar # Copyright © 2010-2019 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -34,6 +34,7 @@ from rattail_tempmon.db import model as tempmon
import colander import colander
from webhelpers2.html import HTML, tags from webhelpers2.html import HTML, tags
from tailbone import forms
from tailbone.views.tempmon import MasterView from tailbone.views.tempmon import MasterView
@ -101,6 +102,9 @@ class TempmonClientView(MasterView):
# disk_type # disk_type
g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE) g.set_enum('disk_type', self.enum.TEMPMON_DISK_TYPE)
# enabled
g.set_type('enabled', 'boolean')
# 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'
@ -134,6 +138,8 @@ class TempmonClientView(MasterView):
f.set_type('notes', 'text') f.set_type('notes', 'text')
# enabled # enabled
if self.creating or self.editing:
f.set_node('enabled', forms.types.DateTimeBoolean())
f.set_helptext('enabled', tempmon.Client.enabled.__doc__) f.set_helptext('enabled', tempmon.Client.enabled.__doc__)
# online # online
@ -145,6 +151,18 @@ class TempmonClientView(MasterView):
# archived # archived
f.set_helptext('archived', tempmon.Client.archived.__doc__) 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): def unique_config_key(self, node, value):
query = self.Session.query(tempmon.Client)\ query = self.Session.query(tempmon.Client)\
.filter(tempmon.Client.config_key == value) .filter(tempmon.Client.config_key == value)

View file

@ -37,7 +37,7 @@ import colander
from deform import widget as dfwidget from deform import widget as dfwidget
from webhelpers2.html import tags from webhelpers2.html import tags
from tailbone import grids from tailbone import forms, grids
from tailbone.views.tempmon import MasterView from tailbone.views.tempmon import MasterView
@ -168,6 +168,23 @@ class TempmonProbeView(MasterView):
if self.creating or self.editing: if self.creating or self.editing:
f.remove_fields('status') 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): def unique_config_key(self, node, value):
query = self.Session.query(tempmon.Probe)\ query = self.Session.query(tempmon.Probe)\
.filter(tempmon.Probe.config_key == value) .filter(tempmon.Probe.config_key == value)