151 lines
4.3 KiB
Python
151 lines
4.3 KiB
Python
# -*- mode: python -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
#
|
|
# Gestion scolarite IUT
|
|
#
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
#
|
|
# 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 NoteProcessError(ScoException):
|
|
"misc errors in process"
|
|
pass
|
|
|
|
|
|
class InvalidEtudId(NoteProcessError):
|
|
pass
|
|
|
|
|
|
class InvalidNoteValue(ScoException):
|
|
pass
|
|
|
|
|
|
# Exception qui stoque dest_url, utilisee dans Zope standard_error_message
|
|
class ScoValueError(ScoException):
|
|
def __init__(self, msg, dest_url=None):
|
|
super().__init__(msg)
|
|
self.dest_url = dest_url
|
|
|
|
|
|
class ScoFormatError(ScoValueError):
|
|
pass
|
|
|
|
|
|
class ScoInvalidDept(ScoValueError):
|
|
"""departement invalide"""
|
|
|
|
pass
|
|
|
|
|
|
class ScoConfigurationError(ScoValueError):
|
|
"""Configuration invalid"""
|
|
|
|
pass
|
|
|
|
|
|
class ScoLockedFormError(ScoValueError):
|
|
"Modification d'une formation verrouillée"
|
|
|
|
def __init__(self, msg="", dest_url=None):
|
|
msg = (
|
|
"Cette formation est verrouillée (car il y a un semestre verrouillé qui s'y réfère). "
|
|
+ str(msg)
|
|
)
|
|
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):
|
|
msg = f"""<h3>{type_objet} "{msg}" utilisé dans des semestres: suppression impossible.</h3>
|
|
<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)
|
|
|
|
|
|
class ScoInvalidIdType(ScoValueError):
|
|
"""Pour les clients qui s'obstinnent à utiliser des bookmarks ou
|
|
historiques anciens avec des ID ScoDoc7"""
|
|
|
|
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)
|
|
|
|
|
|
class ScoGenError(ScoException):
|
|
"exception avec affichage d'une page explicative ad-hoc"
|
|
|
|
def __init__(self, msg=""):
|
|
super().__init__(msg)
|
|
|
|
|
|
class AccessDenied(ScoGenError):
|
|
pass
|
|
|
|
|
|
class ScoInvalidDateError(ScoValueError):
|
|
pass
|
|
|
|
|
|
# Pour les API JSON
|
|
class APIInvalidParams(Exception):
|
|
status_code = 400
|
|
|
|
def __init__(self, message, status_code=None, payload=None):
|
|
super().__init__()
|
|
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
|