Optional: filter airports by country

pull/56/head
Konstantin Gründger 2016-07-14 21:14:55 +02:00
rodzic a039ee3185
commit 943203804f
1 zmienionych plików z 11 dodań i 2 usunięć

Wyświetl plik

@ -2,14 +2,23 @@ from ogn.model import Airport
from ogn.commands.dbutils import session
from manager import Manager
from sqlalchemy import and_, between
manager = Manager()
@manager.arg('country_code', help='filter by country code, eg. "de" for germany')
@manager.command
def list_all():
def list_all(country_code=None):
"""Show a list of all airports."""
or_args = []
if country_code is None:
or_args = [between(Airport.style, 2, 5)]
else:
or_args = [and_(between(Airport.style, 2, 5),
Airport.country_code == country_code)]
query = session.query(Airport) \
.order_by(Airport.name)
.order_by(Airport.name) \
.filter(*or_args)
print('--- Airports ---')
for airport in query.all():