From 2caf6cf49d900cf2560115fa43acafe1d66c7e3c Mon Sep 17 00:00:00 2001 From: gwen Date: Tue, 19 Sep 2023 17:06:51 +0200 Subject: [PATCH] route /actes/ ok --- README.md | 4 +--- app/routes.py | 32 +++++++++++++++++++++++--------- app/templates/corpus.html | 2 +- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 1cc2ffa..ebcea48 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,12 @@ _Nota_ : commands to execute through the terminal (Linux or macOS) - Go to the following directory : `cd webapp`; - Install the environment : `python3 -m venv .venv`. - Install the packages and libraries : - - Activate the environment : `source bootstrap.sh`; - Installation : `pip install -r requirements.txt` - Exit the environment : `deactivate`; ## Launch -- Activate the environment : `source bootstrap.sh`; -- Launch : `flask run`; +- Launch : `python index.py`; - Go to http://127.0.0.1:5000/; - Stop : `ctrl + c`; - Exit the environment : `deactivate`. diff --git a/app/routes.py b/app/routes.py index 538665a..bf2bb28 100644 --- a/app/routes.py +++ b/app/routes.py @@ -17,9 +17,11 @@ main = Blueprint("main", __name__, url_prefix="/") username = urllib.parse.quote_plus(dbadmin) password = urllib.parse.quote_plus(dbpassword) dbclient = MongoClient(f'mongodb://{username}:{password}@{server_ip}:27017') +# database actesdb = dbclient["actesdb"] -# +# collections housecol = actesdb["house"] +# the acte collection is the most important collection actecol = actesdb["acte"] helpers = actesdb["helpers"] #folium_map = actesdb["folium_map"] @@ -48,7 +50,7 @@ def bigram_prince(prince): def trigram_house(house): return house_trigram[house] -# TODO: write tests in the datascience project +# TODO: write tests in the datascience project `datascience/tests` #print(bigram_prince("Agnes")) #print(bigram_prince("Arthur")) #print(bigram_prince("Bernard")) @@ -87,13 +89,25 @@ def actes(house): """actes route shows the princes in the selected house + + :param: the house in the url is the house name + with a capital letter at the beginning + example: `house = "Berry"` """ - #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) + #for code in actecol.distinct('prince_code'): + # print(code) + # house in the store shall be in lower case, but let's force it, just in case + house = house.lower() + # [(prince_name, prince_code)] means for example: + # [("Charles Ier de Bourbon", "Ch_i"), ("Agnès de Bourgogne", "Agn_i")] + princes = [] + for act in actecol.find({"house":house}): + prince_name = act['prince_name'].capitalize() + prince_code = act['prince_code'].capitalize() + if (prince_name, prince_code) not in princes: + princes.append((prince_name, prince_code)) + + return render_template("corpus.html", house=house.capitalize(), princes=princes) @main.route("/actes//") # don't put a slash at the end @@ -135,7 +149,7 @@ def geoloc(): folium.Marker( location=[place['latitude'], place['longitude']], popup=place['name'], - #icon=folium.Icon(icon="cloud") + icon=folium.Icon(color='lightgray', icon="circle", prefix='fa') #icon=folium.Icon(color='lightgray', icon='home', prefix='fa') ).add_to(m) geolocalisation = m._repr_html_() diff --git a/app/templates/corpus.html b/app/templates/corpus.html index 0c2eca9..be811db 100644 --- a/app/templates/corpus.html +++ b/app/templates/corpus.html @@ -15,4 +15,4 @@ {% endfor %} -{% endblock %} \ No newline at end of file +{% endblock %}