mappa-ricezione-radio/rxmap/rxmapp/views.py
2020-03-03 18:35:27 +01:00

45 lines
1.1 KiB
Python

from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import RapportoRicezione, User, TipoRadio
# Create your views here.
def add_page(request):
# TODO: replace with /api/tipiradio/get etc.
return render(
request,
template_name="add.html",
context=dict(tipiradio=TipoRadio.objects.all()),
)
def rapporti_get(request):
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,
lat=request.POST["lat"],
lng=request.POST["lng"],
comprensibile=request.POST["comprensibile"],
stabilita=request.POST["comprensibile"],
tipo_radio=TipoRadio.objects.get(pk=request.POST["tiporadio"]),
)
r.save()
return JsonResponse(True, safe=False)
@csrf_exempt
def rapporto_delete(request):
RapportoRicezione.objects.get(pk=request.POST["rid"]).delete()
return JsonResponse(True, safe=False)