Merge pull request 'fix broken ics export' (#2) from dev into main

Reviewed-on: sl_game_studio/kholles-web#2
This commit is contained in:
Valentin Moguérou 2024-04-20 12:38:38 +02:00
commit b563e962dd
2 changed files with 34 additions and 28 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) \
@ -62,7 +42,7 @@ def to_calendar(etudiant, periode):
event.add("categories", "COLLE-" + str(rotation.creneau.matiere))
description = "Groupes: {','.join(str(groupe) for groupe in rotation.groupes.all())}"
event.add(description)
event.add("description", description)
organizer = vCalAddress("mailto:unknown@mp2i-vms.fr")
organizer.params["cn"] = vText(str(rotation.creneau.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