mappa-ricezione-radio/rxmap/rxmapp/views.py

49 lines
1.3 KiB
Python
Raw Normal View History

2020-03-07 23:57:51 +01:00
from django.shortcuts import render,redirect
2020-03-02 01:49:44 +01:00
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()])
)
2020-03-07 23:57:51 +01:00
def rapporto_edit_redirect(request, pk):
r = RapportoRicezione.objects.get(pk=pk) # request.GET["rid"])
return redirect(r.edit_link)
2020-03-03 18:35:27 +01:00
@csrf_exempt
def rapporto_add(request):
user = User.objects.filter(is_superuser=True).first()
r = RapportoRicezione(
2020-03-07 23:57:57 +01:00
author=request.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)