diff --git a/app/app.py b/app/app.py index 7fcceb0..0ce9441 100644 --- a/app/app.py +++ b/app/app.py @@ -3,8 +3,8 @@ import os from flask import Flask from flask import render_template -#import werkzeug +from .config import secret_key, wtf_csrf_secret_key from .routes import main APPPATH = os.path.dirname(os.path.abspath(__file__)) @@ -21,6 +21,11 @@ app = Flask( "in case we put a trailing slash at the end of the route's uri" app.url_map.strict_slashes = False +app.config.update(dict( + SECRET_KEY= secret_key, + WTF_CSRF_SECRET_KEY= wtf_csrf_secret_key +)) + @app.before_request def clear_trailing(): from flask import redirect, request diff --git a/app/config.py b/app/config.py index 9ca0549..3579bcc 100644 --- a/app/config.py +++ b/app/config.py @@ -19,4 +19,5 @@ with open(local_params_file, 'r') as file_handle: # dbadmin = params_content['dbadmin'] # dbpassword = params_content['dbpassword'] # server_ip = params_content['server_ip'] +# secret_key, wtf_csrf_secret_key """ diff --git a/app/routes.py b/app/routes.py index 10e9afb..8ffc9be 100644 --- a/app/routes.py +++ b/app/routes.py @@ -21,28 +21,44 @@ Then the 'dynamic' (calculated) routes : import typing as t -from flask import Blueprint, abort, render_template, request, send_from_directory +from flask import Blueprint, render_template, request, redirect import folium from pymongo import ASCENDING + from .dbinit import * from .helper import make_timeitem_from_filename main = Blueprint("main", __name__, url_prefix="/") +# flask wtforms +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField +from wtforms.validators import DataRequired + +class SearchForm(FlaskForm): + search = StringField('Recherche', validators=[DataRequired()]) + submit = SubmitField(label=('Rechercher')) + # ______________________________________________________________________________ # routes -@main.route("/") +@main.route("/", methods=('GET', 'POST')) def home(): """home route""" - return render_template("home.html") + form = SearchForm() + if form.validate_on_submit(): + return f'''

Welcome {form.search.data}

''' + return render_template("home.html", form=form) -@main.route("/about/") +@main.route("/about/", methods=('GET', 'POST')) def about(): """about route""" - return render_template("about.html") + form = SearchForm() + if form.validate_on_submit(): + return f'''

Welcome {form.search.data}

''' + return render_template("about.html", form=form) @main.route("/actes/") @@ -145,8 +161,8 @@ def acte(house=None, prince=None, dateitem=None): folium=result.get("folium"), transcribers=result.get('transcribers')) -@main.route("/geoloc") -def geoloc(): +@main.route("/geolocalisation") +def geolocalisation(): "global folium/leaflet map" m = folium.Map(location=[46.603354, 1.888334], zoom_start=6) for result in actecol.find(): diff --git a/app/templates/container.html b/app/templates/container.html index 1219cb8..27aebf4 100644 --- a/app/templates/container.html +++ b/app/templates/container.html @@ -27,13 +27,17 @@ + -
- - + + {{ form.csrf_token }} + +
@@ -138,4 +142,4 @@ ); - \ No newline at end of file +