Browse Source

Last store timestamps

master
Denis Tereshkin 9 years ago
parent
commit
09407ab6c2
  1. 3
      templates/dashboard/overview.html
  2. 9
      views.py

3
templates/dashboard/overview.html

@ -2,11 +2,12 @@
{% block content %} {% block content %}
<div class="panel-group"> <div class="panel-group">
{% for index, instanceId, state, positions in robot_states %} {% for index, instanceId, state, positions, last_store in robot_states %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading" id="heading-{{instanceId}}"> <div class="panel-heading" id="heading-{{instanceId}}">
<a role="button" data-toggle="collapse" href="#collapse-{{index}}"> <a role="button" data-toggle="collapse" href="#collapse-{{index}}">
{{ instanceId }} {{ instanceId }}
{% if last_store %}<div class="pull-right"><span class="badge">{{ last_store }}</span></div>{% endif %}
</a> </a>
</div> </div>
<div id="collapse-{{index}}" class="panel-collapse collapse"> <div id="collapse-{{index}}" class="panel-collapse collapse">

9
views.py

@ -8,6 +8,7 @@ from django.contrib import messages
from .models import RobotInstance from .models import RobotInstance
import redis import redis
import json import json
import datetime
def overview(request): def overview(request):
r = redis.StrictRedis(unix_socket_path='/var/run/redis/redis') 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')) state = json.loads(str(raw_state, 'utf-8'))
try: try:
positions = state['positions'] positions = state['positions']
del state['positions']
except KeyError: except KeyError:
positions = dict() positions = dict()
del state['positions']
else: else:
state = dict() 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 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') template = loader.get_template('dashboard/overview.html')
context = { context = {

Loading…
Cancel
Save