Updated gitignore
This commit is contained in:
parent
a702385c21
commit
b507199c2a
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@ __pycache__/
|
||||
cache/
|
||||
push_to_server.sh
|
||||
log.json
|
||||
venv
|
||||
venv/*
|
||||
|
@ -73,6 +73,6 @@ UniSquat est créé par deux étudiants de l'université de Strasbourg. Rendez-v
|
||||
|
||||
Notre travail est fait de façon bénévole, mais si vous souhaitez nous soutenir, n'hésitez pas à passer sur le campus de l'Esplanade pour nous offrir un chocolat chaud ❤
|
||||
|
||||
Vous pouvez nous contacter sur nos comptes Git respectifs. Vous pouvez aussi contacter @ayte [sur son blog](https://webair.xyz/fr/contact).
|
||||
Vous pouvez nous contacter sur nos comptes Git respectifs. Vous pouvez aussi contacter @ayte [sur son blog](https://webair.xyz/contact.html).
|
||||
|
||||
[homepage]: https://unisquat.alwaysdata.net
|
||||
|
107
app.py
107
app.py
@ -43,16 +43,27 @@ GLOBAL_CONTEXT["DEBUG"] = False # Fait en sorte que le logiciel soit un peu plus
|
||||
GLOBAL_CONTEXT["DOMAIN"] = "https://unisquat.alwaysdata.net" # Le domaine sur lequel est host l'instance
|
||||
|
||||
# Globales
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
logs = [] # Stoque les différentes requêtes faite sur la route /free_rooms/, sous la forme {"timestamp":timestamp,"depts":[]}
|
||||
logs = [] # Stocke les différentes requêtes faite sur la route /free_rooms/, sous la forme {"timestamp":timestamp,"depts":[]}
|
||||
if os.path.isfile(LOG_FILE):
|
||||
with open(LOG_FILE,"r") as f:
|
||||
logs = json.loads(f.read())
|
||||
|
||||
# Fonctions :
|
||||
def save_logs(logs):
|
||||
"""
|
||||
Sauvegarde les logs dans un fichier.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
logs : list
|
||||
Liste des logs.
|
||||
|
||||
Returns
|
||||
-------
|
||||
None.
|
||||
|
||||
"""
|
||||
with open(LOG_FILE,"w") as f:
|
||||
f.write(json.dumps(logs))
|
||||
|
||||
@ -71,7 +82,6 @@ def home() :
|
||||
"""
|
||||
return render_template("index.html", **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/app")
|
||||
def select_dept() :
|
||||
"""
|
||||
@ -95,7 +105,6 @@ def select_dept() :
|
||||
url_for("static", filename="style.css")
|
||||
return render_template("dept-select.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/stats")
|
||||
def stats():
|
||||
"""
|
||||
@ -140,34 +149,40 @@ def stats():
|
||||
context = {"MAX_LOG_DAYS":MAX_LOG_DAYS,"PING_WARN":PING_WARN,"depts":sort[:MAX_LOG_DEPT],"favs":sort_favs[:MAX_LOG_FAVS],"nbping":pings}
|
||||
return render_template("stats.html",**context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
@app.route("/app/free-rooms", methods=["POST", "GET"])
|
||||
def free_rooms() :
|
||||
def free_rooms(api = False, rq = None) :
|
||||
"""
|
||||
Affiche les salles libres dans les départements sélectionnés
|
||||
dans la page des départements.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
None
|
||||
api : bool
|
||||
Indique si la page est accédée par l'API.
|
||||
|
||||
rq : requests.request
|
||||
Requête.
|
||||
|
||||
Returns
|
||||
-------
|
||||
flask.render_template
|
||||
"""
|
||||
if not api :
|
||||
rq = request
|
||||
|
||||
if GLOBAL_CONTEXT["DEBUG"]:
|
||||
print(f"dept:\n\t{request.args.getlist('dept')}")
|
||||
print(f"favs:\n\t{request.args.getlist('favs')}")
|
||||
print(f"date:\n\t{request.args.get('date')}\t{request.args.get('time')}")
|
||||
print(f"dept:\n\t{rq.args.getlist('dept')}")
|
||||
print(f"favs:\n\t{rq.args.getlist('favs')}")
|
||||
print(f"date:\n\t{rq.args.get('date')}\t{rq.args.get('time')}")
|
||||
# Récupération des ID des départements depuis le formulaire :
|
||||
dident_list = list(request.args.getlist("dept"))
|
||||
dident_list = list(rq.args.getlist("dept"))
|
||||
if len(dident_list) > MAX_DEPT :
|
||||
return render_template("error.html", error="Trop de départements sélectionnés ! Vous pouvez en sélectionner "+str(MAX_DEPT)+" au maximum.")
|
||||
if len(dident_list) == 0 :
|
||||
return render_template("error.html", error="Il faut choisir au moins un département !")
|
||||
|
||||
# Récupération de l'éventuelle date personnalisée (depuis la page de sélection de date) :
|
||||
date_uf = str(request.args.get("date"))
|
||||
date_uf = str(rq.args.get("date"))
|
||||
date_uf_sav = date_uf
|
||||
if date_uf == "None" :
|
||||
date_uf = [""]
|
||||
@ -177,7 +192,7 @@ def free_rooms() :
|
||||
if date_uf != [""] and not (date_tools.check_date(date_uf)) :
|
||||
return render_template("error.html", error="Date incorrecte !")
|
||||
|
||||
time_uf = str(request.args.get("time"))
|
||||
time_uf = str(rq.args.get("time"))
|
||||
time_uf_sav = time_uf
|
||||
if time_uf == "None" :
|
||||
time_uf = [""]
|
||||
@ -202,7 +217,7 @@ def free_rooms() :
|
||||
|
||||
|
||||
# Récupération des IDs des salles favorites :
|
||||
favs_ids = list(request.args.getlist("favs"))
|
||||
favs_ids = list(rq.args.getlist("favs"))
|
||||
if favs_ids == [None] :
|
||||
favs_ids = []
|
||||
|
||||
@ -330,10 +345,28 @@ def free_rooms() :
|
||||
|
||||
# Sauvegarde les logs dans un fichier cache
|
||||
save_logs(logs)
|
||||
|
||||
url_for("static", filename="style.css")
|
||||
return render_template("free-rooms.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
|
||||
if api :
|
||||
serial_context = context
|
||||
for i in range(len(serial_context["free_rooms"])) :
|
||||
fr_start = serial_context["free_rooms"][i].start
|
||||
serial_context["free_rooms"][i].start = [fr_start.year, fr_start.month, fr_start.day, fr_start.hour, fr_start.minute, fr_start.second]
|
||||
fr_end = serial_context["free_rooms"][i].end
|
||||
serial_context["free_rooms"][i].end = [fr_end.year, fr_end.month, fr_end.day, fr_end.hour, fr_end.minute, fr_end.second]
|
||||
serial_context["free_rooms"][i] = vars(serial_context["free_rooms"][i])
|
||||
for i in range(len(serial_context["soon_rooms"])) :
|
||||
fr_start = serial_context["soon_rooms"][i].start
|
||||
serial_context["soon_rooms"][i].start = [fr_start.year, fr_start.month, fr_start.day, fr_start.hour, fr_start.minute, fr_start.second]
|
||||
fr_end = serial_context["soon_rooms"][i].end
|
||||
serial_context["soon_rooms"][i].end = [fr_end.year, fr_end.month, fr_end.day, fr_end.hour, fr_end.minute, fr_end.second]
|
||||
serial_context["soon_rooms"][i] = vars(serial_context["soon_rooms"][i])
|
||||
print(serial_context)
|
||||
response = make_response(json.dumps(context))
|
||||
response.headers["Content-Type"] = "application/json"
|
||||
return response
|
||||
else :
|
||||
url_for("static", filename="style.css")
|
||||
return render_template("free-rooms.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
@app.route("/app/date-select", methods=["POST", "GET"])
|
||||
def date_select() :
|
||||
@ -360,14 +393,44 @@ def date_select() :
|
||||
|
||||
return render_template("date-select.html", **context, **GLOBAL_CONTEXT)
|
||||
|
||||
@app.route("/api/depts_list")
|
||||
def api_depts_get() :
|
||||
"""
|
||||
Renvoie la liste des départements (pour l'API).
|
||||
|
||||
Returns
|
||||
-------
|
||||
None.
|
||||
|
||||
"""
|
||||
# Récupération de la liste des départements existants :
|
||||
dept_filen = "data/dept_list.txt"
|
||||
dept_list = ro.get_depts(dept_filen)
|
||||
serial_dlist = [vars(d) for d in dept_list]
|
||||
|
||||
response = make_response(json.dumps(serial_dlist))
|
||||
response.headers["Content-Type"] = "application/json"
|
||||
return response
|
||||
|
||||
@app.route("/api/free_rooms")
|
||||
def api_frooms() :
|
||||
"""
|
||||
Redirige vers le JSON des salles (pour l'API).
|
||||
|
||||
Returns
|
||||
-------
|
||||
None.
|
||||
|
||||
"""
|
||||
return free_rooms(True, request)
|
||||
|
||||
@app.route("/sitemap.xml")
|
||||
def sitemap():
|
||||
sitemap_xml = render_template("sitemap.xml", **GLOBAL_CONTEXT)
|
||||
response= make_response(sitemap_xml)
|
||||
response.headers["Content-Type"] = "application/xml"
|
||||
response = make_response(sitemap_xml)
|
||||
response.headers["Content-Type"] = "application/xml"
|
||||
return response
|
||||
|
||||
|
||||
@app.errorhandler(404)
|
||||
def error(e):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user