blob: 7d23043b0941a6fe2cfec6d990d4bc0fb6f146d8 [file] [log] [blame]
Scott Bakerbf1610d2014-06-18 18:22:03 -07001# /opt/planetstack/core/dashboard/views/helloworld.py
Scott Baker0b48b4b2014-06-19 15:24:58 -07002import datetime
Scott Bakerbf1610d2014-06-18 18:22:03 -07003import os
4import sys
Scott Baker0b48b4b2014-06-19 15:24:58 -07005import time
Scott Bakerbf1610d2014-06-18 18:22:03 -07006import json
7from django.http import HttpResponse, HttpResponseServerError, HttpResponseForbidden
8from django.views.generic import TemplateView, View
9from core.models import *
10from django.forms.models import model_to_dict
11
Scott Baker0b48b4b2014-06-19 15:24:58 -070012def ensure_serializable(d):
13 d2={}
14 for (k,v) in d.items():
15 # datetime is not json serializable
16 if isinstance(v, datetime.datetime):
17 d2[k] = time.mktime(v.timetuple())
18 else:
19 d2[k] = v
20 return d2
21
Scott Bakerbf1610d2014-06-18 18:22:03 -070022class ShellDataView(View):
23 url = r'^shelldata/'
24
25 def get(self, request, **kwargs):
26 allSlices = []
27 for slice in Slice.objects.all():
Scott Baker0b48b4b2014-06-19 15:24:58 -070028 allSlices.append(ensure_serializable(model_to_dict(slice)))
Scott Bakerbf1610d2014-06-18 18:22:03 -070029
30 result = {"slices": allSlices}
31
32 return HttpResponse(json.dumps(result), mimetype='application/json')