From 09407ab6c2c39ae34e7429c97c02a04cb7cb7f33 Mon Sep 17 00:00:00 2001 From: Denis Tereshkin Date: Sun, 5 Mar 2017 19:36:50 +0700 Subject: [PATCH] Last store timestamps --- templates/dashboard/overview.html | 3 ++- views.py | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/dashboard/overview.html b/templates/dashboard/overview.html index 9a79294..62c961c 100644 --- a/templates/dashboard/overview.html +++ b/templates/dashboard/overview.html @@ -2,11 +2,12 @@ {% block content %}
-{% for index, instanceId, state, positions in robot_states %} +{% for index, instanceId, state, positions, last_store in robot_states %}
diff --git a/views.py b/views.py index 636f0f4..137e59b 100644 --- a/views.py +++ b/views.py @@ -8,6 +8,7 @@ from django.contrib import messages from .models import RobotInstance import redis import json +import datetime def overview(request): r = redis.StrictRedis(unix_socket_path='/var/run/redis/redis') @@ -20,13 +21,17 @@ def overview(request): state = json.loads(str(raw_state, 'utf-8')) try: positions = state['positions'] + del state['positions'] except KeyError: positions = dict() - del state['positions'] else: state = dict() + + last_store = r.get(robot.instanceId + ":last_store") + if last_store is not None: + last_store = datetime.datetime.utcfromtimestamp(float(last_store)) index += 1 - robot_states.append((index, robot.instanceId, json.dumps(state, sort_keys=True, indent=2, separators=(',', ': ')), positions)) + robot_states.append((index, robot.instanceId, json.dumps(state, sort_keys=True, indent=2, separators=(',', ': ')), positions, last_store)) template = loader.get_template('dashboard/overview.html') context = {