Browse Source

filtra per tipo

boyska 3 years ago
parent
commit
8ed118a37b
3 changed files with 18 additions and 7 deletions
  1. 1 1
      rxmap/rxmapp/templates/index.html
  2. 4 3
      rxmap/rxmapp/urls.py
  3. 13 3
      rxmap/rxmapp/views.py

+ 1 - 1
rxmap/rxmapp/templates/index.html

@@ -20,7 +20,7 @@
         <select name="tiporadio" >
             <option value="NA" disabled selected="selected">//</option>
             {% for tr in tipiradio %}
-                <option value="{{tr.tid}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:'' }}</option>
+                <option value="{{tr.id}}"><strong>{{tr.nome}}</strong> - {{tr.descrizione|default:'' }}</option>
             {% endfor %}
         </select>
         </div>

+ 4 - 3
rxmap/rxmapp/urls.py

@@ -14,13 +14,14 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 from django.contrib import admin
-from django.urls import path, include
-from django.views.generic import TemplateView
 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
+from django.urls import include, path
+from django.views.generic import TemplateView
+
 from . import views
 
 urlpatterns = [
-    path("", TemplateView.as_view(template_name="index.html"), name="home"),
+    path("", views.ViewMap.as_view(), name="home"),
     path("add", views.add_page, name="add"),
     path("api/rapporti/get", views.rapporti_get),
     path("api/rapporti/<int:pk>/edit", views.rapporto_edit_redirect),

+ 13 - 3
rxmap/rxmapp/views.py

@@ -1,13 +1,23 @@
 from django.conf import settings
-from django.shortcuts import render, redirect
 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 .models import RapportoRicezione, User, TipoRadio
+from .models import RapportoRicezione, TipoRadio, User
 
 # Create your views here.
 
 
+class ViewMap(TemplateView):
+    template_name = "index.html"
+
+    def get_context_data(self, **kwargs):
+        ctx = super().get_context_data(**kwargs)
+        ctx["tipiradio"] = TipoRadio.objects.all()
+        return ctx
+
+
 def add_page(request):
     # TODO: replace with /api/tipiradio/get etc.
     return render(
@@ -42,7 +52,7 @@ def rapporto_add(request):
         lng=float(request.POST["lng"]),
         comprensibile=int(request.POST["comprensibile"]),
         stabilita=int(request.POST["stabilita"]),
-        indirizzo=request.POST.get('indirizzo', ''),
+        indirizzo=request.POST.get("indirizzo", ""),
         tipo_radio=TipoRadio.objects.get(pk=request.POST["tiporadio"]),
     )
     r.save()