Added receiver details view

pull/78/head
Konstantin Gründger 2019-03-19 15:19:11 +01:00
rodzic 54ef1411a5
commit da188b69f9
5 zmienionych plików z 125 dodań i 15 usunięć

Wyświetl plik

@ -1,4 +1,5 @@
from flask import request, render_template
from sqlalchemy import func, and_, or_
from ogn_python import app
from ogn_python import db
@ -28,21 +29,68 @@ def devices():
@app.route('/receivers')
def receivers():
receivers = db.session.query(Receiver) \
.filter(Receiver.country != db.null()) \
.order_by(Receiver.name)
return render_template('receivers.html', receivers=receivers)
sel_country = request.args.get('country')
countries_in_receivers = db.session.query(Country.iso2, func.count(Receiver.id).label('receiver_count')) \
.filter(Country.gid == Receiver.country_id) \
.group_by(Country.iso2) \
.order_by(Country.iso2)
# Get receiver selection list
if sel_country:
receivers = db.session.query(Receiver) \
.filter(and_(Receiver.country_id == Country.gid, Country.iso2 == sel_country)) \
.order_by(Receiver.name)
else:
receivers = db.session.query(Receiver) \
.order_by(Receiver.name)
return render_template('receivers.html', sel_country=sel_country, countries=countries_in_receivers, receivers=receivers)
@app.route('/airports')
@app.route('/receiver')
def receiver():
sel_receiver_id = request.args.get('receiver_id')
receiver = db.session.query(Receiver) \
.filter(Receiver.id == sel_receiver_id)
near_airports = db.session.query(Airport, func.st_distancesphere(Airport.location_wkt, Receiver.location_wkt).label('distance')) \
.filter(and_(Receiver.id == sel_receiver_id), func.st_contains(func.st_buffer(Receiver.location_wkt, 0.5), Airport.location_wkt)) \
.filter(Airport.style.in_((2,4,5))) \
.order_by(func.st_distancesphere(Airport.location_wkt, Receiver.location_wkt)) \
.limit(10)
return render_template('receiver.html', receiver=receiver, near_airports=near_airports)
@app.route('/airports', methods=['GET', 'POST'])
def airports():
sel_country = request.args.get('country')
countries_in_logbook = db.session.query(Country.iso2, func.count(Airport.id).label('airport_count')) \
.filter(Country.iso2 == Airport.country_code) \
.group_by(Country.iso2) \
.order_by(Country.iso2)
if sel_country:
airports = db.session.query(Airport) \
.filter(and_(or_(Logbook.takeoff_airport_id == Airport.id, Logbook.landing_airport_id == Airport.id), Country.iso2 == Airport.country_code)) \
.group_by(Airport.id) \
.order_by(Airport.name)
else:
airports = db.session.query(Airport) \
.filter(or_(Logbook.takeoff_airport_id == Airport.id, Logbook.landing_airport_id == Airport.id)) \
.group_by(Airport.id) \
.order_by(Airport.name)
page = request.args.get('page', 1, type=int)
pagination = db.session.query(Airport) \
.order_by(Airport.name) \
.paginate(page, 20, False)
return render_template('airports.html', pagination=pagination)
return render_template('airports.html', sel_country=sel_country, countries=countries_in_logbook, airports=airports)
@app.route('/airport')
def airport():
pass
@app.route('/logbook', methods=['GET', 'POST'])
def logbook():
@ -73,6 +121,11 @@ def logbook():
.filter(Airport.id == airport_ids_in_logbook.c.id) \
.filter(Airport.country_code == sel_country) \
.order_by(Airport.name)
elif sel_airport:
airports = db.session.query(Airport) \
.filter(Airport.id == sel_airport)
sel_country = airports.one().country_code
else:
airports = ['']

Wyświetl plik

@ -2,10 +2,24 @@
{% block content %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/flags/flags.css') }}"/>
<div class="container">
<div class="panel panel-success">
<div class="panel-heading"><h3 class="panel-title">Airports</h3></div>
<div class="panel-body">
<form>
<div class="well">
<select name="country" onchange="this.form.submit();">
<option value="">(none)</option>
{% for country in countries %}
<option value="{{ country.iso2 }}"{% if sel_country == country.iso2 %} SELECTED{% endif %}>{{ country.iso2 }}</option>
{% endfor %}
</select>
</div>
</form>
<table class="datatable table table-striped table-bordered">
<tr>
<th>#</th>
@ -13,10 +27,10 @@
<th>Country</th>
</tr>
{% for airport in pagination.items %}
{% for airport in airports %}
<tr>
<td>{{ loop.index }}
<td>{{ airport.name }}</td>
<td><a href="{{ url_for('airport', id=airport.id) }}">{{ airport.name }}</a></td>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/></td>
</tr>
{% endfor %}

Wyświetl plik

@ -5,7 +5,7 @@
{% endblock %}
{% block navbar %}
{{nav.top_menubar.render()}}
{{ nav.top_menubar.render() }}
{% endblock %}
{% block content %}

Wyświetl plik

@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block content %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/flags/flags.css') }}"/>
<div class="container">
<div class="panel panel-success" id="asdf">
<div class="panel-heading"><h3 class="panel-title">Receiver</h3></div>
<div class="panel-body">
<table class="datatable table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Country</th>
<th>Distance</th>
</tr>
{% for tupel in near_airports %}
{% set airport = tupel[0] %}
{% set distance = tupel[1] %}
<tr>
<td>{% if airport.takeoff_landings %}<a href="{{ url_for('logbook', airport=airport.id) }}">{{ airport.name }}</a>{% else %}{{ airport.name }}{% endif %}</td>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ airport.country_code|lower }}" alt="{{ airport.country_code }}"/></td>
<td>{{ '%0.1f'|format(distance/1000) }} km</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}

Wyświetl plik

@ -2,12 +2,24 @@
{% block content %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/flags/flags.css') }}"/>
<link rel="stylesheet" href="{{ url_for('static', filename='css/flags/flags.css') }}"/>
<div class="container">
<div class="panel panel-success" id="asdf">
<div class="panel-heading"><h3 class="panel-title">Receivers</h3></div>
<div class="panel-body">
<form>
<div class="well">
<select name="country" onchange="this.form.submit();">
<option value="">(all)</option>
{% for country in countries %}
<option value="{{ country.iso2 }}"{% if sel_country == country.iso2 %} SELECTED{% endif %}>{{ country.iso2 }} ({{ country.receiver_count }})</option>
{% endfor %}
</select>
</div>
</form>
<table class="datatable table table-striped table-bordered">
<tr>
<th>Name</th>
@ -17,9 +29,9 @@
{% for receiver in receivers %}
<tr>
<td>{{ receiver.name }}</td>
<td><a href="{{ url_for('receiver', receiver_id=receiver.id) }}">{{ receiver.name }}</a></td>
<td><img src="{{ url_for('static', filename='img/Transparent.gif') }}" class="flag flag-{{ receiver.country.iso2|lower }}" alt="{{ receiver.country.iso2 }}"/></td>
<td>{{ receiver.altitude }}</td>
<td>{{ receiver.altitude|int }}</td>
</tr>
{% endfor %}
</table>