Сделал парсер, начал интеграцию с бд
This commit is contained in:
@@ -228,6 +228,52 @@ class ShowMapView(UserPassesTestMixin, View):
|
||||
return render(request, 'admin/map_custom.html', context)
|
||||
|
||||
|
||||
class ShowSelectedObjectsMapView(LoginRequiredMixin, View):
|
||||
def get(self, request):
|
||||
ids = request.GET.get('ids', '')
|
||||
points = []
|
||||
if ids:
|
||||
id_list = [int(x) for x in ids.split(',') if x.isdigit()]
|
||||
locations = ObjItem.objects.filter(id__in=id_list).prefetch_related(
|
||||
'parameters_obj__id_satellite',
|
||||
'parameters_obj__polarization',
|
||||
'parameters_obj__modulation',
|
||||
'parameters_obj__standard',
|
||||
'geo_obj'
|
||||
)
|
||||
for obj in locations:
|
||||
param = obj.parameters_obj.get()
|
||||
points.append({
|
||||
'name': f"{obj.name}",
|
||||
'freq': f"{param.frequency} [{param.freq_range}] МГц",
|
||||
'point': (obj.geo_obj.coords.x, obj.geo_obj.coords.y)
|
||||
})
|
||||
else:
|
||||
return redirect('objitem_list')
|
||||
|
||||
# Group points by object name
|
||||
from collections import defaultdict
|
||||
grouped = defaultdict(list)
|
||||
for p in points:
|
||||
grouped[p["name"]].append({
|
||||
'point': p["point"],
|
||||
'frequency': p["freq"]
|
||||
})
|
||||
|
||||
groups = [
|
||||
{
|
||||
"name": name,
|
||||
"points": coords_list
|
||||
}
|
||||
for name, coords_list in grouped.items()
|
||||
]
|
||||
|
||||
context = {
|
||||
'groups': groups,
|
||||
}
|
||||
return render(request, 'mainapp/objitem_map.html', context)
|
||||
|
||||
|
||||
class ClusterTestView(LoginRequiredMixin, View):
|
||||
def get(self, request):
|
||||
objs = ObjItem.objects.filter(name__icontains="! Astra 4A 12654,040 [1,962] МГц H")
|
||||
@@ -316,6 +362,28 @@ class ProcessKubsatView(LoginRequiredMixin, FormView):
|
||||
messages.error(self.request, "Форма заполнена некорректно.")
|
||||
return super().form_invalid(form)
|
||||
|
||||
|
||||
class DeleteSelectedObjectsView(LoginRequiredMixin, View):
|
||||
def post(self, request):
|
||||
if request.user.customuser.role not in ['admin', 'moderator']:
|
||||
return JsonResponse({'error': 'У вас нет прав для удаления объектов'}, status=403)
|
||||
|
||||
ids = request.POST.get('ids', '')
|
||||
if not ids:
|
||||
return JsonResponse({'error': 'Нет ID для удаления'}, status=400)
|
||||
|
||||
try:
|
||||
id_list = [int(x) for x in ids.split(',') if x.isdigit()]
|
||||
deleted_count, _ = ObjItem.objects.filter(id__in=id_list).delete()
|
||||
|
||||
return JsonResponse({
|
||||
'success': True,
|
||||
'message': 'Объект успешно удалён',
|
||||
# 'deleted_count': deleted_count
|
||||
})
|
||||
except Exception as e:
|
||||
return JsonResponse({'error': f'Ошибка при удалении: {str(e)}'}, status=500)
|
||||
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
|
||||
class ObjItemListView(LoginRequiredMixin, View):
|
||||
@@ -520,6 +588,8 @@ class ObjItemListView(LoginRequiredMixin, View):
|
||||
param = param_list[0]
|
||||
|
||||
geo_coords = "-"
|
||||
geo_timestamp = "-"
|
||||
geo_location = "-"
|
||||
kupsat_coords = "-"
|
||||
valid_coords = "-"
|
||||
distance_geo_kup = "-"
|
||||
@@ -528,6 +598,8 @@ class ObjItemListView(LoginRequiredMixin, View):
|
||||
|
||||
if obj.geo_obj:
|
||||
geo_timestamp = obj.geo_obj.timestamp
|
||||
geo_location = obj.geo_obj.location
|
||||
|
||||
if obj.geo_obj.coords:
|
||||
longitude = obj.geo_obj.coords.coords[0]
|
||||
latitude = obj.geo_obj.coords.coords[1]
|
||||
@@ -596,6 +668,7 @@ class ObjItemListView(LoginRequiredMixin, View):
|
||||
'modulation': modulation_name,
|
||||
'snr': snr,
|
||||
'geo_timestamp': geo_timestamp,
|
||||
'geo_location': geo_location,
|
||||
'geo_coords': geo_coords,
|
||||
'kupsat_coords': kupsat_coords,
|
||||
'valid_coords': valid_coords,
|
||||
|
||||
Reference in New Issue
Block a user