2020-03-08 00:08:19 +01:00
|
|
|
from django.conf import settings
|
2020-03-08 01:01:55 +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-08 01:01:55 +01:00
|
|
|
|
2020-03-07 23:57:51 +01:00
|
|
|
def rapporto_edit_redirect(request, pk):
|
2020-03-08 01:01:55 +01:00
|
|
|
r = RapportoRicezione.objects.get(pk=pk) # request.GET["rid"])
|
2020-03-07 23:57:51 +01:00
|
|
|
return redirect(r.edit_link)
|
2020-03-03 18:35:27 +01:00
|
|
|
|
2020-03-08 01:01:55 +01:00
|
|
|
|
2020-03-03 18:35:27 +01:00
|
|
|
@csrf_exempt
|
|
|
|
def rapporto_add(request):
|
2020-03-08 00:08:19 +01:00
|
|
|
user = request.user
|
|
|
|
if user.is_anonymous:
|
|
|
|
if settings.RX_ADD_DEFAULT_USER:
|
|
|
|
user = User.objects.get(pk=int(settings.RX_ADD_DEFAULT_USER))
|
|
|
|
else:
|
|
|
|
user = User.objects.filter().order_by('id').first()
|
2020-03-03 18:35:27 +01:00
|
|
|
r = RapportoRicezione(
|
2020-03-08 00:08:19 +01:00
|
|
|
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"]),
|
2020-03-08 00:02:00 +01:00
|
|
|
stabilita=int(request.POST["stabilita"]),
|
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)
|