diff --git a/Design.org b/Design.org index 8e7d2ab..ac691ca 100644 --- a/Design.org +++ b/Design.org @@ -46,6 +46,13 @@ CLOSED: [2019-11-01 Fri 00:34] - [X] Entity-Relationship ** Implementation *** TODO Backend [2/4] [50%] +**** TODO Flask Application [2/3] [66%] +- [ ] Plots with pandas +- [X] Login for admin +- [X] Tables with pandas +**** TODO Possible additions [1/2] [50%] +- [ ] Text search for glaciers +- [X] Form seach for a year **** DONE Database [3/3] [100%] CLOSED: [2020-01-03 Fri 00:44] - [X] Connection @@ -56,15 +63,12 @@ CLOSED: [2020-01-08 Wed 03:18] - [X] Select useful fiels - [X] Convert PU to Country (ISO 3166) - [X] Insert into database -**** TODO Flask Application [1/4] [25%] -- [ ] Arithmetic operations for yearly changes -- [ ] Tables with pandas -- [ ] Plots with pandas -- [X] Login for admin -**** TODO Possible additions [0/2] [0%] -- [ ] Text search for glaciers -- [ ] Form seach for a year -*** TODO Frontend [1/2] [50%] +*** TODO Documentation [0/2] [0%] +- [ ] Code +- [ ] Explanations (uid as Varchar, ORM) +*** TODO Deployment [0/1] [0%] +- [ ] Virtualenv installation script +*** DONE Frontend [2/2] [100%] +CLOSED: [2020-01-09 Thu 11:09] - [X] Flask-Bootstrap -- [ ] Find CSS -*** TODO Documentation +- [X] Find CSS diff --git a/code/app/forms.py b/code/app/forms.py index 55a4d2d..d30268a 100644 --- a/code/app/forms.py +++ b/code/app/forms.py @@ -1,5 +1,5 @@ from flask_wtf import FlaskForm -from wtforms import StringField, PasswordField, BooleanField, SubmitField +from wtforms import BooleanField, PasswordField, SelectField, StringField, SubmitField from wtforms.validators import DataRequired @@ -8,3 +8,39 @@ class LoginForm(FlaskForm): password = PasswordField("Password", validators=[DataRequired()]) remember_me = BooleanField("Remember Me") submit = SubmitField("Sign In") + + +class YearForm(FlaskForm): + year_list = [ + ("2011", 2011), + ("2012", 2012), + ("2013", 2013), + ("2014", 2014), + ("2015", 2015), + ("2016", 2016), + ("2017", 2017), + ("2018", 2018), + ] + year = SelectField("Year", validators=[DataRequired()], choices=year_list) + submit = SubmitField("Search") + + +class IntervalForm(FlaskForm): + year_list = [ + ("2011", 2011), + ("2012", 2012), + ("2013", 2013), + ("2014", 2014), + ("2015", 2015), + ("2016", 2016), + ("2017", 2017), + ("2018", 2018), + ] + name = StringField("Glacier Name") + lower_bound = SelectField( + "First year", validators=[DataRequired()], choices=year_list + ) + upper_bound = SelectField( + "Second year", validators=[DataRequired()], choices=year_list + ) + submit = SubmitField("Search") diff --git a/code/app/routes.py b/code/app/routes.py index 12f8de4..1f69e5b 100644 --- a/code/app/routes.py +++ b/code/app/routes.py @@ -1,9 +1,10 @@ -from app import app -from app.forms import LoginForm -from app.models import User +from app import app, db +from app.forms import LoginForm, YearForm, IntervalForm +from app.models import User, Annual_Data, Glacier from flask import flash, redirect, render_template, url_for, request from flask_login import current_user, login_user, logout_user, login_required from werkzeug.urls import url_parse +from processing.tabulate import create_table @app.route("/") @@ -53,9 +54,24 @@ def data(): return render_template("data.html", title="Data") -@app.route("/tables") -def tables(): - return render_template("data.html", title="Data") +@app.route("/table_selection", methods=["GET", "POST"]) +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) + return render_template("table.html", table=table, title="Table") + return render_template("table_selection.html", title="Data", form=form) + + +@app.route("/table") +def table(): + return render_template("table.html", table=table, title="Table") @app.route("/plots") diff --git a/code/app/templates/admin.html b/code/app/templates/admin.html index 97dd31b..18a7bca 100644 --- a/code/app/templates/admin.html +++ b/code/app/templates/admin.html @@ -1,7 +1,16 @@ {% extends "base.html" %} {% block content %} -
Do you want to nuke the database?
++ Nah, show me some cool data +
++ Tables +
++ Plots +
+