2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2022-01-01 14:49:42 +01:00
|
|
|
# Copyright (c) 1999 - 2022 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
|
|
|
|
"""
|
|
|
|
|
|
|
|
# --- Exceptions
|
|
|
|
MSGPERMDENIED = "l'utilisateur %s n'a pas le droit d'effectuer cette operation"
|
|
|
|
|
|
|
|
|
|
|
|
class ScoException(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class InvalidNoteValue(ScoException):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-01-27 10:22:42 +01:00
|
|
|
# Exception qui stoque dest_url
|
2020-09-26 16:19:37 +02:00
|
|
|
class ScoValueError(ScoException):
|
2021-09-21 13:36:56 +02:00
|
|
|
def __init__(self, msg, dest_url=None):
|
2022-01-04 17:33:02 +01:00
|
|
|
super().__init__(msg)
|
2020-09-26 16:19:37 +02:00
|
|
|
self.dest_url = dest_url
|
|
|
|
|
|
|
|
|
2022-08-26 14:05:25 +02:00
|
|
|
class ScoPermissionDenied(ScoValueError):
|
|
|
|
"""Permission non accordée (appli web)"""
|
|
|
|
|
|
|
|
def __init__(self, msg=None, dest_url=None):
|
|
|
|
if msg is None:
|
|
|
|
msg = "Opération non autorisée !"
|
|
|
|
super().__init__(msg, dest_url=dest_url)
|
|
|
|
|
|
|
|
|
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):
|
2020-09-26 16:19:37 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-04-12 17:12:51 +02:00
|
|
|
class ScoInvalidParamError(ScoValueError):
|
|
|
|
"""Paramètres requete invalides.
|
|
|
|
A utilisée lorsqu'une route est appelée avec des paramètres invalides
|
|
|
|
(id strings, ...)
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, msg=None, dest_url=None):
|
|
|
|
msg = msg or "Adresse invalide. Vérifiez vos signets."
|
|
|
|
super().__init__(msg, dest_url=dest_url)
|
|
|
|
|
|
|
|
|
2022-01-13 22:36:40 +01:00
|
|
|
class ScoPDFFormatError(ScoValueError):
|
|
|
|
"erreur génération PDF (templates platypus, ...)"
|
|
|
|
|
|
|
|
def __init__(self, msg, dest_url=None):
|
|
|
|
super().__init__(
|
|
|
|
f"""Erreur dans un format pdf:
|
|
|
|
<p>{msg}</p>
|
|
|
|
<p>Vérifiez les paramètres (polices de caractères, balisage)
|
|
|
|
dans les paramètres ou préférences.
|
|
|
|
</p>
|
|
|
|
""",
|
|
|
|
dest_url=dest_url,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
def __init__(self, msg="", dest_url=None):
|
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)
|
|
|
|
)
|
2022-01-04 17:33:02 +01:00
|
|
|
super().__init__(msg=msg, dest_url=dest_url)
|
|
|
|
|
|
|
|
|
|
|
|
class ScoNonEmptyFormationObject(ScoValueError):
|
|
|
|
"""On ne peut pas supprimer un module/matiere ou UE si des formsemestre s'y réfèrent"""
|
|
|
|
|
|
|
|
def __init__(self, type_objet="objet'", msg="", dest_url=None):
|
2022-07-13 18:52:07 +02:00
|
|
|
msg = f"""<h3>{type_objet} "{msg}" utilisé(e) dans des semestres: suppression impossible.</h3>
|
2022-01-04 17:33:02 +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
|
|
|
|
nouvelle version pour la modifier sans affecter les semestres déjà en place.
|
|
|
|
</p>
|
|
|
|
"""
|
|
|
|
super().__init__(msg=msg, dest_url=dest_url)
|
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">
|
|
|
|
Vous utilisez un lien invalide, qui correspond probablement
|
|
|
|
à 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>
|
|
|
|
ou le salon Discord.
|
|
|
|
</p>
|
|
|
|
<p>Message serveur: <tt>{msg}</tt></p>
|
|
|
|
"""
|
|
|
|
super().__init__(msg)
|
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
class ScoGenError(ScoException):
|
|
|
|
"exception avec affichage d'une page explicative ad-hoc"
|
|
|
|
|
2021-09-21 13:36:56 +02:00
|
|
|
def __init__(self, msg=""):
|
2022-01-04 17:33:02 +01:00
|
|
|
super().__init__(msg)
|
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
|
|
|
|
|
|
|
|
|
|
|
# Pour les API JSON
|
|
|
|
class APIInvalidParams(Exception):
|
|
|
|
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):
|
|
|
|
rv = dict(self.payload or ())
|
|
|
|
rv["message"] = self.message
|
|
|
|
return rv
|