Odprta koda 2019. Web aplikacija Sensor.
Samo Penic
2019-04-11 fe4f05bd544255b4874ac8e60d2095a7a0b69dd4
commit | author | age
948497 1 from django.shortcuts import render
fe4f05 2 from .models import *
948497 3 from django.http.response import HttpResponse
SP 4 # Create your views here.
5
6 from math import pi, sin
fe4f05 7 from rest_framework.views import APIView
SP 8 from rest_framework.response import Response
948497 9
fe4f05 10
SP 11 class SensorData(APIView):
12     def post(self, request):
13         data=request.data
14         m=Measurement(sensor_id=Sensor.objects.get(pk=data['sensor_id']), value=data['value'])
15         m.save()
16         return Response(None)
17
18
19
20
21 def index(request, pk):
948497 22
SP 23     sinpi2=sin(pi/2)
24     intlist=list(range(1,11))
25
26     moj_template='sensorui/index.html'
27
fe4f05 28     measurements=Measurement.objects.filter(sensor_id=pk).all()
948497 29
SP 30     context={
31         'sinpi2':sinpi2,
32         'moje_ime': "Samo Penic",
33         'intlist': intlist,
fe4f05 34         'data_table': measurements,
948497 35     }
SP 36     return render(request, moj_template, context)
fe4f05 37
SP 38
39 def myajaxtestview(request):
40     print("AJAX REQUEST")
41     rezultat=(int(request.GET['a'])+int(request.GET['b']))
42     return HttpResponse(rezultat)