Odprta koda 2019. Web aplikacija Sensor.
Samo Penic
2019-04-11 fe4f05bd544255b4874ac8e60d2095a7a0b69dd4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
 
 
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'
 
    measurements=Measurement.objects.filter(sensor_id=pk).all()
 
    context={
        'sinpi2':sinpi2,
        'moje_ime': "Samo Penic",
        'intlist': intlist,
        '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)