|
|
import typing as t
|
|
|
import urllib.parse
|
|
|
from unidecode import unidecode # to remove accents in house and prince names in the urls
|
|
|
|
|
|
from flask import Blueprint, abort, render_template, request, send_from_directory
|
|
|
from pymongo import MongoClient
|
|
|
import folium
|
|
|
|
|
|
from .config import dbadmin, dbpassword, server_ip
|
|
|
from .helper import find_one_or_404
|
|
|
|
|
|
|
|
|
main = Blueprint("main", __name__, url_prefix="/")
|
|
|
|
|
|
# FIXME : put the mongodb connector in the flask app object
|
|
|
# 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"]
|
|
|
actecol = actesdb["acte"]
|
|
|
helpers = actesdb["helpers"]
|
|
|
#folium_map = actesdb["folium_map"]
|
|
|
#
|
|
|
|
|
|
helpers_dicts = helpers.find_one()
|
|
|
house_trigram = helpers_dicts["house_trigram"]
|
|
|
prince_bigram = helpers_dicts["prince_bigram"]
|
|
|
|
|
|
def normalize_trigrams(trigram):
|
|
|
"""noramlizes names like Alençon -> Alencon
|
|
|
|
|
|
or Orléans -> Orleans for the url routes to be clean
|
|
|
"""
|
|
|
return {unidecode(value):key for key, value in trigram.items()}
|
|
|
|
|
|
# normalized_trigrams
|
|
|
house_trigram = normalize_trigrams(house_trigram)
|
|
|
prince_bigram = normalize_trigrams(prince_bigram)
|
|
|
|
|
|
def bigram_prince(prince):
|
|
|
"Translates Charles_i -> ch_i"
|
|
|
name, number = prince.split("_")
|
|
|
return prince_bigram[name] + "_" + number
|
|
|
|
|
|
def trigram_house(house):
|
|
|
return house_trigram[house]
|
|
|
|
|
|
# TODO: write tests in the datascience project
|
|
|
#print(bigram_prince("Agnes"))
|
|
|
#print(bigram_prince("Arthur"))
|
|
|
#print(bigram_prince("Bernard"))
|
|
|
#print(trigram_house("Anjou"))
|
|
|
#print(trigram_house("Orleans"))
|
|
|
|
|
|
def make_acteid_from_route(house=None, prince=None, date_and_item=None):
|
|
|
"/acte/Anjou/Isabelle_i/1441_08_05a -> anj_isa_i_1441_08_05a"
|
|
|
return "_".join([trigram_house(house), bigram_prince(prince), date_and_item])
|
|
|
|
|
|
@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
|
|
|
|
|
|
shows the princes in the selected house
|
|
|
"""
|
|
|
#house = "Berry"
|
|
|
# FIXME faire des princes correspondant à la maison (house) sélectionnée
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
@main.route("/actes/<house>/<prince>") # don't put a slash at the end
|
|
|
def prince_corpus(house=None, prince=None):
|
|
|
"""copora prince, **timeline view**"""
|
|
|
# FIXME
|
|
|
return "FIXME" # make_acteid_from_route(house, prince)
|
|
|
|
|
|
|
|
|
@main.route("/acte/<house>/<prince>/<dateitem>") # don't put a slash at the end
|
|
|
def acte(house=None, prince=None, dateitem=None):
|
|
|
"""specific prince's acte view
|
|
|
|
|
|
:params: - house
|
|
|
- prince
|
|
|
- date + item (sample: 1441_08_05a)
|
|
|
:url location sample: /acte/Anjou/Isabelle_i/1441_08_05a
|
|
|
|
|
|
url transcription samples:
|
|
|
/acte/Anjou/Isabelle_i/1441_08_05a -> anj_isa_i_1441_08_05a
|
|
|
/acte/Bourbon/Anne_i/1388_09_15a -> brb_ann_i_1388_09_15a
|
|
|
"""
|
|
|
filestem = make_acteid_from_route(house, prince, dateitem)
|
|
|
result = actecol.find_one({'_id': filestem})
|
|
|
return render_template("acte.html", house=house, prince=prince,
|
|
|
#infos=None, place=None, doc=None, arch=None,
|
|
|
#diplo=diplo_t[0].replace("_", " "), state=state[0],
|
|
|
output_doc=result.get('xmlcontent'), name_prince=result.get("prince_name"),
|
|
|
folium=result.get("folium"),
|
|
|
transcribers=result.get('transcribers'))
|
|
|
|
|
|
@main.route("/geoloc")
|
|
|
def geoloc():
|
|
|
"global folium/leaflet map"
|
|
|
m = folium.Map(location=[46.603354, 1.888334], zoom_start=6)
|
|
|
for result in actecol.find():
|
|
|
place = result['place']
|
|
|
if place.get('latitude') is not None:
|
|
|
folium.Marker(
|
|
|
location=[place['latitude'], place['longitude']],
|
|
|
popup=place['name'],
|
|
|
#icon=folium.Icon(icon="cloud")
|
|
|
#icon=folium.Icon(color='lightgray', icon='home', prefix='fa')
|
|
|
).add_to(m)
|
|
|
geolocalisation = m._repr_html_()
|
|
|
return render_template("map.html", geolocalisation=geolocalisation)
|
|
|
#geolocalisation = folium_map.find_one()
|
|
|
#geolocalisation = geolocalisation['globalmap']
|
|
|
#return render_template("map.html", geolocalisation=geolocalisation)
|
|
|
|
|
|
@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é")
|