Export form validation
This commit is contained in:
parent
0b5ae309ce
commit
b6da7dc2ce
@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<section>
|
<section>
|
||||||
|
{% if e == "empty" %}
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
Ein oder mehrere Eingabefelder sind leer oder haben das falsche Format.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
<h2>
|
<h2>
|
||||||
Export
|
Export
|
||||||
<small class="text-muted">Zeitraum wählen</small>
|
<small class="text-muted">Zeitraum wählen</small>
|
||||||
@ -18,23 +23,13 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="datetimepicker-from">von</label>
|
<label for="datetimepicker-from">von</label>
|
||||||
<div class="input-group" id="datetimepicker-from">
|
<input type="date" value="{{ fr }}" name="from" class="form-control" id="datetimepicker-from" required>
|
||||||
<input type="text" name="from" class="form-control" placeholder="yyyy-mm-dd">
|
|
||||||
<div class="input-group-append">
|
|
||||||
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="datetimepicker-to">bis</label>
|
<label for="datetimepicker-to">bis</label>
|
||||||
<div class="input-group" id="datetimepicker-to">
|
<input type="date" value="{{ to }}" name="to" class="form-control" id="datetimepicker-to" required>
|
||||||
<input type="text" name="to" class="form-control" placeholder="yyyy-mm-dd">
|
|
||||||
<div class="input-group-append">
|
|
||||||
<div class="input-group-text"><i class="fa fa-calendar"></i></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -17,17 +17,13 @@
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="datetimepicker-from">von</label>
|
<label for="datetimepicker-from">von</label>
|
||||||
<div class="input-group" id="datetimepicker-from">
|
<input type="date" value="{{ fr }}" class="form-control" id="datetimepicker-from" disabled>
|
||||||
<input type="text" value="{{ fr }}" class="form-control" placeholder="yyyy-mm-dd" disabled>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="datetimepicker-to">bis</label>
|
<label for="datetimepicker-to">bis</label>
|
||||||
<div class="input-group" id="datetimepicker-to">
|
<input type="date" value="{{ to }}" class="form-control" id="datetimepicker-to" disabled>
|
||||||
<input type="text" value="{{ to }}" class="form-control" placeholder="yyyy-mm-dd" disabled>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,3 +4,9 @@ from datetime import datetime
|
|||||||
|
|
||||||
def fromisoformat(str):
|
def fromisoformat(str):
|
||||||
return datetime.strptime(str, '%Y-%m-%d').date()
|
return datetime.strptime(str, '%Y-%m-%d').date()
|
||||||
|
|
||||||
|
def toisoformat(str, alt=""):
|
||||||
|
try:
|
||||||
|
return fromisoformat(str).isoformat()
|
||||||
|
except:
|
||||||
|
return alt
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
|
|
||||||
from wetter import app, excel
|
from wetter import app, excel
|
||||||
from wetter.models import Stations, Climate
|
from wetter.models import Stations, Climate
|
||||||
from wetter.utils import fromisoformat
|
from wetter.utils import fromisoformat, toisoformat
|
||||||
from flask import request, make_response, render_template, jsonify
|
from flask import request, make_response, render_template, redirect, jsonify
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
@ -28,18 +29,36 @@ def station(dwd_id):
|
|||||||
|
|
||||||
@app.route('/station/<dwd_id>/export/')
|
@app.route('/station/<dwd_id>/export/')
|
||||||
def export(dwd_id):
|
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()
|
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/<dwd_id>/export/target/')
|
@app.route('/station/<dwd_id>/export/target/')
|
||||||
def export_target(dwd_id):
|
def export_target(dwd_id):
|
||||||
fr = fromisoformat(request.args.get('from'))
|
fr = toisoformat(request.args.get('from'))
|
||||||
to = fromisoformat(request.args.get('to'))
|
to = toisoformat(request.args.get('to'))
|
||||||
|
|
||||||
|
if fr and to:
|
||||||
station = Stations.query.filter_by(dwd_id=dwd_id).first_or_404()
|
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):
|
def export_target_ce(request, dwd_id):
|
||||||
fr = fromisoformat(request.args.get('from'))
|
fr = fromisoformat(request.args.get('from'))
|
||||||
|
Loading…
Reference in New Issue
Block a user