diff --git a/wetter/templates/export.html b/wetter/templates/export.html index dabdc7e..7dcbc1c 100644 --- a/wetter/templates/export.html +++ b/wetter/templates/export.html @@ -9,6 +9,11 @@ {% block content %}
+ {% if e == "empty" %} + + {% endif %}

Export Zeitraum wählen @@ -18,23 +23,13 @@
-
- -
-
-
-
+
-
- -
-
-
-
+
diff --git a/wetter/templates/target.html b/wetter/templates/target.html index 1b09590..436f958 100644 --- a/wetter/templates/target.html +++ b/wetter/templates/target.html @@ -17,17 +17,13 @@
-
- -
+
-
- -
+
diff --git a/wetter/utils.py b/wetter/utils.py index e59ea25..5795a46 100644 --- a/wetter/utils.py +++ b/wetter/utils.py @@ -4,3 +4,9 @@ from datetime import datetime def fromisoformat(str): return datetime.strptime(str, '%Y-%m-%d').date() + +def toisoformat(str, alt=""): + try: + return fromisoformat(str).isoformat() + except: + return alt diff --git a/wetter/views.py b/wetter/views.py index a505609..bec66f0 100644 --- a/wetter/views.py +++ b/wetter/views.py @@ -2,9 +2,10 @@ from wetter import app, excel from wetter.models import Stations, Climate -from wetter.utils import fromisoformat -from flask import request, make_response, render_template, jsonify +from wetter.utils import fromisoformat, toisoformat +from flask import request, make_response, render_template, redirect, jsonify from datetime import datetime +from urllib.parse import urlencode @app.route('/') def index(): @@ -28,18 +29,36 @@ def station(dwd_id): @app.route('/station//export/') def export(dwd_id): + fr = toisoformat(request.args.get('from')) + to = toisoformat(request.args.get('to')) + e = request.args.get('e') + station = Stations.query.filter_by(dwd_id=dwd_id).first_or_404() - return render_template('export.html', station=station) + return render_template('export.html', e=e, station=station, fr=fr, to=to) @app.route('/station//export/target/') def export_target(dwd_id): - fr = fromisoformat(request.args.get('from')) - to = fromisoformat(request.args.get('to')) + fr = toisoformat(request.args.get('from')) + to = toisoformat(request.args.get('to')) - station = Stations.query.filter_by(dwd_id=dwd_id).first_or_404() + if fr and to: + station = Stations.query.filter_by(dwd_id=dwd_id).first_or_404() - return render_template('target.html', station=station, fr=fr.isoformat(), to=to.isoformat()) + return render_template('target.html', station=station, fr=fr, to=to) + + else: + qs = { + "e": "empty", + } + + if fr: + qs["from"] = fr + + if to: + qs["to"] = to + + return redirect('/station/' + dwd_id + '/export/?' + urlencode(qs), code=302) def export_target_ce(request, dwd_id): fr = fromisoformat(request.args.get('from'))