fix broken ics export

This commit is contained in:
joseph 2024-04-20 12:32:03 +02:00
parent 941c5c69b6
commit 0fb1806f76
2 changed files with 33 additions and 27 deletions

View File

@ -1,7 +1,7 @@
from datetime import date, time, datetime, timedelta
from pytz import timezone
from uuid import uuid4
from os import path
from icalendar import Calendar, Event, vCalAddress, vText
from colloscope.models import *
@ -10,32 +10,12 @@ LOCAL_TZ = "Europe/Paris"
def to_calendar(etudiant, periode):
cal = Calendar()
cal.add("prodid", "-//Colloscope//colles.mp2i-vms.fr//")
cal.add("version", "2.0")
cal.add(
"""
BEGIN:VTIMEZONE
TZID:Europe/Paris
X-LIC-LOCATION:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
"""
)
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) \
@ -63,7 +43,7 @@ def to_calendar(etudiant, periode):
description = "Groupes: {','.join(str(groupe) for groupe in rotation.groupes.all())}"
event.add(description)
organizer = vCalAddress("mailto:unknown@mp2i-vms.fr")
organizer.params["cn"] = vText(str(rotation.creneau.colleur))
organizer.params["role"] = vText("Colleur")

26
static/Base_Calendar.ics Normal file
View File

@ -0,0 +1,26 @@
BEGIN:VCALENDAR
PRODID:-//mp2i-vms-[2]-(23-24)-s3//Stackity Bot Inc//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:EDT
X-WR-TIMEZONE:Europe/Paris
BEGIN:VTIMEZONE
TZID:Europe/Paris
X-LIC-LOCATION:Europe/Paris
BEGIN:DAYLIGHT
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
TZNAME:CEST
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
TZNAME:CET
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
END:STANDARD
END:VTIMEZONE
END:VCALENDAR