diff --git a/tailbone/templates/tempmon/probes/graph.mako b/tailbone/templates/tempmon/probes/graph.mako index 795af145..412f25dd 100644 --- a/tailbone/templates/tempmon/probes/graph.mako +++ b/tailbone/templates/tempmon/probes/graph.mako @@ -39,7 +39,13 @@ - ${time_range} + + + + + + @@ -86,7 +92,9 @@ this.chart.destroy() } - this.$http.get('${url('{}.graph_readings'.format(route_prefix), uuid=probe.uuid)}', {params: {'time-range': timeRange}}).then(({ data }) => { + let url = '${url(f'{route_prefix}.graph_readings', uuid=probe.uuid)}' + let params = {'time-range': timeRange} + this.$http.get(url, {params: params}).then(({ data }) => { this.chart = new Chart(this.$refs.tempchart, { type: 'scatter', diff --git a/tailbone/views/tempmon/probes.py b/tailbone/views/tempmon/probes.py index 6d12a3d2..381a9f4a 100644 --- a/tailbone/views/tempmon/probes.py +++ b/tailbone/views/tempmon/probes.py @@ -26,12 +26,11 @@ Views for tempmon probes import datetime -from rattail.time import make_utc, localtime from rattail_tempmon.db import model as tempmon import colander from deform import widget as dfwidget -from webhelpers2.html import tags, HTML +from webhelpers2.html import tags from tailbone import forms, grids from tailbone.views.tempmon import MasterView @@ -258,27 +257,16 @@ class TempmonProbeView(MasterView): selected = self.request.session.get(key, 'last hour') self.request.session[key] = selected - range_options = tags.Options([ - tags.Option("Last Hour", 'last hour'), - tags.Option("Last 6 Hours", 'last 6 hours'), - tags.Option("Last Day", 'last day'), - tags.Option("Last Week", 'last week'), - ]) - - time_range = HTML.tag('b-select', c=[range_options.render()], - **{'v-model': 'currentTimeRange', - '@input': 'timeRangeChanged'}) - context = { 'probe': probe, 'parent_title': str(probe), 'parent_url': self.get_action_url('view', probe), - 'time_range': time_range, 'current_time_range': selected, } return self.render_to_response('graph', context) def graph_readings(self): + app = self.get_rattail_app() probe = self.get_instance() key = 'tempmon.probe.{}.graph_time_range'.format(probe.uuid) @@ -299,7 +287,7 @@ class TempmonProbeView(MasterView): raise NotImplementedError("Unknown time range: {}".format(selected)) # figure out which readings we need to graph - cutoff = make_utc() - datetime.timedelta(seconds=cutoff) + cutoff = app.make_utc() - datetime.timedelta(seconds=cutoff) readings = self.Session.query(tempmon.Reading)\ .filter(tempmon.Reading.probe == probe)\ .filter(tempmon.Reading.taken >= cutoff)\ @@ -308,7 +296,7 @@ class TempmonProbeView(MasterView): # convert readings to data for scatter plot data = [{ - 'x': localtime(self.rattail_config, reading.taken, from_utc=True).isoformat(), + 'x': app.localtime(reading.taken, from_utc=True).isoformat(), 'y': float(reading.degrees_f), } for reading in readings] return data