Add table querying via form
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Hey, {{ current_user.username }}!</h1>
|
||||
Do you want to nuke the database?
|
||||
<li><a href="{{ url_for('nuke') }}">Yes, I want to burn down the world</a></li>
|
||||
<h1 class="text-center">Hey, {{ current_user.username }}!</h1>
|
||||
<p class="text-center">Do you want to nuke the database?</p>
|
||||
<li>
|
||||
<p class="text-center">
|
||||
<a href="{{ url_for('nuke') }}"><b>Yes</b>, I want to burn down the world</a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p class="text-center">
|
||||
Nah, show me some cool <a href="{{ url_for('data') }}">data</a>
|
||||
</p>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{% extends 'bootstrap/base.html' %}
|
||||
|
||||
{% block title %}
|
||||
IGDB
|
||||
{% if title %}{{ title }} - IGDB{% else %}IGDB{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block styles %}
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Hey, {{ current_user.username }}!</h1>
|
||||
Wanna check out some cool data?
|
||||
<li><a href="{{ url_for('tables') }}"></a></li>
|
||||
<li><a href="{{ url_for('plots') }}"></a></li>
|
||||
<h1 class="text-center">What do you want to check out?</h1>
|
||||
<li>
|
||||
<p class="text-center">
|
||||
<a href="{{ url_for('table_selection') }}">Tables</a>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p class="text-center">
|
||||
<a href="{{ url_for('plots') }}">Plots</a>
|
||||
</p>
|
||||
</li>
|
||||
{% endblock %}
|
||||
|
||||
7
code/app/templates/table.html
Normal file
7
code/app/templates/table.html
Normal file
@@ -0,0 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
{% import 'bootstrap/wtf.html' as wtf %}
|
||||
|
||||
{% block app_content %}
|
||||
<h1>Table</h1>
|
||||
{{ table|safe }}
|
||||
{% endblock %}
|
||||
12
code/app/templates/table_selection.html
Normal file
12
code/app/templates/table_selection.html
Normal file
@@ -0,0 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
{% import 'bootstrap/wtf.html' as wtf %}
|
||||
|
||||
{% block app_content %}
|
||||
<h1>Table selection</h1>
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
{{ wtf.quick_form(form) }}
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user