From 0b5a644de1c4b421c69b4b1984e55d910213397d Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 12 Jan 2017 15:36:18 -0600 Subject: [PATCH] Improve columns, filters for TempMon Readings grid --- tailbone/views/tempmon/readings.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tailbone/views/tempmon/readings.py b/tailbone/views/tempmon/readings.py index 66c2738b..7bf0e6ae 100644 --- a/tailbone/views/tempmon/readings.py +++ b/tailbone/views/tempmon/readings.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -26,8 +26,12 @@ Views for tempmon readings from __future__ import unicode_literals, absolute_import +from sqlalchemy import orm + from rattail_tempmon.db import model as tempmon +import formalchemy as fa + from tailbone.views.tempmon import MasterView, ClientFieldRenderer, ProbeFieldRenderer @@ -43,14 +47,33 @@ class TempmonReadingView(MasterView): creatable = False editable = False + def query(self, session): + return session.query(tempmon.Reading)\ + .join(tempmon.Client)\ + .options(orm.joinedload(tempmon.Reading.client)) + def _preconfigure_grid(self, g): + + g.append(fa.Field('client_key', value=lambda r: r.client.config_key)) + g.sorters['client_key'] = g.make_sorter(tempmon.Client.config_key) + g.filters['client_key'] = g.make_filter('client_key', tempmon.Client.config_key) + + g.append(fa.Field('client_host', value=lambda r: r.client.hostname)) + g.sorters['client_host'] = g.make_sorter(tempmon.Client.hostname) + g.filters['client_host'] = g.make_filter('client_host', tempmon.Client.hostname) + + g.joiners['probe'] = lambda q: q.join(tempmon.Probe) + g.sorters['probe'] = g.make_sorter(tempmon.Probe.description) + g.filters['probe'] = g.make_filter('probe', tempmon.Probe.description) + g.default_sortkey = 'taken' g.default_sortdir = 'desc' def configure_grid(self, g): g.configure( include=[ - g.client, + g.client_key, + g.client_host, g.probe, g.taken, g.degrees_f,