Merge remote-tracking branch 'refs/remotes/origin/dev'

# Conflicts:
#	colloscope/icalexport.py
This commit is contained in:
Valentin Moguérou 2024-04-20 14:40:17 +02:00
commit 8bd4cfa756
1 changed files with 21 additions and 12 deletions

View File

@ -9,20 +9,30 @@ from colloscope.models import *
LOCAL_TZ = "Europe/Paris"
def to_calendar(etudiant, periode):
def emailize(nom, prenom=None):
if prenom is not None:
return "{}.{}@example.com" \
.format(
prenom.replace(" ", "_").lower(),
nom.replace(" ", "_").lower()
)
else:
return "{}@example.com" \
.format(nom.replace(" ", "_").lower())
def to_calendar(etudiant, periode):
p = path.abspath('./static/Base_Calendar.ics')
with open(p) as f:
cal = Calendar.from_ical(f.read())
rotations = Rotation.objects \
.filter(groupes__membres=etudiant) \
.select_related("creneau__periode__classe__lycee") \
.select_related("creneau__matiere") \
.select_related("creneau__colleur") \
\
for rotation in rotations:
event = Event()
@ -37,22 +47,21 @@ def to_calendar(etudiant, periode):
event.add("dtstamp", datetime.now())
event.add("uid", str(uuid4()))
event.add("location", f"{rotation.creneau.salle} ({rotation.creneau.periode.classe.lycee})")
event.add("categories", "COLLE-" + str(rotation.creneau.matiere))
description = f"Groupes: {','.join(str(groupe) for groupe in rotation.groupes.all())}"
event.add("description", description)
organizer = vCalAddress("mailto:unknown@mp2i-vms.fr")
organizer = vCalAddress(f"mailto:{emailize(rotation.creneau.colleur.nom)}")
organizer.params["cn"] = vText(str(rotation.creneau.colleur))
organizer.params["role"] = vText("Colleur")
event.add("organizer", organizer)
for e in rotation.groupe_effectif():
attendee = vCalAddress("mailto:unknown@mp2i-vms.fr")
attendee.params["role"] = vText("Etudiant")
attendee = vCalAddress("mailto:{emailize(e.nom, prenom=e.prenom)}")
attendee.params["cn"] = vText(str(e))
attendee.params["role"] = vText("Etudiant")
event.add("attendee", attendee, encode=0)