Fixed logbook with missing DeviceInfo

pull/78/head
Konstantin Gründger 2019-03-23 13:57:44 +01:00
rodzic 4979e26ab7
commit 1909442241
5 zmienionych plików z 28 dodań i 22 usunięć

Wyświetl plik

@ -1,5 +1,7 @@
from ogn_python import db
from sqlalchemy.ext.hybrid import hybrid_property
from ogn_python import db
from .device_info import DeviceInfo
class Device(db.Model):
__tablename__ = 'devices'
@ -25,3 +27,11 @@ class Device(db.Model):
self.software_version,
self.hardware_version,
self.real_address)
@hybrid_property
def info(self):
query = db.session.query(DeviceInfo) \
.filter(DeviceInfo.address == self.address) \
.order_by(DeviceInfo.address_origin)
return query.first()

Wyświetl plik

@ -17,7 +17,7 @@ class DeviceInfo(db.Model):
address_origin = db.Column(db.SmallInteger)
# Relations
# Relations (deprecated)
device_id = db.Column(db.Integer, db.ForeignKey('devices.id', ondelete='SET NULL'), index=True)
device = db.relationship('Device', foreign_keys=[device_id], backref=db.backref('infos', order_by='DeviceInfo.address_origin.asc()'))

Wyświetl plik

@ -20,8 +20,8 @@ def devices():
return render_template('devices.html', devices=devices)
@app.route('/device.html', methods=['GET', 'POST'])
def device():
@app.route('/device_detail.html', methods=['GET', 'POST'])
def device_detail():
device_id = request.args.get('id')
device = db.session.query(Device) \
.filter(Device.id == device_id) \
@ -166,12 +166,11 @@ def logbook():
filters.append(Logbook.device_id == sel_device_id)
if len(filters) > 0:
entries = db.session.query(Logbook, Device, DeviceInfo) \
logbook = db.session.query(Logbook) \
.filter(*filters) \
.filter(db.and_(Logbook.device_id == Device.id, Device.address == DeviceInfo.address)) \
.order_by(Logbook.reftime)
else:
entries = None
logbook = None
return render_template('logbook.html',
title='Logbook',
@ -181,7 +180,7 @@ def logbook():
airports=airports,
sel_date=sel_date,
dates=dates,
entries=entries)
logbook=logbook)
@app.route('/statistics.html')
def statistics():

Wyświetl plik

@ -17,10 +17,10 @@
{% for device in devices %}
<tr>
<td><a href="{{ url_for('device', id=device.id) }}">{{ device.address }}</a></td>
<td><a href="{{ url_for('device_detail', id=device.id) }}">{{ device.address }}</a></td>
<td>{% if device.takeoff_landings %}{% set last_action = device.takeoff_landings|last %}{{ last_action.airport.name }}{% endif %}
<td>{% if device.takeoff_landings %}{% set last_action = device.takeoff_landings|last %}{% if last_action.is_takeoff == True %}↗{% else %}↘{% endif %} @ {{ last_action.timestamp.strftime('%Y-%m-%d %H:%M:%S') }}{% endif %}
<td>{% if device.infos %}{% set info = device.infos|first %}{{ info.registration }} {% else %} - {% endif %}</td>
<td>{% if device.info is not none %}{{ device.info.registration }}{% else %} - {% endif %}</td>
<td>{% if device.software_version is not none %}{% if device.software_version < 6.6 %}<p class="text-danger">{{ device.software_version }}</p>{% else %}{{ device.software_version }}{% endif %}{% else %} - {% endif %}</td>
</tr>
{% endfor %}

Wyświetl plik

@ -31,7 +31,7 @@
</form>
{% if entries is not none %}
{% if logbook is not none %}
<table class="datatable table table-striped table-bordered">
<tr>
<th>Nr.</th>
@ -41,19 +41,16 @@
<th colspan="2">Landing</th>
<th>AGL</th>
</tr>
{% for entry in entries %}
{% set logbook = entry[0] %}
{% set device = entry[1] %}
{% set device_info = entry[2] %}
{% for entry in logbook %}
<tr>
<td>{{ loop.index }}</td>
<td><a href="{{ url_for('device', id=device.id) }}">{{ device_info.registration }}</a></td>
<td>{{ device_info.aircraft }}</td>
<td>{% if logbook.takeoff_timestamp is not none %} {{ logbook.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
<td>{% if logbook.takeoff_track is not none %} {{ '%02d' | format(logbook.takeoff_track/10) }} {% endif %}</td>
<td>{% if logbook.landing_timestamp is not none %} {{ logbook.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
<td>{% if logbook.landing_track is not none %} {{ '%02d' | format(logbook.landing_track/10) }} {% endif %}</td>
<td>{% if logbook.max_altitude is not none %} {{ logbook.max_altitude }} {% endif %}</td>
<td><a href="{{ url_for('device_detail', id=entry.device.id) }}">{% if entry.device.info is none %}{{ entry.device.address }}{% else %}{{ entry.device.info.registration }}{% endif %}</a></td>
<td>{% if entry.device.info is none %}(unknown){% else %}{{ entry.device.info.aircraft }}{% endif %}</td>
<td>{% if entry.takeoff_timestamp is not none %} {{ entry.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
<td>{% if entry.takeoff_track is not none %} {{ '%02d' | format(entry.takeoff_track/10) }} {% endif %}</td>
<td>{% if entry.landing_timestamp is not none %} {{ entry.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
<td>{% if entry.landing_track is not none %} {{ '%02d' | format(entry.landing_track/10) }} {% endif %}</td>
<td>{% if entry.max_altitude is not none %} {{ entry.max_altitude }} {% endif %}</td>
</tr>
{% endfor %}
</table>