Affichage des salles lambda quand des favoris sont sélectionnés

This commit is contained in:
theo@manjaro 2022-06-15 23:34:38 +02:00
parent 17130f7c04
commit 104feb31b9
2 changed files with 59 additions and 28 deletions

19
app.py
View File

@ -195,13 +195,6 @@ def free_rooms() :
ignore_list = ["salle non définie", "salle en Distanciel"]
free_rooms = ro.getrooms(date, depts, ignore_list)
# Filtre selon les favoris ( s'il y en a )
if len(favs_ids)>0:
final_rooms = list()
for r in free_rooms:
if r.id in favs_ids:
final_rooms.append(r)
free_rooms = final_rooms
frooms_disp = dict() # Mise en forme des infos pour la page Web
@ -231,7 +224,17 @@ def free_rooms() :
for dept in dident_list:
nofavslink+="dept="+str(dept)+"&"
nofavslink = nofavslink[:-1] # Enlever le dernier &
context = {"free_rooms":free_rooms, "frooms_disp":frooms_disp, "depts_str":depts_str, "dident_list":dident_list, "date_str":date_str, "change_date_str":change_date_str, "favs":len(favs_ids)>0,"nofavslink":nofavslink}
# Trier les salles selon leurs catégories
favs_free_rooms = []
favs_soon_rooms = []
soon_rooms = []
final_rooms = []
for r in free_rooms:
[[soon_rooms,final_rooms],[favs_soon_rooms,favs_free_rooms]][r.id in favs_ids][r.is_free].append(r)
context = {"favs_free_rooms":favs_free_rooms, "favs_soon_rooms":favs_soon_rooms, "free_rooms":final_rooms, "soon_rooms":soon_rooms, "frooms_disp":frooms_disp, "depts_str":depts_str, "dident_list":dident_list, "date_str":date_str, "change_date_str":change_date_str, "favs":len(favs_ids)>0,"nofavslink":nofavslink}
# Crée un log de la date et des départements demandés ( pour des futures statistiques )
log = {}

View File

@ -9,14 +9,6 @@
<body>
{% include "base.html" %}
<main>
{% if favs: %}
<div class="flex">
<p>Attention, tu as des favoris de précisé, les résultats sont donc filtrés et tu ne vois pas toute les salles !</p>
</div>
<div class="flex">
<a class="button" href="{{ nofavslink }}">Retirer</a>
</div>
{% endif %}
<div class="flex">
<p>
Départements sélectionnés : <br>
@ -32,45 +24,81 @@
<a class="button" href='/app/date-select{{change_date_str}}'>Choisir une date</a>
</div>
<form action="/app/free-rooms" method="get">
<h1>Disponibles maintenant</h1>
{% if favs: %}
<div class="flex">
<a class="button" href="{{ nofavslink }}">Retirer les favoris</a>
</div>
{% if favs_free_rooms|length>0: %}
<br>
<h1>Favoris disponibles maintenant</h1>
<div class="flex-container">
<ul>
{% for room in free_rooms : %}
{% if room.is_free : %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}{%if not favs:%}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}"> <label for="{{ room.id }}"></label>{% endif %}
{% for room in favs_free_rooms : %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}" checked> <label for="{{ room.id }}"></label>
{% if not(room.end.hour == 23 and room.end.minute == 59 and room.end.second == 59) : %}
<br><span class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% endif %}
</dt>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
{% if favs_soon_rooms|length>0: %}
<br>
<h1>Disponibles prochainement</h1>
<h1>Favoris disponibles prochainement</h1>
<div class="flex-container">
<ul>
{% for room in free_rooms : %}
{% if not room.is_free : %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}{%if not favs:%}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}"> <label for="{{ room.id }}"></label>{% endif %}
{% for room in favs_soon_rooms: %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}" checked> <label for="{{ room.id }}"></label>
{% if room.end.hour == 23 and room.end.minute == 59 and room.end.second == 59 : %}
<br><span class=details>À {{ frooms_disp[room.name]["start"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% else %}
<br><span class=details>De {{ frooms_disp[room.name]["start"] }} à {{ frooms_disp[room.name]["end"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% endif %}
</dt>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
{% endif %}
{% if free_rooms|length>0 %}
<br>
<h1>Disponibles maintenant</h1>
<div class="flex-container">
<ul>
{% for room in free_rooms: %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}"> <label for="{{ room.id }}"></label>
{% if not(room.end.hour == 23 and room.end.minute == 59 and room.end.second == 59) : %}
<br><span class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% endif %}
</dt>
{% endfor %}
</ul>
</div>
{% endif %}
{% if soon_rooms|length>0 %}
<br>
<h1>Disponibles prochainement</h1>
<div class="flex-container">
<ul>
{% for room in soon_rooms: %}
<dt>{{ room.name }} {% if DEBUG :%}( {{ room.id }} ){% endif %}<input class="fav" type="checkbox" id="{{ room.id }}" name="favs" value="{{ room.id }}"> <label for="{{ room.id }}"></label>
{% if room.end.hour == 23 and room.end.minute == 59 and room.end.second == 59 : %}
<br><span class=details>À {{ frooms_disp[room.name]["start"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% else %}
<br><span class=details>De {{ frooms_disp[room.name]["start"] }} à {{ frooms_disp[room.name]["end"] }} (dans {{ frooms_disp[room.name]["rtime"] }})</span>
{% endif %}
</dt>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="flex">
{% for d in dident_list : %} <!-- Magie noire pour conserver les départements séléctionnés -->
<span style="display: none;"><input type="text" name="dept" value="{{ d }}"/></span>
{% endfor %}
{% if not favs:%}
<input type="submit" value="Valider les favoris">
{% endif %}
</div>
</form>
</main>