2020-03-02 01:49:44 +01:00
|
|
|
from django.shortcuts import render
|
|
|
|
from django.http import JsonResponse
|
2020-03-03 18:35:27 +01:00
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
2020-03-02 01:49:44 +01:00
|
|
|
|
2020-03-03 18:35:27 +01:00
|
|
|
from .models import RapportoRicezione, User, TipoRadio
|
2020-03-02 01:49:44 +01:00
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
2020-03-03 18:35:27 +01:00
|
|
|
|
|
|
|
def add_page(request):
|
|
|
|
# TODO: replace with /api/tipiradio/get etc.
|
|
|
|
return render(
|
|
|
|
request,
|
|
|
|
template_name="add.html",
|
|
|
|
context=dict(tipiradio=TipoRadio.objects.all()),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-03-02 01:49:44 +01:00
|
|
|
def rapporti_get(request):
|
2020-03-03 18:35:27 +01:00
|
|
|
return JsonResponse(
|
|
|
|
dict(rapporti=[r.serialize() for r in RapportoRicezione.objects.all()])
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
def rapporto_add(request):
|
|
|
|
user = User.objects.filter(is_superuser=True).first()
|
|
|
|
r = RapportoRicezione(
|
|
|
|
author=user,
|
2020-03-03 18:44:22 +01:00
|
|
|
lat=float(request.POST["lat"]),
|
|
|
|
lng=float(request.POST["lng"]),
|
|
|
|
comprensibile=int(request.POST["comprensibile"]),
|
|
|
|
stabilita=int(request.POST["comprensibile"]),
|
2020-03-03 18:35:27 +01:00
|
|
|
tipo_radio=TipoRadio.objects.get(pk=request.POST["tiporadio"]),
|
|
|
|
)
|
|
|
|
r.save()
|
|
|
|
|
2020-03-03 18:44:22 +01:00
|
|
|
return JsonResponse(r.serialize())
|
2020-03-03 18:35:27 +01:00
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
def rapporto_delete(request):
|
|
|
|
RapportoRicezione.objects.get(pk=request.POST["rid"]).delete()
|
|
|
|
|
|
|
|
return JsonResponse(True, safe=False)
|