1
0
forked from ScoDoc/ScoDoc

EDT: améliore gestion erreur chargement ics

This commit is contained in:
Emmanuel Viennet 2023-11-14 14:06:47 +01:00
parent 324488f9c4
commit 098502f2d3
4 changed files with 36 additions and 8 deletions

View File

@ -565,7 +565,9 @@ def save_groups_auto_assignment(formsemestre_id: int):
@permission_required(Permission.ScoView) @permission_required(Permission.ScoView)
@as_json @as_json
def formsemestre_edt(formsemestre_id: int): 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) query = FormSemestre.query.filter_by(id=formsemestre_id)
if g.scodoc_dept: if g.scodoc_dept:
query = query.filter_by(dept_id=g.scodoc_dept_id) query = query.filter_by(dept_id=g.scodoc_dept_id)

View File

@ -58,13 +58,31 @@ def formsemestre_load_calendar(
try: try:
with open(ics_filename, "rb") as file: with open(ics_filename, "rb") as file:
log(f"Loading edt from {ics_filename}") log(f"Loading edt from {ics_filename}")
calendar = icalendar.Calendar.from_ical(file.read()) try:
except FileNotFoundError: calendar = icalendar.Calendar.from_ical(file.read())
flash("erreur chargement du calendrier") 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( log(
f"formsemestre_load_calendar: ics not found for {formsemestre}\npath='{ics_filename}'" 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 return calendar
@ -88,7 +106,10 @@ def formsemestre_edt_dict(formsemestre: FormSemestre) -> list[dict]:
Fonction appellée par l'API /formsemestre/<int:formsemestre_id>/edt Fonction appellée par l'API /formsemestre/<int:formsemestre_id>/edt
TODO: spécifier intervalle de dates start et end 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 # Génération des événements pour le calendrier html
events_cal = [] events_cal = []
for event in events_scodoc: for event in events_scodoc:

View File

@ -95,7 +95,12 @@ document.addEventListener('DOMContentLoaded', function() {
fetch(`${SCO_URL}/../api/formsemestre/{{formsemestre.id}}/edt`) fetch(`${SCO_URL}/../api/formsemestre/{{formsemestre.id}}/edt`)
.then(r=>{return r.json()}) .then(r=>{return r.json()})
.then(events=>{ .then(events=>{
calendar.createEvents(events); if (typeof events == 'string') {
// error !
alert("error: " + events)
} else {
calendar.createEvents(events);
}
}); });
}); });

View File

@ -1,7 +1,7 @@
# -*- mode: python -*- # -*- mode: python -*-
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
SCOVERSION = "9.6.53" SCOVERSION = "9.6.54"
SCONAME = "ScoDoc" SCONAME = "ScoDoc"