From bec6b19d1c0d628aa669d410b28425bfb967488d Mon Sep 17 00:00:00 2001 From: coolneng Date: Fri, 12 Jun 2020 22:49:49 +0200 Subject: [PATCH] Add dataset selection with validation --- app/__init__.py | 2 ++ app/forms.py | 9 +++++++++ app/routes.py | 11 ++++++++++- app/templates/base.html | 8 -------- app/templates/data.html | 21 +++++++++------------ shell.nix | 1 + 6 files changed, 31 insertions(+), 21 deletions(-) create mode 100644 app/forms.py diff --git a/app/__init__.py b/app/__init__.py index e1997a7..a996400 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -6,3 +6,5 @@ from flask_bootstrap import Bootstrap app = Flask(__name__) app.secret_key = SECRET_KEY bootstrap = Bootstrap(app) + +from app import errors, routes diff --git a/app/forms.py b/app/forms.py new file mode 100644 index 0000000..9b9aed0 --- /dev/null +++ b/app/forms.py @@ -0,0 +1,9 @@ +from constants import DATASETS +from flask_wtf import FlaskForm +from wtforms import SelectField, SubmitField +from wtforms.validators import DataRequired + + +class DatasetForm(FlaskForm): + dataset = SelectField(validators=[DataRequired()], choices=DATASETS) + submit = SubmitField("Submit") diff --git a/app/routes.py b/app/routes.py index b89650d..41fb0b6 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,6 +1,7 @@ from flask import render_template from app import app +from app.forms import DatasetForm @app.route("/") @@ -11,4 +12,12 @@ def index(): @app.route("/data") def data(): - return render_template("data.html", title="Data") + form = DatasetForm() + if form.validate_on_submit(): + return render_template("visualization.html", form=form, title="Visualization") + return render_template("data.html", title="Data", form=form) + + +@app.route("/visualization") +def visualization(): + return render_template("visualization.html", title="Visualization", form=form) diff --git a/app/templates/base.html b/app/templates/base.html index 410165e..5a3a6c3 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -29,14 +29,6 @@ {% block content %}
- {% with messages = get_flashed_messages() %} - {% if messages %} - {% for message in messages %} - - {% endfor %} - {% endif %} - {% endwith %} - {# application content needs to be provided in the app_content block #} {% block app_content %}{% endblock %}
diff --git a/app/templates/data.html b/app/templates/data.html index 3e695c9..8d14c53 100644 --- a/app/templates/data.html +++ b/app/templates/data.html @@ -1,15 +1,12 @@ {% extends "base.html" %} +{% import 'bootstrap/wtf.html' as wtf %} -{% block content %} -

How you like your data?

-
  • -

    - Maps -

    -
  • -
  • -

    - Plots -

    -
  • +{% block app_content %} +

    Select a dataset

    +
    +
    + {{ wtf.quick_form(form) }} +
    +
    +
    {% endblock %} diff --git a/shell.nix b/shell.nix index ec9d83d..95ab49b 100644 --- a/shell.nix +++ b/shell.nix @@ -10,6 +10,7 @@ pkgs.mkShell { flask flask-bootstrap flask_wtf + matplotlib folium pytest # Development tools