Merge branch 'feature/DbReader' into develop

develop
gwen 2 years ago
commit 13e4d17a7c

2
.gitignore vendored

@ -1,2 +1,2 @@
.venv/* .venv/*
params.yaml

@ -3,13 +3,14 @@ import os
from flask import Flask from flask import Flask
from flask import render_template from flask import render_template
import werkzeug #import werkzeug
from .routes import main
APPPATH = os.path.dirname(os.path.abspath(__file__)) APPPATH = os.path.dirname(os.path.abspath(__file__))
templates = os.path.join(APPPATH, "templates") templates = os.path.join(APPPATH, "templates")
static = os.path.join(APPPATH, "static") static = os.path.join(APPPATH, "static")
app = Flask( app = Flask(
"Princely-Acts", "Princely-Acts",
template_folder=templates, template_folder=templates,
@ -19,17 +20,13 @@ app = Flask(
@app.errorhandler(404) @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 return render_template("404.html", title="Page non trouvée"), 404
@app.errorhandler(500) @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 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 "<p>Hello, World!</p>"

@ -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']
"""

@ -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/<username>")
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

@ -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/<house>") # 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/<house>/<prince>") # 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/<prince>/<acte_id>") # 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é")

@ -4,9 +4,9 @@
<h1>Corpus</h1> <h1>Corpus</h1>
<p>Corpus disponibles :</p> <p>Corpus disponibles :</p>
<ul> <ul>
<li><a href="{{url_for('main.actes', house='Bourbon')}}">Actes des ducs et duchesses de Bourbon</a></li> {% for house in houses %}
<li><a href="{{url_for('main.actes', house='Berry')}}">Actes des ducs et duchesses de Berry</a></li> <li><a href="{{url_for('main.actes', house=house.name)}}">Actes des ducs et duchesses {{ house.particle }}</a></li>
<li><a href="{{url_for('main.actes', house='Anjou')}}">Actes des ducs et duchesses d'Anjou</a></li>
</ul> {% endfor %}
</div><!-- /.container -->
{% endblock %} {% endblock %}

@ -3,25 +3,23 @@
click==8.1.3 click==8.1.3
dnspython==2.4.2 dnspython==2.4.2
email-validator==2.0.0.post2 email-validator==2.0.0.post2
Flask==2.2.2 Flask==2.3.3
flask-mongoengine==1.0.0
Flask-WTF==1.1.1 Flask-WTF==1.1.1
idna==3.4 idna==3.4
gunicorn==21.2.0 gunicorn==21.2.0
importlib-metadata==5.0.0 importlib-metadata==5.0.0
itsdangerous==2.1.2 itsdangerous==2.1.2
Jinja2==3.1.2 Jinja2==3.1.2
# FIXME remove lxml later MarkupSafe==2.1.3
# lxml==4.9.1
MarkupSafe==2.1.1
packaging==23.1 packaging==23.1
mongoengine==0.27.0 #mongoengine==0.27.0
# FIXME remove pewee later
# peewee==3.15.3
pymongo==4.5.0 pymongo==4.5.0
#soupsieve==2.3.2.post1 #soupsieve==2.3.2.post1
#tqdm==4.64.1 #tqdm==4.64.1
typing==3.7.4.3 typing==3.7.4.3
Werkzeug==2.2.2 Werkzeug==2.3.7
Flask-WTF==1.1.1
WTForms==3.0.1 WTForms==3.0.1
zipp==3.9.0 zipp==3.9.0
pyyaml-6.0.1

Loading…
Cancel
Save