Добавил транспондеры к ObjItem шаблону
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Map related views for displaying objects on maps.
|
||||
"""
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
@@ -18,7 +19,7 @@ from ..models import ObjItem
|
||||
@method_decorator(staff_member_required, name="dispatch")
|
||||
class ShowMapView(RoleRequiredMixin, View):
|
||||
"""View for displaying objects on map (admin interface)."""
|
||||
|
||||
|
||||
required_roles = ["admin", "moderator"]
|
||||
|
||||
def get(self, request):
|
||||
@@ -41,7 +42,7 @@ class ShowMapView(RoleRequiredMixin, View):
|
||||
or not obj.geo_obj.coords
|
||||
):
|
||||
continue
|
||||
param = getattr(obj, 'parameter_obj', None)
|
||||
param = getattr(obj, "parameter_obj", None)
|
||||
if not param:
|
||||
continue
|
||||
points.append(
|
||||
@@ -53,7 +54,7 @@ class ShowMapView(RoleRequiredMixin, View):
|
||||
)
|
||||
else:
|
||||
return redirect("admin")
|
||||
|
||||
|
||||
grouped = defaultdict(list)
|
||||
for p in points:
|
||||
grouped[p["name"]].append({"point": p["point"], "frequency": p["freq"]})
|
||||
@@ -71,7 +72,7 @@ class ShowMapView(RoleRequiredMixin, View):
|
||||
|
||||
class ShowSelectedObjectsMapView(LoginRequiredMixin, View):
|
||||
"""View for displaying selected objects on map."""
|
||||
|
||||
|
||||
def get(self, request):
|
||||
ids = request.GET.get("ids", "")
|
||||
points = []
|
||||
@@ -92,7 +93,7 @@ class ShowSelectedObjectsMapView(LoginRequiredMixin, View):
|
||||
or not obj.geo_obj.coords
|
||||
):
|
||||
continue
|
||||
param = getattr(obj, 'parameter_obj', None)
|
||||
param = getattr(obj, "parameter_obj", None)
|
||||
if not param:
|
||||
continue
|
||||
points.append(
|
||||
@@ -121,9 +122,142 @@ class ShowSelectedObjectsMapView(LoginRequiredMixin, View):
|
||||
return render(request, "mainapp/objitem_map.html", context)
|
||||
|
||||
|
||||
class ShowSourcesMapView(LoginRequiredMixin, View):
|
||||
"""View for displaying selected sources on map."""
|
||||
|
||||
def get(self, request):
|
||||
from ..models import Source
|
||||
|
||||
ids = request.GET.get("ids", "")
|
||||
groups = []
|
||||
|
||||
if ids:
|
||||
id_list = [int(x) for x in ids.split(",") if x.isdigit()]
|
||||
sources = Source.objects.filter(id__in=id_list)
|
||||
|
||||
# Define coordinate types with their labels and colors
|
||||
coord_types = [
|
||||
("coords_average", "Усредненные координаты", "blue"),
|
||||
("coords_kupsat", "Координаты Кубсата", "orange"),
|
||||
("coords_valid", "Координаты оперативников", "green"),
|
||||
("coords_reference", "Координаты справочные", "violet"),
|
||||
]
|
||||
|
||||
# Group points by coordinate type
|
||||
for coord_field, label, color in coord_types:
|
||||
points = []
|
||||
for source in sources:
|
||||
coords = getattr(source, coord_field)
|
||||
if coords:
|
||||
# coords is a Point object with x (longitude) and y (latitude)
|
||||
points.append(
|
||||
{
|
||||
"point": (coords.x, coords.y), # (lon, lat)
|
||||
"source_id": f"Источник #{source.id}",
|
||||
}
|
||||
)
|
||||
|
||||
if points:
|
||||
groups.append(
|
||||
{
|
||||
"name": label,
|
||||
"points": points,
|
||||
"color": color,
|
||||
}
|
||||
)
|
||||
else:
|
||||
return redirect("mainapp:home")
|
||||
|
||||
context = {
|
||||
"groups": groups,
|
||||
}
|
||||
return render(request, "mainapp/source_map.html", context)
|
||||
|
||||
|
||||
class ShowSourceWithPointsMapView(LoginRequiredMixin, View):
|
||||
"""View for displaying a single source with all its related ObjItem points."""
|
||||
|
||||
def get(self, request, source_id):
|
||||
from ..models import Source
|
||||
|
||||
try:
|
||||
source = Source.objects.prefetch_related(
|
||||
"source_objitems",
|
||||
"source_objitems__parameter_obj",
|
||||
"source_objitems__geo_obj",
|
||||
).get(id=source_id)
|
||||
except Source.DoesNotExist:
|
||||
return redirect("mainapp:home")
|
||||
|
||||
groups = []
|
||||
|
||||
# Цвета для разных типов координат источника
|
||||
source_coord_types = [
|
||||
("coords_average", "Усредненные координаты", "blue"),
|
||||
("coords_kupsat", "Координаты Кубсата", "orange"),
|
||||
("coords_valid", "Координаты оперативников", "green"),
|
||||
("coords_reference", "Координаты справочные", "violet"),
|
||||
]
|
||||
|
||||
# Добавляем координаты источника
|
||||
for coord_field, label, color in source_coord_types:
|
||||
coords = getattr(source, coord_field)
|
||||
if coords:
|
||||
groups.append(
|
||||
{
|
||||
"name": label,
|
||||
"points": [
|
||||
{
|
||||
"point": (coords.x, coords.y),
|
||||
"source_id": f"Источник #{source.id}",
|
||||
}
|
||||
],
|
||||
"color": color,
|
||||
}
|
||||
)
|
||||
|
||||
# Добавляем все точки ГЛ одной группой
|
||||
gl_points = source.source_objitems.select_related(
|
||||
"parameter_obj", "geo_obj"
|
||||
).all()
|
||||
|
||||
# Собираем все точки ГЛ в одну группу
|
||||
all_gl_points = []
|
||||
for obj in gl_points:
|
||||
if (
|
||||
not hasattr(obj, "geo_obj")
|
||||
or not obj.geo_obj
|
||||
or not obj.geo_obj.coords
|
||||
):
|
||||
continue
|
||||
param = getattr(obj, "parameter_obj", None)
|
||||
if not param:
|
||||
continue
|
||||
|
||||
all_gl_points.append(
|
||||
{
|
||||
"point": (obj.geo_obj.coords.x, obj.geo_obj.coords.y),
|
||||
"name": obj.name,
|
||||
"frequency": f"{param.frequency} [{param.freq_range}] МГц",
|
||||
}
|
||||
)
|
||||
|
||||
# Добавляем все точки ГЛ одним цветом (красный)
|
||||
if all_gl_points:
|
||||
groups.append(
|
||||
{"name": "Точки ГЛ", "points": all_gl_points, "color": "red"}
|
||||
)
|
||||
|
||||
context = {
|
||||
"groups": groups,
|
||||
"source_id": source_id,
|
||||
}
|
||||
return render(request, "mainapp/source_with_points_map.html", context)
|
||||
|
||||
|
||||
class ClusterTestView(LoginRequiredMixin, View):
|
||||
"""Test view for clustering functionality."""
|
||||
|
||||
|
||||
def get(self, request):
|
||||
objs = ObjItem.objects.filter(
|
||||
name__icontains="! Astra 4A 12654,040 [1,962] МГц H"
|
||||
|
||||
Reference in New Issue
Block a user