Add Glacier name search for table querying
This commit is contained in:
@@ -21,6 +21,7 @@ class YearForm(FlaskForm):
|
||||
("2017", 2017),
|
||||
("2018", 2018),
|
||||
]
|
||||
name = StringField("Glacier Name")
|
||||
year = SelectField("Year", validators=[DataRequired()], choices=year_list)
|
||||
submit = SubmitField("Search")
|
||||
|
||||
|
||||
@@ -58,13 +58,20 @@ def data():
|
||||
def table_selection():
|
||||
form = YearForm()
|
||||
if form.validate_on_submit():
|
||||
annual_data = (
|
||||
db.session.query(Annual_Data).filter_by(year=form.year.data).statement
|
||||
)
|
||||
if annual_data is None:
|
||||
flash("Invalid query, please try again")
|
||||
return redirect(url_for("table_selection"))
|
||||
table = create_table(annual_data)
|
||||
annual_data = db.session.query(Annual_Data).filter_by(year=form.year.data)
|
||||
query = annual_data
|
||||
if form.name.data:
|
||||
query = (
|
||||
db.session.query(Annual_Data)
|
||||
.filter_by(year=form.year.data)
|
||||
.join(Glacier, Glacier.id == Annual_Data.id)
|
||||
.filter_by(name=form.name.data)
|
||||
.group_by(Glacier.id)
|
||||
)
|
||||
if query.scalar() is None:
|
||||
flash("Sorry, no results found")
|
||||
return redirect(url_for("table_selection"))
|
||||
table = create_table(query.statement)
|
||||
return render_template("table.html", table=table, title="Table")
|
||||
return render_template("table_selection.html", title="Data", form=form)
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
{% import 'bootstrap/wtf.html' as wtf %}
|
||||
|
||||
{% block app_content %}
|
||||
<h1>Table</h1>
|
||||
{{ table|safe }}
|
||||
<h1>Table</h1>
|
||||
{{ table|safe }}
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user