1
0
Fork 0

Merge branch 'pr/views_comments' into 'master'

views/prediction_windows: Add comments, remove single-use variable

See merge request librespacefoundation/satnogs/satnogs-network!832
merge-requests/832/merge
Fabian P. Schmidt 2019-12-19 23:51:41 +00:00
commit 3825359ad9
1 changed files with 22 additions and 8 deletions

View File

@ -376,18 +376,22 @@ def prediction_windows(request):
params = prediction_windows_parse_parameters(request)
# Check the selected satellite exists and is alive
try:
sat = Satellite.objects.filter(status='alive').get(norad_cat_id=params['sat_norad_id'])
except Satellite.DoesNotExist:
data = [{'error': 'You should select a Satellite first.'}]
return JsonResponse(data, safe=False)
# Check there is a TLE available for this satellite
try:
tle = LatestTle.objects.get(satellite_id=sat.id)
except LatestTle.DoesNotExist:
data = [{'error': 'No TLEs for this satellite yet.'}]
return JsonResponse(data, safe=False)
# Check the selected transmitter exists, and if yes,
# store this transmitter in the downlink variable
try:
transmitter = get_transmitter_by_uuid(params['transmitter'])
if not transmitter:
@ -398,12 +402,17 @@ def prediction_windows(request):
data = [{'error': error.message}]
return JsonResponse(data, safe=False)
scheduled_obs_queryset = Observation.objects.filter(end__gt=now())
# Fetch all available ground stations
stations = Station.objects.filter(status__gt=0).prefetch_related(
Prefetch('observations', queryset=scheduled_obs_queryset, to_attr='scheduled_obs'),
'antenna'
Prefetch(
'observations',
queryset=Observation.objects.filter(end__gt=now()),
to_attr='scheduled_obs'
), 'antenna'
)
if params['station_ids'] and params['station_ids'] != ['']:
# Filter ground stations based on the given selection
stations = stations.filter(id__in=params['station_ids'])
if not stations:
if len(params['station_ids']) == 1:
@ -557,10 +566,13 @@ def observation_vet(request, observation_id):
def stations_list(request):
"""View to render Stations page."""
scheduled_obs_queryset = Observation.objects.filter(end__gt=now())
stations = Station.objects.prefetch_related(
'antenna', 'owner',
Prefetch('observations', queryset=scheduled_obs_queryset, to_attr='scheduled_obs')
Prefetch(
'observations',
queryset=Observation.objects.filter(end__gt=now()),
to_attr='scheduled_obs'
)
).order_by('-status', 'id')
stations_total_obs = {
x['id']: x['total_obs']
@ -699,11 +711,13 @@ def scheduling_stations(request):
@ajax_required
def pass_predictions(request, station_id):
"""Endpoint for pass predictions"""
scheduled_obs_queryset = Observation.objects.filter(end__gt=now())
station = get_object_or_404(
Station.objects.prefetch_related(
Prefetch('observations', queryset=scheduled_obs_queryset, to_attr='scheduled_obs'),
'antenna'
Prefetch(
'observations',
queryset=Observation.objects.filter(end__gt=now()),
to_attr='scheduled_obs'
), 'antenna'
),
id=station_id
)