2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Exception handling
|
|
|
|
"""
|
2023-02-12 01:13:43 +01:00
|
|
|
from flask_login import current_user
|
2024-02-22 17:39:18 +01:00
|
|
|
import app
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-05-11 14:01:23 +02:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# --- Exceptions
|
|
|
|
class ScoException(Exception):
|
2023-02-12 01:13:43 +01:00
|
|
|
"super classe de toutes les exceptions ScoDoc."
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidNoteValue(ScoException):
|
2023-02-12 01:13:43 +01:00
|
|
|
"Valeur note invalide. Usage interne saisie note."
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-03-19 10:26:03 +01:00
|
|
|
class ScoInvalidCSRF(ScoException):
|
|
|
|
"Erreur validation token CSRF"
|
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
class ScoValueError(ScoException):
|
2024-05-20 10:46:36 +02:00
|
|
|
"""Exception avec page d'erreur utilisateur
|
|
|
|
- dest_url : url où aller après la page d'erreur
|
|
|
|
- safe (default False): si vrai, affiche le message non html quoté.
|
|
|
|
"""
|
2023-05-11 14:01:23 +02:00
|
|
|
|
2023-02-12 01:13:43 +01:00
|
|
|
# mal nommée: super classe de toutes les exceptions avec page
|
|
|
|
# d'erreur gentille.
|
2024-08-23 19:01:10 +02:00
|
|
|
def __init__(self, msg, dest_url=None, dest_label=None, safe=False):
|
2022-01-04 17:33:02 +01:00
|
|
|
super().__init__(msg)
|
2024-08-23 19:01:10 +02:00
|
|
|
# champs utilisés par template sco_value_error.j2
|
2020-09-26 16:19:37 +02:00
|
|
|
self.dest_url = dest_url
|
2024-08-23 19:01:10 +02:00
|
|
|
self.dest_label = dest_label
|
|
|
|
self.safe = safe
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-08-26 14:05:25 +02:00
|
|
|
class ScoPermissionDenied(ScoValueError):
|
|
|
|
"""Permission non accordée (appli web)"""
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg=None, dest_url=None, safe=False):
|
2022-08-26 14:05:25 +02:00
|
|
|
if msg is None:
|
2023-02-12 01:13:43 +01:00
|
|
|
msg = f"""Opération non autorisée pour {
|
|
|
|
current_user.get_nomcomplet() if current_user else "?"
|
|
|
|
}. Pas la permission, ou objet verrouillé."""
|
2024-06-26 21:26:51 +02:00
|
|
|
super().__init__(msg, dest_url=dest_url, safe=safe)
|
2022-08-26 14:05:25 +02:00
|
|
|
|
|
|
|
|
2022-03-21 11:48:34 +01:00
|
|
|
class ScoBugCatcher(ScoException):
|
|
|
|
"bug avec enquete en cours"
|
|
|
|
|
|
|
|
|
2022-01-17 22:32:44 +01:00
|
|
|
class NoteProcessError(ScoValueError):
|
|
|
|
"Valeurs notes invalides"
|
|
|
|
|
|
|
|
|
2022-01-18 20:23:47 +01:00
|
|
|
class InvalidEtudId(NoteProcessError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-12-03 14:13:49 +01:00
|
|
|
class ScoFormatError(ScoValueError):
|
2023-05-11 14:01:23 +02:00
|
|
|
"Erreur lecture d'un fichier fourni par l'utilisateur"
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg, filename="", dest_url=None, safe=False):
|
|
|
|
super().__init__(msg, dest_url=dest_url, safe=safe)
|
2023-05-11 14:01:23 +02:00
|
|
|
self.filename = filename
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-04-12 17:12:51 +02:00
|
|
|
class ScoInvalidParamError(ScoValueError):
|
|
|
|
"""Paramètres requete invalides.
|
2023-01-03 13:06:11 +01:00
|
|
|
Utilisée lorsqu'une route est appelée avec des paramètres invalides
|
2022-04-12 17:12:51 +02:00
|
|
|
(id strings, ...)
|
|
|
|
"""
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg=None, dest_url=None, safe=False):
|
2022-04-12 17:12:51 +02:00
|
|
|
msg = msg or "Adresse invalide. Vérifiez vos signets."
|
2024-06-26 21:26:51 +02:00
|
|
|
super().__init__(msg, dest_url=dest_url, safe=safe)
|
2022-04-12 17:12:51 +02:00
|
|
|
|
|
|
|
|
2022-01-13 22:36:40 +01:00
|
|
|
class ScoPDFFormatError(ScoValueError):
|
|
|
|
"erreur génération PDF (templates platypus, ...)"
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg, dest_url=None, safe=False):
|
2022-01-13 22:36:40 +01:00
|
|
|
super().__init__(
|
|
|
|
f"""Erreur dans un format pdf:
|
|
|
|
<p>{msg}</p>
|
2024-04-10 15:29:30 +02:00
|
|
|
<p>Vérifiez les paramètres (polices de caractères, balisage, réglages bulletins...)
|
2022-01-13 22:36:40 +01:00
|
|
|
dans les paramètres ou préférences.
|
|
|
|
</p>
|
|
|
|
""",
|
|
|
|
dest_url=dest_url,
|
2024-06-26 21:26:51 +02:00
|
|
|
safe=safe,
|
2022-01-13 22:36:40 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-06-02 22:40:34 +02:00
|
|
|
class ScoInvalidDept(ScoValueError):
|
|
|
|
"""departement invalide"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-05-31 00:14:15 +02:00
|
|
|
class ScoConfigurationError(ScoValueError):
|
|
|
|
"""Configuration invalid"""
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-01-04 17:33:02 +01:00
|
|
|
class ScoLockedFormError(ScoValueError):
|
|
|
|
"Modification d'une formation verrouillée"
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg="", dest_url=None, safe=False):
|
2020-09-26 16:19:37 +02:00
|
|
|
msg = (
|
|
|
|
"Cette formation est verrouillée (car il y a un semestre verrouillé qui s'y réfère). "
|
|
|
|
+ str(msg)
|
|
|
|
)
|
2024-06-26 21:26:51 +02:00
|
|
|
super().__init__(msg=msg, dest_url=dest_url, safe=safe)
|
2023-02-10 22:04:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScoLockedSemError(ScoValueError):
|
|
|
|
"Modification d'un formsemestre verrouillé"
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, msg="", dest_url=None, safe=False):
|
2023-02-10 22:04:09 +01:00
|
|
|
msg = "Ce semestre est verrouillé ! " + str(msg)
|
2024-06-26 21:26:51 +02:00
|
|
|
super().__init__(msg=msg, dest_url=dest_url, safe=safe)
|
2022-01-04 17:33:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScoNonEmptyFormationObject(ScoValueError):
|
|
|
|
"""On ne peut pas supprimer un module/matiere ou UE si des formsemestre s'y réfèrent"""
|
|
|
|
|
2024-06-26 21:26:51 +02:00
|
|
|
def __init__(self, type_objet="objet'", msg="", dest_url=None, safe=False):
|
2022-07-13 18:52:07 +02:00
|
|
|
msg = f"""<h3>{type_objet} "{msg}" utilisé(e) dans des semestres: suppression impossible.</h3>
|
2023-12-22 15:18:20 +01:00
|
|
|
<p class="help">Il faut d'abord supprimer le semestre (ou en retirer ce {type_objet}).
|
|
|
|
Mais il est peut-être préférable de laisser ce programme intact et d'en créer une
|
2022-01-04 17:33:02 +01:00
|
|
|
nouvelle version pour la modifier sans affecter les semestres déjà en place.
|
|
|
|
</p>
|
|
|
|
"""
|
2024-06-26 21:26:51 +02:00
|
|
|
super().__init__(msg=msg, dest_url=dest_url, safe=safe)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-01-10 12:00:02 +01:00
|
|
|
class ScoInvalidIdType(ScoValueError):
|
2022-03-13 22:02:30 +01:00
|
|
|
"""Pour les clients qui s'obstinent à utiliser des bookmarks
|
|
|
|
ou historiques anciens avec des ID ScoDoc7.
|
|
|
|
"""
|
2022-01-10 12:00:02 +01:00
|
|
|
|
|
|
|
def __init__(self, msg=""):
|
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
|
|
|
|
msg = f"""<h3>Adresse de page invalide</h3>
|
|
|
|
<p class="help">
|
2023-12-22 15:18:20 +01:00
|
|
|
Vous utilisez un lien invalide, qui correspond probablement
|
2022-01-10 12:00:02 +01:00
|
|
|
à une ancienne version du logiciel. <br>
|
|
|
|
Au besoin, mettre à jour vos marque-pages.
|
|
|
|
</p>
|
|
|
|
<p> Si le problème persiste, merci de contacter l'assistance
|
|
|
|
via la liste de diffusion <a href="{scu.SCO_USERS_LIST}">Notes</a>
|
2022-09-18 16:53:00 +02:00
|
|
|
ou de préférence le <a href="{scu.SCO_DISCORD_ASSISTANCE}">salon Discord</a>.
|
2022-01-10 12:00:02 +01:00
|
|
|
</p>
|
|
|
|
<p>Message serveur: <tt>{msg}</tt></p>
|
|
|
|
"""
|
|
|
|
super().__init__(msg)
|
|
|
|
|
|
|
|
|
2023-01-03 13:06:11 +01:00
|
|
|
class ScoNoReferentielCompetences(ScoValueError):
|
|
|
|
"""Formation APC (BUT) non associée à référentiel de compétences"""
|
|
|
|
|
|
|
|
def __init__(self, msg: str = "", formation: "Formation" = None):
|
|
|
|
formation_title = (
|
2023-01-04 13:15:57 +01:00
|
|
|
f"{formation.titre} version {formation.version}" if formation else ""
|
2023-01-03 13:06:11 +01:00
|
|
|
)
|
|
|
|
msg = f"""
|
|
|
|
<p>Pas de référentiel de compétences associé à la formation {formation_title}!
|
|
|
|
</p>
|
|
|
|
<p>Pour associer un référentiel, passer par le menu <b>Semestre /
|
|
|
|
Voir la formation... </b> et suivre le lien <em>"associer à un référentiel
|
|
|
|
de compétences"</em>
|
|
|
|
"""
|
|
|
|
super().__init__(msg)
|
|
|
|
|
|
|
|
|
2024-07-19 16:32:56 +02:00
|
|
|
class ScoGenError(ScoValueError):
|
2020-09-26 16:19:37 +02:00
|
|
|
"exception avec affichage d'une page explicative ad-hoc"
|
|
|
|
|
2024-07-19 16:32:56 +02:00
|
|
|
def __init__(self, msg="", safe=False):
|
|
|
|
super().__init__(msg, safe=safe)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-10-10 21:03:18 +02:00
|
|
|
class AccessDenied(ScoGenError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
class ScoInvalidDateError(ScoValueError):
|
|
|
|
pass
|
2021-09-13 09:54:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
class APIInvalidParams(Exception):
|
2022-10-30 16:07:06 +01:00
|
|
|
"""Exception pour les API JSON"""
|
|
|
|
|
2021-09-13 09:54:53 +02:00
|
|
|
status_code = 400
|
|
|
|
|
|
|
|
def __init__(self, message, status_code=None, payload=None):
|
2022-01-04 17:33:02 +01:00
|
|
|
super().__init__()
|
2021-09-13 09:54:53 +02:00
|
|
|
self.message = message
|
|
|
|
if status_code is not None:
|
|
|
|
self.status_code = status_code
|
|
|
|
self.payload = payload
|
|
|
|
|
|
|
|
def to_dict(self):
|
2022-10-30 16:07:06 +01:00
|
|
|
"dict"
|
2021-09-13 09:54:53 +02:00
|
|
|
rv = dict(self.payload or ())
|
|
|
|
rv["message"] = self.message
|
|
|
|
return rv
|
2022-10-30 16:07:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScoFormationConflict(Exception):
|
|
|
|
"""Conflit cohérence formation (APC)"""
|
2024-02-02 15:16:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScoTemporaryError(ScoValueError):
|
|
|
|
"""Erreurs temporaires rarissimes (caches ?)"""
|
|
|
|
|
|
|
|
def __init__(self, msg: str = ""):
|
|
|
|
msg = """
|
2024-02-22 17:39:18 +01:00
|
|
|
<p>Erreur temporaire</p>
|
|
|
|
<p>Veuillez ré-essayer. Si le problème persiste (ou s'il venait
|
|
|
|
à se produire fréquemment), merci de contacter l'assistance ScoDoc
|
|
|
|
(voir <a href="https://scodoc.org/Contact/">les informations de contact</a>).
|
2024-02-02 15:16:55 +01:00
|
|
|
</p>
|
|
|
|
"""
|
2024-02-22 17:39:18 +01:00
|
|
|
app.clear_scodoc_cache()
|
2024-02-02 15:16:55 +01:00
|
|
|
super().__init__(msg)
|