Show all matching annual data for glacier's name
This commit is contained in:
parent
65d3af6817
commit
1e52bcae0d
|
@ -21,8 +21,8 @@ class YearForm(FlaskForm):
|
||||||
("2017", 2017),
|
("2017", 2017),
|
||||||
("2018", 2018),
|
("2018", 2018),
|
||||||
]
|
]
|
||||||
name = StringField("Glacier Name")
|
name = StringField("Search by Glacier Name")
|
||||||
year = SelectField("Year", validators=[DataRequired()], choices=year_list)
|
year = SelectField("Search by Year", validators=[DataRequired()], choices=year_list)
|
||||||
submit = SubmitField("Search")
|
submit = SubmitField("Search")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -60,9 +60,6 @@ def table_selection():
|
||||||
form = YearForm()
|
form = YearForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
query = query_annual_data(form)
|
query = query_annual_data(form)
|
||||||
if query.scalar() is None:
|
|
||||||
flash("Sorry, no results found")
|
|
||||||
return redirect(url_for("table_selection"))
|
|
||||||
table = create_table(query.statement)
|
table = create_table(query.statement)
|
||||||
return render_template("table.html", table=table, title="Table")
|
return render_template("table.html", table=table, title="Table")
|
||||||
return render_template("table_selection.html", title="Data", form=form)
|
return render_template("table_selection.html", title="Data", form=form)
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
{% import 'bootstrap/wtf.html' as wtf %}
|
{% import 'bootstrap/wtf.html' as wtf %}
|
||||||
|
|
||||||
{% block app_content %}
|
{% block app_content %}
|
||||||
<h1>Sign In</h1>
|
<h1>Sign In</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-4">
|
<div class="col-md-4">
|
||||||
{{ wtf.quick_form(form) }}
|
{{ wtf.quick_form(form) }}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<br>
|
</div>
|
||||||
|
<br>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -4,4 +4,5 @@
|
||||||
{% block app_content %}
|
{% block app_content %}
|
||||||
<h1>Table</h1>
|
<h1>Table</h1>
|
||||||
{{ table|safe }}
|
{{ table|safe }}
|
||||||
|
<p><a href="{{ url_for('table_selection') }}">Back</a></p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
from app.models import Glacier, Annual_Data, User
|
|
||||||
from app import db
|
from app import db
|
||||||
|
from app.models import Annual_Data, Glacier, User
|
||||||
|
from flask_sqlalchemy import BaseQuery
|
||||||
|
from flask import flash, redirect, url_for
|
||||||
|
|
||||||
|
|
||||||
def query_annual_data(form):
|
def query_annual_data(form) -> BaseQuery:
|
||||||
annual_data = db.session.query(Annual_Data).filter_by(year=form.year.data)
|
annual_data = db.session.query(Annual_Data).filter_by(year=form.year.data)
|
||||||
query = annual_data
|
|
||||||
if form.name.data:
|
if form.name.data:
|
||||||
query = (
|
glacier_name = (
|
||||||
db.session.query(Annual_Data)
|
db.session.query(Annual_Data)
|
||||||
.filter_by(year=form.year.data)
|
|
||||||
.join(Glacier, Glacier.id == Annual_Data.id)
|
.join(Glacier, Glacier.id == Annual_Data.id)
|
||||||
.filter_by(name=form.name.data)
|
.filter_by(name=form.name.data)
|
||||||
.group_by(Glacier.id)
|
.group_by(Annual_Data.year)
|
||||||
)
|
)
|
||||||
return query
|
if glacier_name.first() is None:
|
||||||
|
flash("Sorry, no results found")
|
||||||
|
return redirect(url_for("table_selection"))
|
||||||
|
return glacier_name
|
||||||
|
return annual_data
|
||||||
|
|
||||||
|
|
||||||
def query_user(form):
|
def query_user(form) -> BaseQuery:
|
||||||
user = User.query.filter_by(username=form.username.data).first()
|
user = User.query.filter_by(username=form.username.data).first()
|
||||||
return user
|
return user
|
||||||
|
|
Loading…
Reference in New Issue