Fix CRUD pages for tempmon clients, probes

for some reason if helptext had embedded newlines, it would now fail
to render the form altogether.  guess that is a result of recent
change to e.g. `<b-field :message="['foo', 'bar']">` logic,
somehow.. anyway hopefully this fixes and no more surprises
This commit is contained in:
Lance Edgar 2023-10-05 13:11:05 -05:00
parent 3dfab8e42d
commit b30f6cdf3a
4 changed files with 31 additions and 47 deletions

View file

@ -755,7 +755,8 @@ class Form(object):
""" """
Set the help text for a given field. Set the help text for a given field.
""" """
self.helptext[key] = value # nb. must avoid newlines, they cause some weird "blank page" error?!
self.helptext[key] = value.replace('\n', ' ')
if value and dynamic: if value and dynamic:
self.dynamic_helptext[key] = True self.dynamic_helptext[key] = True
else: else:
@ -1009,6 +1010,8 @@ class Form(object):
# render the field widget or whatever # render the field widget or whatever
if self.readonly or fieldname in self.readonly_fields: if self.readonly or fieldname in self.readonly_fields:
html = self.render_field_value(fieldname) or HTML.tag('span') html = self.render_field_value(fieldname) or HTML.tag('span')
if type(html) is str:
html = HTML.tag('span', c=[html])
elif field: elif field:
html = field.serialize(**self.get_renderer_kwargs(fieldname)) html = field.serialize(**self.get_renderer_kwargs(fieldname))
html = HTML.literal(html) html = HTML.literal(html)

View file

@ -1,16 +1,8 @@
## -*- coding: utf-8; -*- ## -*- coding: utf-8; -*-
<%inherit file="/master/view.mako" /> <%inherit file="/master/view.mako" />
<%def name="render_form_complete()"> <%def name="page_content()">
## ${self.render_form()}
<script type="text/x-template" id="form-page-template">
<div style="display: flex; justify-content: space-between;">
<div class="form-wrapper"> <div class="form-wrapper">
<div style="display: flex; flex-direction: column;"> <div style="display: flex; flex-direction: column;">
<nav class="panel" id="probe-main"> <nav class="panel" id="probe-main">
@ -33,17 +25,6 @@
</div> </div>
</div> </div>
<ul id="context-menu">
${self.context_menu_items()}
</ul>
</div>
</script>
<div id="form-page-app">
<form-page></form-page>
</div>
</%def> </%def>

View file

@ -24,8 +24,6 @@
Views for tempmon clients Views for tempmon clients
""" """
from __future__ import unicode_literals, absolute_import
import subprocess import subprocess
from rattail.config import parse_list from rattail.config import parse_list
@ -51,6 +49,7 @@ class TempmonClientView(MasterView):
has_rows = True has_rows = True
model_row_class = tempmon.Reading model_row_class = tempmon.Reading
rows_title = "Readings"
grid_columns = [ grid_columns = [
'config_key', 'config_key',
@ -83,7 +82,7 @@ class TempmonClientView(MasterView):
] ]
def configure_grid(self, g): def configure_grid(self, g):
super(TempmonClientView, self).configure_grid(g) super().configure_grid(g)
# config_key # config_key
g.set_label('config_key', "Key") g.set_label('config_key', "Key")
@ -116,7 +115,7 @@ class TempmonClientView(MasterView):
return "No" return "No"
def configure_form(self, f): def configure_form(self, f):
super(TempmonClientView, self).configure_form(f) super().configure_form(f)
# config_key # config_key
f.set_validator('config_key', self.unique_config_key) f.set_validator('config_key', self.unique_config_key)
@ -160,7 +159,7 @@ class TempmonClientView(MasterView):
f.set_helptext('archived', tempmon.Client.archived.__doc__) f.set_helptext('archived', tempmon.Client.archived.__doc__)
def template_kwargs_view(self, **kwargs): def template_kwargs_view(self, **kwargs):
kwargs = super(TempmonClientView, self).template_kwargs_view(**kwargs) kwargs = super().template_kwargs_view(**kwargs)
client = kwargs['instance'] client = kwargs['instance']
kwargs['probes_data'] = self.normalize_probes(client.probes) kwargs['probes_data'] = self.normalize_probes(client.probes)
@ -177,7 +176,7 @@ class TempmonClientView(MasterView):
if data['enabled'] and form.model_instance.enabled: if data['enabled'] and form.model_instance.enabled:
data['enabled'] = form.model_instance.enabled data['enabled'] = form.model_instance.enabled
return super(TempmonClientView, self).objectify(form, data=data) return super().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)\
@ -230,7 +229,7 @@ class TempmonClientView(MasterView):
return reading.client return reading.client
def configure_row_grid(self, g): def configure_row_grid(self, g):
super(TempmonClientView, self).configure_row_grid(g) super().configure_row_grid(g)
# probe # probe
g.set_filter('probe', tempmon.Probe.description) g.set_filter('probe', tempmon.Probe.description)

View file

@ -49,6 +49,7 @@ class TempmonProbeView(MasterView):
has_rows = True has_rows = True
model_row_class = tempmon.Reading model_row_class = tempmon.Reading
rows_title = "Readings"
labels = { labels = {
'critical_max_timeout': "Critical High Timeout", 'critical_max_timeout': "Critical High Timeout",
@ -98,7 +99,7 @@ class TempmonProbeView(MasterView):
] ]
def configure_grid(self, g): def configure_grid(self, g):
super(TempmonProbeView, self).configure_grid(g) super().configure_grid(g)
g.joiners['client'] = lambda q: q.join(tempmon.Client) g.joiners['client'] = lambda q: q.join(tempmon.Client)
g.sorters['client'] = g.make_sorter(tempmon.Client.config_key) g.sorters['client'] = g.make_sorter(tempmon.Client.config_key)
@ -121,7 +122,7 @@ class TempmonProbeView(MasterView):
return "No" return "No"
def configure_form(self, f): def configure_form(self, f):
super(TempmonProbeView, self).configure_form(f) super().configure_form(f)
# config_key # config_key
f.set_validator('config_key', self.unique_config_key) f.set_validator('config_key', self.unique_config_key)
@ -186,7 +187,7 @@ class TempmonProbeView(MasterView):
if data['enabled'] and form.model_instance.enabled: if data['enabled'] and form.model_instance.enabled:
data['enabled'] = form.model_instance.enabled data['enabled'] = form.model_instance.enabled
return super(TempmonProbeView, self).objectify(form, data=data) return super().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)\
@ -240,7 +241,7 @@ class TempmonProbeView(MasterView):
return reading.client return reading.client
def configure_row_grid(self, g): def configure_row_grid(self, g):
super(TempmonProbeView, self).configure_row_grid(g) super().configure_row_grid(g)
# # probe # # probe
# g.set_filter('probe', tempmon.Probe.description) # g.set_filter('probe', tempmon.Probe.description)