From fe4f05bd544255b4874ac8e60d2095a7a0b69dd4 Mon Sep 17 00:00:00 2001
From: Samo Penic <samo.penic@gmail.com>
Date: Thu, 11 Apr 2019 19:41:14 +0000
Subject: [PATCH] Spremembe narejene na zadnji delavnici.

---
 djsenzor/sensorui/views.py |   41 +++++++++++++++++++++++------------------
 1 files changed, 23 insertions(+), 18 deletions(-)

diff --git a/djsenzor/sensorui/views.py b/djsenzor/sensorui/views.py
index 786e1bb..25533a0 100644
--- a/djsenzor/sensorui/views.py
+++ b/djsenzor/sensorui/views.py
@@ -1,37 +1,42 @@
 from django.shortcuts import render
-
+from .models import *
 from django.http.response import HttpResponse
 # Create your views here.
 
 from math import pi, sin
+from rest_framework.views import APIView
+from rest_framework.response import Response
 
-def index(request):
+
+class SensorData(APIView):
+    def post(self, request):
+        data=request.data
+        m=Measurement(sensor_id=Sensor.objects.get(pk=data['sensor_id']), value=data['value'])
+        m.save()
+        return Response(None)
+
+
+
+
+def index(request, pk):
 
     sinpi2=sin(pi/2)
     intlist=list(range(1,11))
 
     moj_template='sensorui/index.html'
 
-    data_table=[]
+    measurements=Measurement.objects.filter(sensor_id=pk).all()
 
-    data_table.append({'sensor_id':1,
-                       'data': 10.0,
-                       'date': '10.10.1010'
-                       })
-
-    data_table.append({'sensor_id':1,
-                       'data': 8.0,
-                       'date': '11.10.1010'
-                       })
-
-    data_table.append({'sensor_id':1,
-                       'data': 12.0,
-                       'date': '11.11.1010'
-                       })
     context={
         'sinpi2':sinpi2,
         'moje_ime': "Samo Penic",
         'intlist': intlist,
-        'data_table': data_table,
+        'data_table': measurements,
     }
     return render(request, moj_template, context)
+
+
+def myajaxtestview(request):
+    print("AJAX REQUEST")
+    rezultat=(int(request.GET['a'])+int(request.GET['b']))
+    return HttpResponse(rezultat)

--
Gitblit v1.9.3