diff --git a/README.md b/README.md index 579e79a..008c890 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ $ poetry run python test_axione_api.py Travailler depuis la VM whitelistée par Axione est peu pratique. C'est pourquoi nous avons ajouté un mode debug permettant de simuler les réponses d'Axione. -Pour l'activer, il vous faudra mettre la variable d'environnement `DEBUG` a `true`. Vous pouvez également utiliser un fichier de configuration ne se trouvant pas a `/etc/axione-elig-test.ini` à l'aide de la variable d'environnement `CONFIG`. - -Par example: +Pour lancer la webapp localement en mode debug, vous pouvez utiliser le script `run-dev-server`: ```bash -$ DEBUG=true CONFIG=./elig-test.ini poetry run python elig-test.py +./run-dev-server ``` diff --git a/run-dev-server b/run-dev-server new file mode 100755 index 0000000..73af97d --- /dev/null +++ b/run-dev-server @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +DEBUG=true CONFIG=./elig-test.ini.sample FLASK_APP=webapp poetry run flask run --reload diff --git a/templates/landing_form.html b/templates/landing_form.html new file mode 100644 index 0000000..cf61cbf --- /dev/null +++ b/templates/landing_form.html @@ -0,0 +1,25 @@ + + + + + + + Aquilenet: Éligibilité FTTH + + + + +

Aquilenet

+
+

Test d'Éligibilité FTTH Aquilenet

+
+ + +
+
+ + diff --git a/templates/result.html b/templates/result.html new file mode 100644 index 0000000..5db72a8 --- /dev/null +++ b/templates/result.html @@ -0,0 +1,62 @@ + + + + + + + Aquilenet: Éligibilité FTTH + + + + +

Aquilenet

+
+

Test d'Éligibilité FTTH Aquilenet: Résultats

+

Résultat pour le PTO: {{ pto }}

+ {% for batiment in result %} + + + + + + + {% for etage in batiment["etages"] %} + + + + + {% endfor %} +
{{ batiment["referenceBatiment"] }}
{{ etage["reference"] }} + + + + + + + +
Nb Lignes Actives{{ etage["nbLignesActives"] }}
Nb Lignes Existantes{{ etage["nbLignesExistantes"] }}
Nb Locaux FTTH{{ etage["nbLocauxFtth"] }}
+ + + + + + {% for ligne in etage["lignes"] %} + + + + + + + + + + {% endfor %} +
Lignes
PTOPBOactifcommercialisableexistantraccordablerompu
{{ ligne["pto"] }}{{ ligne["pbo"] }}{{ ligne["actif"] }}{{ ligne["commercialisable"] }}{{ ligne["existant"] }}{{ ligne["raccordable"] }}{{ ligne["rompu"] }}
+
+
+ {% endfor %} +
+ + diff --git a/templates/style.css b/templates/style.css new file mode 100644 index 0000000..ef5c813 --- /dev/null +++ b/templates/style.css @@ -0,0 +1,46 @@ +body { + background-color: #1787c2; + display: flex; + flex-direction: column; + font-family: 'Titillium Web', sans-serif; +} +#aquilenet-title { + color: white; + align-self: center; + font-size: 4em; + margin-top: .3em; + margin-bottom: .5em; +} +#container { + width: 80%; + background-color: #ffd38c; + align-self: center; + padding: 2em; + display: flex; + flex-direction: column; + padding-bottom: 10em; +} + +form { + align-self: center; +} + +#main-title { + align-self: center; + margin-bottom: 2em; +} + +table,td { + border: 2px solid #333; + border-collapse: collapse; +} + +thead, tfoot { + background-color: #333; + color: #fff; +} + +td { + padding-left: 1em; + padding-right: 1em; +} diff --git a/webapp.py b/webapp.py new file mode 100644 index 0000000..d0da2b6 --- /dev/null +++ b/webapp.py @@ -0,0 +1,32 @@ +import os +from flask import Flask, render_template, request, escape + +from axione_api.config import parse_config +from axione_api.api import query_axione_pto, parse_response + +def load_config(): + cfg_path = os.environ.get("CONFIG", "/etc/axione-elig-test.ini") + print(f'Reading the "{cfg_path}" config file') + cfg = parse_config(cfg_path) + cfg.debug = True if "DEBUG" in os.environ else False + if cfg.debug: + print("===================") + print("DEBUG_MODE") + print("No requests will be performed") + print("We'll inject some dummy data instead") + print("===================") + print("") + return cfg + +cfg = load_config() +app = Flask(__name__) + +@app.route("/", methods=['GET']) +def get_form(): + return render_template("landing_form.html") + +@app.route("/result", methods=['POST']) +def show_result(): + pto = escape(request.form['pto']) + result = parse_response(query_axione_pto(cfg, pto)) + return render_template("result.html", pto=pto, result=result)