filtra davvero

This commit is contained in:
boyska 2020-09-29 16:49:25 +02:00
parent 8ed118a37b
commit 388b25d032
5 changed files with 15 additions and 7 deletions

View file

@ -2,3 +2,4 @@ Django==2.2
gunicorn==20.0.4 gunicorn==20.0.4
pytz==2019.3 pytz==2019.3
sqlparse==0.3.1 sqlparse==0.3.1
django-filter==2.4.0

View file

@ -7,7 +7,7 @@ function viewMap () {
L.tileLayer( L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
).addTo(map) ).addTo(map)
$.getJSON('/api/rapporti/get', function (data) { $.getJSON('/api/rapporti/get' + (new URL(document.URL).search), function (data) {
for (var i in data.rapporti) { for (var i in data.rapporti) {
var p = data.rapporti[i] var p = data.rapporti[i]
var marker = new RapportoMarker([p.lat, p.lng], { var marker = new RapportoMarker([p.lat, p.lng], {

View file

@ -16,8 +16,8 @@
<form method="GET"> <form method="GET">
<div class="form-field-line"> <div class="form-field-line">
<label for="tiporadio">Osservazione fatta con</label> <label for="tipo_radio__id">Osservazione fatta con</label>
<select name="tiporadio" > <select name="tipo_radio__id" >
<option value="NA" disabled selected="selected">//</option> <option value="NA" disabled selected="selected">//</option>
{% for tr in tipiradio %} {% for tr in tipiradio %}
<option value="{{tr.id}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:'' }}</option> <option value="{{tr.id}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:'' }}</option>

View file

@ -24,6 +24,7 @@ urlpatterns = [
path("", views.ViewMap.as_view(), name="home"), path("", views.ViewMap.as_view(), name="home"),
path("add", views.add_page, name="add"), path("add", views.add_page, name="add"),
path("api/rapporti/get", views.rapporti_get), path("api/rapporti/get", views.rapporti_get),
# path("api/rapporti/get", views.RapportiGet.as_view()),
path("api/rapporti/<int:pk>/edit", views.rapporto_edit_redirect), path("api/rapporti/<int:pk>/edit", views.rapporto_edit_redirect),
path("api/rapporti/add", views.rapporto_add), path("api/rapporti/add", views.rapporto_add),
# path("api/rapporti/delete", views.rapporto_delete), # path("api/rapporti/delete", views.rapporto_delete),

View file

@ -1,8 +1,9 @@
import django_filters
from django.conf import settings from django.conf import settings
from django.http import JsonResponse from django.http import JsonResponse
from django.shortcuts import redirect, render from django.shortcuts import redirect, render
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView from django.views.generic import ListView, TemplateView
from .models import RapportoRicezione, TipoRadio, User from .models import RapportoRicezione, TipoRadio, User
@ -27,10 +28,15 @@ def add_page(request):
) )
class RapportiFilter(django_filters.FilterSet):
class Meta:
model = RapportoRicezione
fields = ["tipo_radio__id"]
def rapporti_get(request): def rapporti_get(request):
return JsonResponse( pf = RapportiFilter(request.GET, queryset=RapportoRicezione.objects.all())
dict(rapporti=[r.serialize() for r in RapportoRicezione.objects.all()]) return JsonResponse(dict(rapporti=[r.serialize() for r in pf.qs]))
)
def rapporto_edit_redirect(request, pk): def rapporto_edit_redirect(request, pk):