From 098502f2d345855782de756ec3eeea1306eb21fd Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Tue, 14 Nov 2023 14:06:47 +0100 Subject: [PATCH] =?UTF-8?q?EDT:=20am=C3=A9liore=20gestion=20erreur=20charg?= =?UTF-8?q?ement=20ics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/formsemestres.py | 4 +++- app/scodoc/sco_edt_cal.py | 31 ++++++++++++++++++++++++++----- app/templates/formsemestre/edt.j2 | 7 ++++++- sco_version.py | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/app/api/formsemestres.py b/app/api/formsemestres.py index 87a6401940..3aaef1c78f 100644 --- a/app/api/formsemestres.py +++ b/app/api/formsemestres.py @@ -565,7 +565,9 @@ def save_groups_auto_assignment(formsemestre_id: int): @permission_required(Permission.ScoView) @as_json def formsemestre_edt(formsemestre_id: int): - """l'emploi du temps du semestre""" + """l'emploi du temps du semestre + Si ok, une liste d'évènements. Sinon, une chaine indiquant un message d'erreur. + """ query = FormSemestre.query.filter_by(id=formsemestre_id) if g.scodoc_dept: query = query.filter_by(dept_id=g.scodoc_dept_id) diff --git a/app/scodoc/sco_edt_cal.py b/app/scodoc/sco_edt_cal.py index 0c7f89b440..7d63add014 100644 --- a/app/scodoc/sco_edt_cal.py +++ b/app/scodoc/sco_edt_cal.py @@ -58,13 +58,31 @@ def formsemestre_load_calendar( try: with open(ics_filename, "rb") as file: log(f"Loading edt from {ics_filename}") - calendar = icalendar.Calendar.from_ical(file.read()) - except FileNotFoundError: - flash("erreur chargement du calendrier") + try: + calendar = icalendar.Calendar.from_ical(file.read()) + except ValueError as exc: + log( + f"""formsemestre_load_calendar: error importing ics for { + formsemestre}\npath='{ics_filename}'""" + ) + raise ScoValueError( + f"calendrier ics illisible (edt_id={edt_id})" + ) from exc + except FileNotFoundError as exc: log( f"formsemestre_load_calendar: ics not found for {formsemestre}\npath='{ics_filename}'" ) - return None + raise ScoValueError( + f"Fichier ics introuvable (filename={ics_filename})" + ) from exc + except PermissionError as exc: + log( + f"""formsemestre_load_calendar: permission denied for {formsemestre + }\npath='{ics_filename}'""" + ) + raise ScoValueError( + f"Fichier ics inaccessible: vérifier permissions (filename={ics_filename})" + ) from exc return calendar @@ -88,7 +106,10 @@ def formsemestre_edt_dict(formsemestre: FormSemestre) -> list[dict]: Fonction appellée par l'API /formsemestre//edt TODO: spécifier intervalle de dates start et end """ - events_scodoc = _load_and_convert_ics(formsemestre) + try: + events_scodoc = _load_and_convert_ics(formsemestre) + except ScoValueError as exc: + return exc.args[0] # Génération des événements pour le calendrier html events_cal = [] for event in events_scodoc: diff --git a/app/templates/formsemestre/edt.j2 b/app/templates/formsemestre/edt.j2 index 2dbdaadb1c..d5bb1debfd 100644 --- a/app/templates/formsemestre/edt.j2 +++ b/app/templates/formsemestre/edt.j2 @@ -95,7 +95,12 @@ document.addEventListener('DOMContentLoaded', function() { fetch(`${SCO_URL}/../api/formsemestre/{{formsemestre.id}}/edt`) .then(r=>{return r.json()}) .then(events=>{ - calendar.createEvents(events); + if (typeof events == 'string') { + // error ! + alert("error: " + events) + } else { + calendar.createEvents(events); + } }); }); diff --git a/sco_version.py b/sco_version.py index 1fd49c1119..e8ed7d5f80 100644 --- a/sco_version.py +++ b/sco_version.py @@ -1,7 +1,7 @@ # -*- mode: python -*- # -*- coding: utf-8 -*- -SCOVERSION = "9.6.53" +SCOVERSION = "9.6.54" SCONAME = "ScoDoc"