Compare commits

...

15 Commits

Author SHA1 Message Date
Valentin Moguérou fb9580c26e parse email strings 2024-04-20 15:02:20 +02:00
Valentin Moguérou ac0f0e75e6 unique uid for event 2024-04-20 14:55:12 +02:00
Valentin Moguérou b81c70519b f string 2024-04-20 14:45:52 +02:00
Valentin Moguérou 214abf1f43 Merge 2024-04-20 14:44:15 +02:00
Valentin Moguérou 0bfa51bf0c Merge 2024-04-20 14:41:35 +02:00
Valentin Moguérou 8bd4cfa756 Merge remote-tracking branch 'refs/remotes/origin/dev'
# Conflicts:
#	colloscope/icalexport.py
2024-04-20 14:40:17 +02:00
Valentin Moguérou 4b3f1462e7 Actualiser kholles_web/settings.sample.py 2024-04-20 12:57:06 +02:00
Valentin Moguérou d26e1e5690 Actualiser .gitignore 2024-04-20 12:55:53 +02:00
Valentin Moguérou 22b6e77997 Merge pull request 'f string fix' (#3) from dev into main
Reviewed-on: sl_game_studio/kholles-web#3
2024-04-20 12:54:31 +02:00
Valentin Moguérou e671b5a1a1 f string fix 2024-04-20 12:41:33 +02:00
Valentin Moguérou b563e962dd Merge pull request 'fix broken ics export' (#2) from dev into main
Reviewed-on: sl_game_studio/kholles-web#2
2024-04-20 12:38:38 +02:00
Valentin Moguérou b1556643de Actualiser colloscope/icalexport.py 2024-04-20 12:37:07 +02:00
joseph 35bf2e794a fix broken ics export 2024-04-20 12:32:03 +02:00
Valentin Moguérou 6332e083c1 Merge pull request 'respect RFC 5545 for ics export' (#1) from dev into main
Reviewed-on: sl_game_studio/kholles-web#1
2024-04-20 12:27:51 +02:00
joseph 5fd334f7fa respect RFC 5545 for ics export 2024-04-20 11:43:14 +02:00
4 changed files with 60 additions and 24 deletions

2
.gitignore vendored
View File

@ -159,3 +159,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear # and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder. # option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/ .idea/
kholles_web/settings.py

View File

@ -1,47 +1,55 @@
from datetime import date, time, datetime, timedelta from unidecode import unidecode
from pytz import timezone from os import path
from icalendar import Calendar, Event, vCalAddress, vText from icalendar import Calendar, Event, vCalAddress, vText
from colloscope.models import * from colloscope.models import *
LOCAL_TZ = "Europe/Paris"
def emailize(nom, prenom=None): def emailize(nom, prenom=None):
if prenom is not None: if prenom is not None:
return "{}.{}@example.com" \ return "{}.{}@example.com" \
.format( .format(
prenom.replace(" ", "_").lower(), unidecode(prenom).replace(" ", "_").lower(),
nom.replace(" ", "_").lower() unidecode(nom).replace(" ", "_").lower()
) )
else: else:
return "{}@example.com" \ return "{}@example.com" \
.format(nom.replace(" ", "_").lower()) .format(unidecode(nom).replace(" ", "_").lower())
def to_calendar(etudiant, periode): def to_calendar(etudiant, periode):
cal = Calendar() p = path.abspath('./static/Base_Calendar.ics')
cal.add("prodid", "-//Colloscope//colles.mp2i-vms.fr//") with open(p) as f:
cal.add("version", "2.0") cal = Calendar.from_ical(f.read())
rotations = Rotation.objects \ rotations = Rotation.objects \
.filter(groupes__membres=etudiant) \ .filter(groupes__membres=etudiant, creneau__periode=periode) \
.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()
event.add("name", "Colle")
event.add("summary", str(rotation)) summary = f"Colle {rotation.creneau.matiere} ({rotation.creneau.colleur})"
event.add("summary", summary)
start = rotation.datetime() start = rotation.datetime()
fin = start + rotation.creneau.duree fin = start + rotation.creneau.duree
event.add("dtstart", start) event.add("dtstart", start, parameters={"tzid": LOCAL_TZ})
event.add("dtend", fin) event.add("dtend", fin, parameters={"tzid": LOCAL_TZ})
event.add("dtstamp", datetime.now()) event.add("dtstamp", datetime.now())
event.add("uid", str(rotation.id))
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("matiere", str(rotation.creneau.matiere)) 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(f"mailto:{emailize(rotation.creneau.colleur.nom)}") organizer = vCalAddress(f"mailto:{emailize(rotation.creneau.colleur.nom)}")
organizer.params["cn"] = vText(str(rotation.creneau.colleur)) organizer.params["cn"] = vText(str(rotation.creneau.colleur))
@ -49,7 +57,7 @@ def to_calendar(etudiant, periode):
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(f"mailto:{emailize(e.nom, prenom=e.prenom)}")
attendee.params["cn"] = vText(str(e)) attendee.params["cn"] = vText(str(e))
attendee.params["role"] = vText("Etudiant") attendee.params["role"] = vText("Etudiant")

View File

@ -25,12 +25,12 @@ SECRET_KEY = 'django-insecure-$)@!wj+$^y1@^tr78ay&)cna10da_k^vncrbo+4ja-qth$8bhz
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = ["127.0.0.1", "colles.mp2i-vms.fr"] ALLOWED_HOSTS = ["127.0.0.1"] # à modifier
CSRF_TRUSTED_ORIGINS = [ CSRF_TRUSTED_ORIGINS = [
"http://127.0.0.1:8000", "http://127.0.0.1:8000",
"https://colles.mp2i-vms.fr" "https://colles.mp2i-vms.fr"
] ] # à modifier
CORS_ORIGIN_WHITELIST = [ CORS_ORIGIN_WHITELIST = [
"http://localhost:8000", "http://localhost:8000",

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