diff --git a/.gitignore b/.gitignore
index 29eeee3..e6b4e53 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
.venv/*
-
+params.yaml
diff --git a/app/app.py b/app/app.py
index 26f198f..04b3add 100644
--- a/app/app.py
+++ b/app/app.py
@@ -3,13 +3,14 @@ import os
from flask import Flask
from flask import render_template
-import werkzeug
+#import werkzeug
+
+from .routes import main
APPPATH = os.path.dirname(os.path.abspath(__file__))
templates = os.path.join(APPPATH, "templates")
static = os.path.join(APPPATH, "static")
-
app = Flask(
"Princely-Acts",
template_folder=templates,
@@ -19,17 +20,13 @@ app = Flask(
@app.errorhandler(404)
-def page_not_found(e: werkzeug.exceptions.HTTPException) -> t.Tuple[t.Text, int]:
+def page_not_found(e):
return render_template("404.html", title="Page non trouvée"), 404
@app.errorhandler(500)
-def internal_server_error(e: werkzeug.exceptions.HTTPException) -> t.Tuple[t.Text, int]:
+def internal_server_error(e):
return render_template("500.html", title="Erreur interne du serveur"), 500
+app.register_blueprint(main)
-### DEBUG
-@app.route('/')
-@app.route('/index')
-def hello_world():
- return "
Hello, World!
"
diff --git a/app/config.py b/app/config.py
new file mode 100644
index 0000000..9ca0549
--- /dev/null
+++ b/app/config.py
@@ -0,0 +1,22 @@
+"""Application's configuration file"""
+
+from pathlib import Path
+
+# path configuration
+# let's guess that :file:`config.py` is located here : :file:`{rootpath}/app/`
+_here = Path(__file__).resolve().parent
+rootpath = _here.parent
+"root project directory"
+
+from yaml import safe_load
+
+# loads database credentials in the globals config module
+local_params_file = rootpath / "params.yaml"
+with open(local_params_file, 'r') as file_handle:
+ params_content = safe_load(file_handle)
+ globals().update(params_content)
+"""
+# dbadmin = params_content['dbadmin']
+# dbpassword = params_content['dbpassword']
+# server_ip = params_content['server_ip']
+"""
diff --git a/app/helper.py b/app/helper.py
new file mode 100644
index 0000000..29918c0
--- /dev/null
+++ b/app/helper.py
@@ -0,0 +1,26 @@
+"helper functions"
+
+from flask import abort
+
+def find_one_or_404(collection, **kwargs):
+ """Find a single document or raise a 404.
+
+ This is like :meth:`~pymongo.collection.Collection.find_one`, but
+ rather than returning ``None``, cause a 404 Not Found HTTP status
+ on the request.
+
+ .. code-block:: python
+
+ usercollection = mydb['usercollection']
+
+ @app.route("/user/")
+ def user_profile(username):
+ userfound = find_one_or_404(usercollection, {"_id": username})
+ return render_template("user.html",
+ user=userfound)
+ """
+ found = collection.find_one(**kwargs)
+ if found is None:
+ abort(404)
+ return found
+
diff --git a/app/routes.py b/app/routes.py
new file mode 100644
index 0000000..9460cc7
--- /dev/null
+++ b/app/routes.py
@@ -0,0 +1,86 @@
+import typing as t
+import urllib.parse
+
+from flask import Blueprint, abort, render_template, request, send_from_directory
+from pymongo import MongoClient
+
+from .config import dbadmin, dbpassword, server_ip
+from .helper import find_one_or_404
+
+
+main = Blueprint("main", __name__, url_prefix="/")
+
+# database connexion
+username = urllib.parse.quote_plus(dbadmin)
+password = urllib.parse.quote_plus(dbpassword)
+dbclient = MongoClient(f'mongodb://{username}:{password}@{server_ip}:27017')
+actesdb = dbclient["actesdb"]
+housecol = actesdb["house"]
+
+
+@main.route("/")
+def home():
+ """home route"""
+ return render_template("home.html")
+
+
+@main.route("/about/")
+def about():
+ """about route"""
+ return render_template("about.html")
+
+
+@main.route("/actes/")
+def corpora_all():
+ """copora all
+
+ lists houses
+ sample_house_names = ["Bourbon", "Berry", "Anjou", ...]
+ """
+ houses = list(housecol.find())
+ return render_template("corpora_all.html", houses=houses)
+
+
+@main.route("/actes/") # dont put a slash at the end
+def actes(house):
+ """actes route"""
+ #house = "Berry"
+ # FIXME faire des princes correspondant à la maison (house) sélectionnée
+ # FIXME : supprimer ces ids
+ # Corpus > Bourbon
+ princes = [("Charles Ier de Bourbon", 36), ("Agnès de Bourgogne", 38),
+ ("Marie de Berry", 39)]
+ return render_template("corpus.html", house=house, princes=princes)
+
+
+# FIXME SLUGGIFY the house
+# FIXME supprimer cet id de prince et remplacer par le slug du prince
+@main.route("/actes//") # don't put a slash at the end
+def prince_corpus(house=None, prince=None):
+ """copora prince, **timeline view**"""
+ return "FIXME"
+
+
+# FIXME : slugigy this route (remove acte_id) (prince and acte)
+# FIXME: isn't it /acte/house/prince/slug instead of /acte/prince/slug ?
+@main.route("/acte//") # don't put a slash at the end
+def acte(house=None, prince=None, acte_id=None):
+ """specific prince's acte"""
+ return "FIXME"
+
+@main.route("/contact")
+def contact() -> t.Text:
+ """Displays the Contact page"""
+ return render_template("contact.html", title="Contact")
+
+
+@main.route("/termsofservice")
+def terms() -> t.Text:
+ """Displaysthe T&C page."""
+ return render_template("terms.html", title="Mentions légales")
+
+
+@main.route("/privacy")
+def privacy() -> t.Text:
+ """Displays the privacy policy page."""
+ return render_template("privacy.html", title="Politique de confidentialité")
diff --git a/app/templates/corpora_all.html b/app/templates/corpora_all.html
index f932c94..8e4208c 100644
--- a/app/templates/corpora_all.html
+++ b/app/templates/corpora_all.html
@@ -4,9 +4,9 @@
Corpus
Corpus disponibles :
-
-{% endblock %}
\ No newline at end of file
+ {% for house in houses %}
+ Actes des ducs et duchesses {{ house.particle }}
+
+ {% endfor %}
+
+{% endblock %}
diff --git a/app/templates/home.html b/app/templates/home.html
index bcf38e0..83a745f 100644
--- a/app/templates/home.html
+++ b/app/templates/home.html
@@ -58,4 +58,4 @@
-{% endblock %}
\ No newline at end of file
+{% endblock %}
diff --git a/requirements.txt b/requirements.txt
index 022a5bd..88a7665 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,25 +3,23 @@
click==8.1.3
dnspython==2.4.2
email-validator==2.0.0.post2
-Flask==2.2.2
-flask-mongoengine==1.0.0
+Flask==2.3.3
Flask-WTF==1.1.1
idna==3.4
gunicorn==21.2.0
importlib-metadata==5.0.0
itsdangerous==2.1.2
Jinja2==3.1.2
-# FIXME remove lxml later
-# lxml==4.9.1
-MarkupSafe==2.1.1
+MarkupSafe==2.1.3
packaging==23.1
-mongoengine==0.27.0
-# FIXME remove pewee later
-# peewee==3.15.3
+#mongoengine==0.27.0
pymongo==4.5.0
#soupsieve==2.3.2.post1
#tqdm==4.64.1
typing==3.7.4.3
-Werkzeug==2.2.2
+Werkzeug==2.3.7
+Flask-WTF==1.1.1
WTForms==3.0.1
zipp==3.9.0
+pyyaml-6.0.1
+