Ajout d'un contexte global pour les templates
This commit is contained in:
parent
ada9dcd7a3
commit
8e187ff5fd
16
app.py
16
app.py
@ -29,6 +29,10 @@ MAX_DEPT = 5 # Le maximum de départements qu'il est possible de sélectionner
|
||||
MAX_LOG_DAYS = 30 # Le nombre de jours pendant lesquels les logs sont conservés
|
||||
MAX_LOG_DEPT = 3 # Le nombre maximum affiché de départements qui ont été le plus cherché
|
||||
PING_WARN = 5 # Nombre d'utilisations à partir du quel un message d'avertissement est affiché
|
||||
GLOBAL_CONTEXT = {} # Contexte constant pour les templates Jinja
|
||||
GLOBAL_CONTEXT["SOURCE"] = "https://forge.chapril.org/Wantoo/UniSquat_Python" # Le lien du code source
|
||||
GLOBAL_CONTEXT["CREDITSLINK"] = "https://forge.chapril.org/Wantoo" # Le lien de l'organisation
|
||||
GLOBAL_CONTEXT["CREDITSNAME"] = "Wantoo" # Le nom de l'organisation
|
||||
|
||||
# Globales
|
||||
logs = [] # Stoque les différentes requêtes faite sur la route /free_rooms/, sous la forme {"timestamp":timestamp,"depts":[]}
|
||||
@ -50,7 +54,7 @@ def home() :
|
||||
flask.render_template
|
||||
"""
|
||||
|
||||
return render_template("index.html")
|
||||
return render_template("index.html", **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/app")
|
||||
@ -75,7 +79,7 @@ def select_dept() :
|
||||
content = {"dept_list":dept_list}
|
||||
|
||||
url_for("static", filename="style.css")
|
||||
return render_template("dept-select.html", **content)
|
||||
return render_template("dept-select.html", **content, **GLOBAL_CONTEXT)
|
||||
|
||||
@app.route("/stats")
|
||||
def stats():
|
||||
@ -106,7 +110,7 @@ def stats():
|
||||
sort.sort(key = lambda x: x[1],reverse = True ) # Trie selon la valeur du deuxieme élément de la liste
|
||||
|
||||
context = {"MAX_LOG_DAYS":MAX_LOG_DAYS,"PING_WARN":PING_WARN,"depts":sort[:MAX_LOG_DEPT],"nbping":pings}
|
||||
return render_template("stats.html",**context)
|
||||
return render_template("stats.html",**context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/app/free-rooms", methods=["POST", "GET"])
|
||||
@ -210,7 +214,7 @@ def free_rooms() :
|
||||
del(logs[0])
|
||||
|
||||
url_for("static", filename="style.css")
|
||||
return render_template("free-rooms.html", **context)
|
||||
return render_template("free-rooms.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/app/date-select", methods=["POST", "GET"])
|
||||
@ -231,7 +235,7 @@ def date_select() :
|
||||
|
||||
context = {"dident_list":dident_list}
|
||||
|
||||
return render_template("date-select.html", **context)
|
||||
return render_template("date-select.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
@ -247,4 +251,4 @@ def error(e):
|
||||
-------
|
||||
flask.render_template
|
||||
"""
|
||||
return render_template("error.html", error="Page non trouvée !")
|
||||
return render_template("error.html", error="Page non trouvée !", **GLOBAL_CONTEXT)
|
||||
|
@ -6,7 +6,7 @@
|
||||
<div class="flex">
|
||||
<a href="/app">Start</a>
|
||||
<a href="/stats">Stats</a>
|
||||
<a href="https://forge.chapril.org/Wantoo/UniSquat_Python">Source</a>
|
||||
<a href="{{SOURCE}}">Source</a>
|
||||
</div>
|
||||
</strong>
|
||||
</header>
|
||||
|
@ -3,6 +3,6 @@
|
||||
<p>Version en cours de développement</p>
|
||||
</div>
|
||||
<div class="flex">
|
||||
<p>Fait avec ❤ par <a href="https://forge.chapril.org/Wantoo">Wantoo</a></p>
|
||||
<p>Fait avec ❤ par <a href="{{CREDITSLINK}}">{{CREDITSNAME}}</a></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
Loading…
Reference in New Issue
Block a user