1
0
Fork 0

better error handling around latest_data

In satellite_card.html we assume if telemetry_data_count returns a value then latest_data will also run fine. This adds some better handling in the off chance that it does not (like in an odd cache state)

Signed-off-by: Corey Shields <cshields@gmail.com>
spacecruft
Corey Shields 2021-05-14 15:59:09 -04:00
parent 33dd436cc1
commit c217f66b2d
2 changed files with 29 additions and 25 deletions

View File

@ -326,15 +326,17 @@ class Satellite(models.Model):
data = DemodData.objects.filter(
Q(satellite=self.id) | Q(satellite__associated_satellite=self.id)
).order_by('-id')[:1]
latest_datum = data[0]
return {
'data_id': latest_datum.data_id,
'payload_frame': latest_datum.payload_frame,
'timestamp': latest_datum.timestamp,
'is_decoded': latest_datum.is_decoded,
'station': latest_datum.station,
'observer': latest_datum.observer,
}
if data:
latest_datum = data[0]
return {
'data_id': latest_datum.data_id,
'payload_frame': latest_datum.payload_frame,
'timestamp': latest_datum.timestamp,
'is_decoded': latest_datum.is_decoded,
'station': latest_datum.station,
'observer': latest_datum.observer,
}
return None
@property
def needs_help(self):

View File

@ -53,24 +53,26 @@
</div>
</div>
{% with latest_data=satellite.latest_data %}
<div class="d-flex flex-row">
<div class="d-flex satellite-card-body-row align-self-center justify-content-center" data-toggle="tooltip"
title="Latest data timestamp">
<i class="fas fa-clock"></i>
{% if latest_data %}
<div class="d-flex flex-row">
<div class="d-flex satellite-card-body-row align-self-center justify-content-center" data-toggle="tooltip"
title="Latest data timestamp">
<i class="fas fa-clock"></i>
</div>
<div class="d-inline-flex text-truncate">
{{ latest_data.timestamp|date:"Y-m-d H:i:s" }}
</div>
</div>
<div class="d-inline-flex text-truncate">
{{ latest_data.timestamp|date:"Y-m-d H:i:s" }}
<div class="d-flex flex-row">
<div class="d-flex satellite-card-body-row align-self-center justify-content-center" data-toggle="tooltip"
title="Latest data submitter">
<i class="fas fa-user"></i>
</div>
<div class="d-inline-flex text-truncate">
{{ latest_data.station }}
</div>
</div>
</div>
<div class="d-flex flex-row">
<div class="d-flex satellite-card-body-row align-self-center justify-content-center" data-toggle="tooltip"
title="Latest data submitter">
<i class="fas fa-user"></i>
</div>
<div class="d-inline-flex text-truncate">
{{ latest_data.station }}
</div>
</div>
{% endif %}
{% endwith %}
{% else %}
<div class="d-flex flex-row">