diff --git a/requirements.txt b/requirements.txt index b86b6f9..8c323b1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ Django==2.2 gunicorn==20.0.4 pytz==2019.3 sqlparse==0.3.1 +django-filter==2.4.0 diff --git a/rxmap/rxmapp/static/js/viewmap.js b/rxmap/rxmapp/static/js/viewmap.js index 6fe0468..b2a5213 100644 --- a/rxmap/rxmapp/static/js/viewmap.js +++ b/rxmap/rxmapp/static/js/viewmap.js @@ -7,7 +7,7 @@ function viewMap () { L.tileLayer( 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' ).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) { var p = data.rapporti[i] var marker = new RapportoMarker([p.lat, p.lng], { diff --git a/rxmap/rxmapp/templates/index.html b/rxmap/rxmapp/templates/index.html index 06d0ed2..cbf313a 100644 --- a/rxmap/rxmapp/templates/index.html +++ b/rxmap/rxmapp/templates/index.html @@ -16,8 +16,8 @@
- - {% for tr in tipiradio %} diff --git a/rxmap/rxmapp/urls.py b/rxmap/rxmapp/urls.py index 81cea2c..4e56acd 100644 --- a/rxmap/rxmapp/urls.py +++ b/rxmap/rxmapp/urls.py @@ -24,6 +24,7 @@ urlpatterns = [ path("", views.ViewMap.as_view(), name="home"), path("add", views.add_page, name="add"), path("api/rapporti/get", views.rapporti_get), + # path("api/rapporti/get", views.RapportiGet.as_view()), path("api/rapporti//edit", views.rapporto_edit_redirect), path("api/rapporti/add", views.rapporto_add), # path("api/rapporti/delete", views.rapporto_delete), diff --git a/rxmap/rxmapp/views.py b/rxmap/rxmapp/views.py index 34103d8..ec86300 100644 --- a/rxmap/rxmapp/views.py +++ b/rxmap/rxmapp/views.py @@ -1,8 +1,9 @@ +import django_filters from django.conf import settings from django.http import JsonResponse from django.shortcuts import redirect, render 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 @@ -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): - return JsonResponse( - dict(rapporti=[r.serialize() for r in RapportoRicezione.objects.all()]) - ) + pf = RapportiFilter(request.GET, queryset=RapportoRicezione.objects.all()) + return JsonResponse(dict(rapporti=[r.serialize() for r in pf.qs])) def rapporto_edit_redirect(request, pk):