Compare commits
No commits in common. "0bfa51bf0c4dfed54b2abf4095c9130b903f62b1" and "4b3f1462e7a29c055a3929349d8a67428d51bcea" have entirely different histories.
0bfa51bf0c
...
4b3f1462e7
|
@ -9,36 +9,26 @@ from colloscope.models import *
|
||||||
LOCAL_TZ = "Europe/Paris"
|
LOCAL_TZ = "Europe/Paris"
|
||||||
|
|
||||||
|
|
||||||
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):
|
def to_calendar(etudiant, periode):
|
||||||
|
|
||||||
p = path.abspath('./static/Base_Calendar.ics')
|
p = path.abspath('./static/Base_Calendar.ics')
|
||||||
|
|
||||||
with open(p) as f:
|
with open(p) as f:
|
||||||
cal = Calendar.from_ical(f.read())
|
cal = Calendar.from_ical(f.read())
|
||||||
|
|
||||||
|
|
||||||
rotations = Rotation.objects \
|
rotations = Rotation.objects \
|
||||||
.filter(groupes__membres=etudiant, periode=periode) \
|
.filter(groupes__membres=etudiant) \
|
||||||
.select_related("creneau__periode__classe__lycee") \
|
.select_related("creneau__periode__classe__lycee") \
|
||||||
.select_related("creneau__matiere") \
|
.select_related("creneau__matiere") \
|
||||||
.select_related("creneau__colleur")
|
.select_related("creneau__colleur") \
|
||||||
|
|
||||||
for rotation in rotations:
|
for rotation in rotations:
|
||||||
event = Event()
|
event = Event()
|
||||||
|
|
||||||
summary = f"Colle {rotation.creneau.matiere} ({rotation.creneau.colleur})"
|
summary = f"Colle {rotation.creneau.matiere} ({rotation.creneau.colleur})"
|
||||||
event.add("summary", summary)
|
event.add("summary", summary)
|
||||||
|
|
||||||
start = rotation.datetime()
|
start = rotation.datetime()
|
||||||
fin = start + rotation.creneau.duree
|
fin = start + rotation.creneau.duree
|
||||||
|
|
||||||
|
@ -46,6 +36,7 @@ def to_calendar(etudiant, periode):
|
||||||
event.add("dtend", fin, parameters={"tzid": LOCAL_TZ})
|
event.add("dtend", fin, parameters={"tzid": LOCAL_TZ})
|
||||||
event.add("dtstamp", datetime.now())
|
event.add("dtstamp", datetime.now())
|
||||||
event.add("uid", str(uuid4()))
|
event.add("uid", str(uuid4()))
|
||||||
|
|
||||||
|
|
||||||
event.add("location", f"{rotation.creneau.salle} ({rotation.creneau.periode.classe.lycee})")
|
event.add("location", f"{rotation.creneau.salle} ({rotation.creneau.periode.classe.lycee})")
|
||||||
event.add("categories", "COLLE-" + str(rotation.creneau.matiere))
|
event.add("categories", "COLLE-" + str(rotation.creneau.matiere))
|
||||||
|
@ -53,15 +44,15 @@ def to_calendar(etudiant, periode):
|
||||||
description = f"Groupes: {','.join(str(groupe) for groupe in rotation.groupes.all())}"
|
description = f"Groupes: {','.join(str(groupe) for groupe in rotation.groupes.all())}"
|
||||||
event.add("description", description)
|
event.add("description", description)
|
||||||
|
|
||||||
organizer = vCalAddress(f"mailto:{emailize(rotation.creneau.colleur.nom)}")
|
organizer = vCalAddress("mailto:unknown@mp2i-vms.fr")
|
||||||
organizer.params["cn"] = vText(str(rotation.creneau.colleur))
|
organizer.params["cn"] = vText(str(rotation.creneau.colleur))
|
||||||
organizer.params["role"] = vText("Colleur")
|
organizer.params["role"] = vText("Colleur")
|
||||||
event.add("organizer", organizer)
|
event.add("organizer", organizer)
|
||||||
|
|
||||||
for e in rotation.groupe_effectif():
|
for e in rotation.groupe_effectif():
|
||||||
attendee = vCalAddress("mailto:{emailize(e.nom, prenom=e.prenom)}")
|
attendee = vCalAddress("mailto:unknown@mp2i-vms.fr")
|
||||||
attendee.params["cn"] = vText(str(e))
|
|
||||||
attendee.params["role"] = vText("Etudiant")
|
attendee.params["role"] = vText("Etudiant")
|
||||||
|
attendee.params["cn"] = vText(str(e))
|
||||||
|
|
||||||
event.add("attendee", attendee, encode=0)
|
event.add("attendee", attendee, encode=0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue