kopia lustrzana https://github.com/glidernet/ogn-python
Fixed logbook with missing DeviceInfo
rodzic
4979e26ab7
commit
1909442241
|
@ -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):
|
class Device(db.Model):
|
||||||
__tablename__ = 'devices'
|
__tablename__ = 'devices'
|
||||||
|
@ -25,3 +27,11 @@ class Device(db.Model):
|
||||||
self.software_version,
|
self.software_version,
|
||||||
self.hardware_version,
|
self.hardware_version,
|
||||||
self.real_address)
|
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()
|
||||||
|
|
|
@ -17,7 +17,7 @@ class DeviceInfo(db.Model):
|
||||||
|
|
||||||
address_origin = db.Column(db.SmallInteger)
|
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_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()'))
|
device = db.relationship('Device', foreign_keys=[device_id], backref=db.backref('infos', order_by='DeviceInfo.address_origin.asc()'))
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ def devices():
|
||||||
return render_template('devices.html', devices=devices)
|
return render_template('devices.html', devices=devices)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/device.html', methods=['GET', 'POST'])
|
@app.route('/device_detail.html', methods=['GET', 'POST'])
|
||||||
def device():
|
def device_detail():
|
||||||
device_id = request.args.get('id')
|
device_id = request.args.get('id')
|
||||||
device = db.session.query(Device) \
|
device = db.session.query(Device) \
|
||||||
.filter(Device.id == device_id) \
|
.filter(Device.id == device_id) \
|
||||||
|
@ -166,12 +166,11 @@ def logbook():
|
||||||
filters.append(Logbook.device_id == sel_device_id)
|
filters.append(Logbook.device_id == sel_device_id)
|
||||||
|
|
||||||
if len(filters) > 0:
|
if len(filters) > 0:
|
||||||
entries = db.session.query(Logbook, Device, DeviceInfo) \
|
logbook = db.session.query(Logbook) \
|
||||||
.filter(*filters) \
|
.filter(*filters) \
|
||||||
.filter(db.and_(Logbook.device_id == Device.id, Device.address == DeviceInfo.address)) \
|
|
||||||
.order_by(Logbook.reftime)
|
.order_by(Logbook.reftime)
|
||||||
else:
|
else:
|
||||||
entries = None
|
logbook = None
|
||||||
|
|
||||||
return render_template('logbook.html',
|
return render_template('logbook.html',
|
||||||
title='Logbook',
|
title='Logbook',
|
||||||
|
@ -181,7 +180,7 @@ def logbook():
|
||||||
airports=airports,
|
airports=airports,
|
||||||
sel_date=sel_date,
|
sel_date=sel_date,
|
||||||
dates=dates,
|
dates=dates,
|
||||||
entries=entries)
|
logbook=logbook)
|
||||||
|
|
||||||
@app.route('/statistics.html')
|
@app.route('/statistics.html')
|
||||||
def statistics():
|
def statistics():
|
||||||
|
|
|
@ -17,10 +17,10 @@
|
||||||
|
|
||||||
{% for device in devices %}
|
{% for device in devices %}
|
||||||
<tr>
|
<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 %}{{ 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.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>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
{% if entries is not none %}
|
{% if logbook is not none %}
|
||||||
<table class="datatable table table-striped table-bordered">
|
<table class="datatable table table-striped table-bordered">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Nr.</th>
|
<th>Nr.</th>
|
||||||
|
@ -41,19 +41,16 @@
|
||||||
<th colspan="2">Landing</th>
|
<th colspan="2">Landing</th>
|
||||||
<th>AGL</th>
|
<th>AGL</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for entry in entries %}
|
{% for entry in logbook %}
|
||||||
{% set logbook = entry[0] %}
|
|
||||||
{% set device = entry[1] %}
|
|
||||||
{% set device_info = entry[2] %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ loop.index }}</td>
|
<td>{{ loop.index }}</td>
|
||||||
<td><a href="{{ url_for('device', id=device.id) }}">{{ device_info.registration }}</a></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>{{ device_info.aircraft }}</td>
|
<td>{% if entry.device.info is none %}(unknown){% else %}{{ entry.device.info.aircraft }}{% endif %}</td>
|
||||||
<td>{% if logbook.takeoff_timestamp is not none %} {{ logbook.takeoff_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
<td>{% if entry.takeoff_timestamp is not none %} {{ entry.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 entry.takeoff_track is not none %} {{ '%02d' | format(entry.takeoff_track/10) }} {% endif %}</td>
|
||||||
<td>{% if logbook.landing_timestamp is not none %} {{ logbook.landing_timestamp.strftime('%H:%M') }} {% endif %}</td>
|
<td>{% if entry.landing_timestamp is not none %} {{ entry.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 entry.landing_track is not none %} {{ '%02d' | format(entry.landing_track/10) }} {% endif %}</td>
|
||||||
<td>{% if logbook.max_altitude is not none %} {{ logbook.max_altitude }} {% endif %}</td>
|
<td>{% if entry.max_altitude is not none %} {{ entry.max_altitude }} {% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Ładowanie…
Reference in New Issue