Compare commits

..

2 Commits

Author SHA1 Message Date
theo@manjaro ee35260d97 Fix du délai d'un mois 2024-03-31 21:43:55 +02:00
theo@manjaro dda111f4cf Ajout d'info git au contexte global 2024-03-22 16:59:00 +01:00
5 changed files with 65 additions and 43 deletions

15
app.py
View File

@ -16,6 +16,7 @@ import pytz
import json
import os
import traceback
import git
from flask import Flask
from flask import render_template
@ -68,6 +69,12 @@ GLOBAL_CONTEXT["DOMAIN"] = "https://unisquat.alwaysdata.net"
# Timezone du serveur :
TIMEZONE = pytz.timezone("Europe/Paris")
# Branche actuelle git
GLOBAL_CONTEXT["GIT_BRANCH"] = git.get_active_branch_name()
# Hash du commit actuel git
GLOBAL_CONTEXT["GIT_COMMIT"] = git.get_git_revision()
# Globales :
app = Flask(__name__)
@ -76,11 +83,7 @@ app = Flask(__name__)
logs = []
if os.path.isfile(LOG_FILE):
with open(LOG_FILE,"r") as f:
try:
logs = json.loads(f.read())
# On supprime le fichier s'il est invalide :
except json.decoder.JSONDecodeError:
os.remove(LOG_FILE)
logs = json.loads(f.read())
# Fonctions :
def save_logs(logs):
@ -304,7 +307,7 @@ def free_rooms(api = False, rq = None) :
if GLOBAL_CONTEXT["DEBUG"] :
print(errdetails)
return render_template("error.html",
error="Désolé, une erreur est survenue. UniSquat ne peut pas continuer.")
error="Le serveur Unistra a rencontré une erreur ! Veuillez réessayer plus tard.")
# Création d'un dictionnaire avec les infos des salles :
frooms_disp = dict() # Mise en forme des infos pour la page Web

22
git.py Normal file
View File

@ -0,0 +1,22 @@
from pathlib import Path
def get_active_branch_name(base_path="."):
head_dir = Path(base_path) / ".git" / "HEAD"
with head_dir.open("r") as f:
content = f.read().splitlines()
for line in content:
if line[0:4] == "ref:":
return line.partition("refs/heads/")[2]
def get_git_revision(base_path=".", short = True):
git_dir = Path(base_path) / '.git'
with (git_dir / 'HEAD').open('r') as head:
ref = head.readline().split(' ')[-1].strip()
with (git_dir / ref).open('r') as git_hash:
hash = git_hash.readline().strip()
if short:
return hash[:7]
else:
return hash

View File

@ -22,6 +22,7 @@ import pytz
import os
import shutil
import time
import datetime
# Fichiers locaux :
from objects import Room
@ -245,18 +246,12 @@ def get_tot_rooms(datet, depts, ignore_list) :
margintime = 1
# Récupération du calendrier de chaque département,
# sur une période de 'margintime' mois.
# On choisit comme jour le 28, car tous les mois ont au moins 28 jours.
# sur une période de 'margintime' mois :
cals = list() # Liste des EDT des départements choisis
for d in depts :
if datet.month < 12 :
result = sched_get(datet, d.link,
datet.replace(day = 28, month = datet.month + margintime),
NO_CACHE)
else :
result = sched_get(datet, d.link,
datet.replace(day = 28, month = 1, year = datet.year + 1),
NO_CACHE)
result = sched_get(datet, d.link,
datet + datetime.timedelta(margintime),
NO_CACHE)
# # Utilisation du module 'ics' pour le tri du calendrier dans l'ordre
# # chronologique :
# cal = ics.Calendar(result)
@ -417,4 +412,4 @@ def getrooms(datet, depts, ignore_list) :
dept_index += 1
return total_rooms
return total_rooms

View File

@ -9,30 +9,29 @@ body {
background: var(--bg);
color: var(--fg);
font-family: "ubuntu", sans-serif;
margin: 0px;
}
h1, h2 {
text-align: center;
font-size: 5vh;
font-size: 6vh;
}
h2 {
font-size: 4vh;
font-size: 5vh;
font-weight: normal;
/* margin-bottom: 8vh; */
margin-bottom: 8vh;
}
/* .slider {
overflow: hidden;
} */
.slider { overflow: hidden;
}
.slide-track {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
gap: 2vw;
/* animation: scroll 40s linear infinite; */
/* width: 3000vh; Pas bô, mais on va faire avec en attendant... */
gap: 3vw;
animation: scroll 40s linear infinite;
width: 3000vh; /* Pas bô, mais on va faire avec en attendant... */
}
.room {
@ -43,26 +42,26 @@ h2 {
border-color: var(--bg-dark);
border-radius: 3vw;
padding: 1vw;
height: 10vh;
height: 17vh;
color: var(--bg);
font-size: 5vh;
font-size: 8vh;
display: flex;
flex-direction: column;
justify-content: center;
}
/* @keyframes scroll {
@keyframes scroll {
0% { transform: translateX(0); }
100% { transform: translateX(calc(-25vw * 7)); }
} */
}
.details {
margin: 1vh;
font-size: 4vh;
font-size: 6vh;
}
footer {
margin-top: 5vh;
margin-top: 8vh;
font-size: 3vh;
text-align: center;
}

View File

@ -13,16 +13,19 @@
<div class="slide-track">
{% if favs: %}
<!-- Afficher les favoris -->
{% if favs_free_rooms|length > 0 : %}
{% for room in favs_free_rooms : %}
<div class="room">
<b>{{ room.name }}</b> {% if DEBUG :%}( {{ room.id }} ){% endif %}
{% if not(room.noend) : %}
<p class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }}</p>
{% endif %}
</div>
{% endfor %}
{% endif %}
<!-- Deux fois pour que l'animation boucle -->
{% for i in range(2) : %}
{% if favs_free_rooms|length > 0 : %}
{% for room in favs_free_rooms : %}
<div class="room">
<b>{{ room.name }}</b> {% if DEBUG :%}( {{ room.id }} ){% endif %}
{% if not(room.noend) : %}
<p class=details>Jusqu'à {{ frooms_disp[room.name]["end"] }}</p>
{% endif %}
</div>
{% endfor %}
{% endif %}
{% endfor %}
{% else %}
<!-- Si les favoris ne sont pas définis, afficher les salles classiques -->
{% for i in range(2):%}