Внёс мелкие правки и фиксы

This commit is contained in:
2025-11-21 10:31:26 +03:00
parent c2c8c8799f
commit 58838614a5
13 changed files with 423 additions and 99 deletions

View File

@@ -570,3 +570,55 @@ class SatelliteDataAPIView(LoginRequiredMixin, View):
return JsonResponse({'error': 'Спутник не найден'}, status=404)
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)
class SatelliteDataAPIView(LoginRequiredMixin, View):
"""API endpoint for getting Satellite data."""
def get(self, request, satellite_id):
from ..models import Satellite
try:
satellite = Satellite.objects.prefetch_related('band').get(id=satellite_id)
# Format launch_date
launch_date_str = '-'
if satellite.launch_date:
launch_date_str = satellite.launch_date.strftime("%d.%m.%Y")
# Format created_at and updated_at
created_at_str = '-'
if satellite.created_at:
local_time = timezone.localtime(satellite.created_at)
created_at_str = local_time.strftime("%d.%m.%Y %H:%M")
updated_at_str = '-'
if satellite.updated_at:
local_time = timezone.localtime(satellite.updated_at)
updated_at_str = local_time.strftime("%d.%m.%Y %H:%M")
# Get band names
bands = list(satellite.band.values_list('name', flat=True))
bands_str = ', '.join(bands) if bands else '-'
data = {
'id': satellite.id,
'name': satellite.name,
'norad': satellite.norad if satellite.norad else None,
'bands': bands_str,
'undersat_point': satellite.undersat_point if satellite.undersat_point is not None else None,
'url': satellite.url or None,
'comment': satellite.comment or '-',
'launch_date': launch_date_str,
'created_at': created_at_str,
'updated_at': updated_at_str,
'created_by': str(satellite.created_by) if satellite.created_by else '-',
'updated_by': str(satellite.updated_by) if satellite.updated_by else '-',
}
return JsonResponse(data)
except Satellite.DoesNotExist:
return JsonResponse({'error': 'Спутник не найден'}, status=404)
except Exception as e:
return JsonResponse({'error': str(e)}, status=500)