diff --git a/code/app/forms.py b/code/app/forms.py index d30268a..1c73f14 100644 --- a/code/app/forms.py +++ b/code/app/forms.py @@ -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") diff --git a/code/app/routes.py b/code/app/routes.py index 1f69e5b..c16dfd8 100644 --- a/code/app/routes.py +++ b/code/app/routes.py @@ -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) diff --git a/code/app/templates/table.html b/code/app/templates/table.html index b8dc318..dbc7da9 100644 --- a/code/app/templates/table.html +++ b/code/app/templates/table.html @@ -2,6 +2,6 @@ {% import 'bootstrap/wtf.html' as wtf %} {% block app_content %} -