Update tempmon UI now that enabled
flags are really datetime in DB
This commit is contained in:
parent
90e1baef50
commit
eb78d79bb3
|
@ -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.
|
||||
|
|
|
@ -5,31 +5,36 @@
|
|||
## page body
|
||||
##############################
|
||||
|
||||
<ul id="context-menu">
|
||||
${self.context_menu_items()}
|
||||
</ul>
|
||||
<div style="display: flex; justify-content: space-between;">
|
||||
|
||||
<div class="form-wrapper">
|
||||
|
||||
<div style="display: flex; flex-direction: column;">
|
||||
|
||||
<div class="panel" id="probe-main">
|
||||
<h2>General</h2>
|
||||
<div class="panel-body">
|
||||
<div style="clear: none; float: left;">
|
||||
<div>
|
||||
${self.render_main_fields(form)}
|
||||
</div>
|
||||
## % if image_url:
|
||||
## ${h.image(image_url, "Probe Image", id='probe-image', width=150, height=150)}
|
||||
## % endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="display: flex;">
|
||||
<div class="panel-wrapper">
|
||||
${self.left_column()}
|
||||
</div>
|
||||
|
||||
<div class="panel-wrapper">
|
||||
<div class="panel-wrapper" style="margin-left: 1em;"> <!-- right column -->
|
||||
${self.right_column()}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ul id="context-menu">
|
||||
${self.context_menu_items()}
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue