colles.mp2i-vms.fr/colloscope/table.py

60 lines
1.7 KiB
Python

from colloscope.models import *
def table_colloscope(periode, heading=True, est_colle=True):
semaines = periode.range_semaines()
lundis = [ periode.classe.date_debut_sem(n) for n in semaines ]
creneaux = Creneau.objects.filter(periode=periode, est_colle=est_colle)
jours = ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"]
s = ""
s += "<table>\n"
if heading:
s += "<tr>\n"
for th in ("Matière", "Jour", "Heure", "Colleur", "Salle"):
s += f"<th rowspan=2>{th}</th>\n"
for sem in semaines:
s +=f"<th>{sem}</th>\n"
s += "</tr>\n<tr>\n"
for lundi in lundis:
s += f"<th>{lundi.strftime('%d/%m/%y')}</th>\n"
s += "</tr>\n"
for i, c in enumerate(creneaux):
matiere = c.matiere
jour = c.jour
heure = c.heure
colleur = c.colleur
salle = c.salle
s += "<tr>\n"
s += f"<td>{matiere.libelle}</td>\n"
s += f"<td>{jours[jour]}</td>\n"
s += f"<td>{heure.strftime('%H:%M')}</td>\n"
s += "<td>{} {}</td>\n".format("M." if colleur.civilite=="M" else "Mme", colleur.nom.upper())
s += f"<td>salle</td>\n"
for sem in semaines:
if Rotation.objects.filter(creneau=c, semaine=sem).exists():
r = Rotation.objects.get(creneau=c, semaine=sem)
groupes = r.groupes
content = ", ".join(g.libelle for g in groupes.all())
if r.est_modifiee():
s += f"<td class='modif'>{content}</td>\n"
else:
s += f"<td>{content}</td>\n"
else:
s += "<td></td>\n"
s += "</table>\n"
return s