Add "status since" to template context for email alerts

This commit is contained in:
Lance Edgar 2018-10-06 20:17:46 -05:00
parent 76e40063ee
commit b4fa6a17c5

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8; -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar # Copyright © 2010-2018 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -30,6 +30,8 @@ import time
import datetime import datetime
import logging import logging
import humanize
from rattail.db import Session, api from rattail.db import Session, api
from rattail_tempmon.db import Session as TempmonSession, model as tempmon from rattail_tempmon.db import Session as TempmonSession, model as tempmon
from rattail.daemon import Daemon from rattail.daemon import Daemon
@ -183,6 +185,10 @@ class TempmonServerDaemon(Daemon):
if (self.now - probe.status_changed) <= timeout: if (self.now - probe.status_changed) <= timeout:
return return
since = localtime(self.config, probe.status_changed, from_utc=True)
data['status_since'] = since.strftime('%I:%M %p')
data['status_since_delta'] = humanize.naturaltime(self.now - probe.status_changed)
msgtypes = { msgtypes = {
self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP : 'tempmon_low_temp', self.enum.TEMPMON_PROBE_STATUS_LOW_TEMP : 'tempmon_low_temp',
self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP : 'tempmon_high_temp', self.enum.TEMPMON_PROBE_STATUS_HIGH_TEMP : 'tempmon_high_temp',