This commit is contained in:
2025-10-24 16:54:20 +03:00
parent 5e40201460
commit 178854c6ba
15 changed files with 505 additions and 232 deletions

View File

@@ -5,64 +5,80 @@ from django.core import serializers
from django.http import HttpResponse, HttpResponseNotFound
from django.views.decorators.cache import cache_page
from django.views.decorators.http import require_GET
from django.utils.decorators import method_decorator
from django.views import View
from django.views.generic import TemplateView
from mainapp.models import Satellite
from .models import Transponders
from .utils import get_band_names
def cesium_map(request):
sats = Satellite.objects.all()
class CesiumMapView(TemplateView):
template_name = 'mapsapp/map3d.html'
return render(request, 'mapsapp/map3d.html', {'sats': sats})
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['sats'] = Satellite.objects.all()
return context
def get_footprints(request, sat_id):
try:
sat_name = Satellite.objects.get(id=sat_id).name
footprint_names = get_band_names(sat_name)
return JsonResponse(footprint_names, safe=False)
except Exception as e:
return JsonResponse({"error": str(e)}, status=400)
class GetFootprintsView(View):
def get(self, request, sat_id):
try:
sat_name = Satellite.objects.get(id=sat_id).name
footprint_names = get_band_names(sat_name)
return JsonResponse(footprint_names, safe=False)
except Exception as e:
return JsonResponse({"error": str(e)}, status=400)
@require_GET
@cache_page(60 * 60 * 24)
def tile_proxy(request, footprint_name, z, x, y):
if not footprint_name.replace('-', '').replace('_', '').isalnum():
return HttpResponse("Invalid footprint name", status=400)
class TileProxyView(View):
@method_decorator(require_GET)
@method_decorator(cache_page(60 * 60 * 24)) # Cache for 24 hours
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
url = f"https://static.satbeams.com/tiles/{footprint_name}/{z}/{x}/{y}.png"
def get(self, request, footprint_name, z, x, y):
if not footprint_name.replace('-', '').replace('_', '').isalnum():
return HttpResponse("Invalid footprint name", status=400)
try:
resp = requests.get(url, timeout=10)
if resp.status_code == 200:
response = HttpResponse(resp.content, content_type='image/png')
response["Access-Control-Allow-Origin"] = "*"
return response
else:
return HttpResponseNotFound("Tile not found")
except Exception as e:
return HttpResponse(f"Proxy error: {e}", status=500)
url = f"https://static.satbeams.com/tiles/{footprint_name}/{z}/{x}/{y}.png"
try:
resp = requests.get(url, timeout=10)
if resp.status_code == 200:
response = HttpResponse(resp.content, content_type='image/png')
response["Access-Control-Allow-Origin"] = "*"
return response
else:
return HttpResponseNotFound("Tile not found")
except Exception as e:
return HttpResponse(f"Proxy error: {e}", status=500)
def leaflet_map(request):
sats = Satellite.objects.all()
trans = Transponders.objects.all()
return render(request, 'mapsapp/map2d.html', {'sats': sats, 'trans': trans})
class LeafletMapView(TemplateView):
template_name = 'mapsapp/map2d.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['sats'] = Satellite.objects.all()
context['trans'] = Transponders.objects.all()
return context
def get_transponder_on_satid(request, sat_id):
trans = Transponders.objects.filter(sat_id=sat_id)
output = []
for tran in trans:
output.append(
{
"name": tran.name,
"frequency": tran.frequency,
"frequency_range": tran.frequency_range,
"zone_name": tran.zone_name,
"polarization": tran.polarization.name
}
)
if not trans:
return JsonResponse({'error': 'Объектов не найдено'}, status=400)
class GetTransponderOnSatIdView(View):
def get(self, request, sat_id):
trans = Transponders.objects.filter(sat_id=sat_id)
output = []
for tran in trans:
output.append(
{
"name": tran.name,
"frequency": tran.frequency,
"frequency_range": tran.frequency_range,
"zone_name": tran.zone_name,
"polarization": tran.polarization.name
}
)
if not trans:
return JsonResponse({'error': 'Объектов не найдено'}, status=400)
return JsonResponse(output, safe=False)
return JsonResponse(output, safe=False)