2021-01-17 22:31:28 +01: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.
|
2021-01-17 22:31:28 +01: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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""Fonctions sur les moduleimpl
|
|
|
|
"""
|
2021-08-22 13:24:36 +02:00
|
|
|
|
|
|
|
from flask_login import current_user
|
2022-02-14 13:55:07 +01:00
|
|
|
import psycopg2
|
2021-06-19 23:21:37 +02:00
|
|
|
|
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
import app.scodoc.notesdb as ndb
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
|
|
|
from app.scodoc.sco_exceptions import ScoValueError, AccessDenied
|
2021-08-29 19:57:32 +02:00
|
|
|
from app import log
|
2021-12-10 15:03:29 +01:00
|
|
|
from app import models
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import scolog
|
|
|
|
from app.scodoc import sco_formsemestre
|
2021-07-19 19:53:01 +02:00
|
|
|
from app.scodoc import sco_cache
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
# --- Gestion des "Implémentations de Modules"
|
|
|
|
# Un "moduleimpl" correspond a la mise en oeuvre d'un module
|
|
|
|
# dans une formation spécifique, à une date spécifique.
|
2021-06-19 23:21:37 +02:00
|
|
|
_moduleimplEditor = ndb.EditableTable(
|
2021-01-17 22:31:28 +01:00
|
|
|
"notes_moduleimpl",
|
|
|
|
"moduleimpl_id",
|
|
|
|
(
|
|
|
|
"moduleimpl_id",
|
|
|
|
"module_id",
|
|
|
|
"formsemestre_id",
|
|
|
|
"responsable_id",
|
|
|
|
"computation_expr",
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
_modules_enseignantsEditor = ndb.EditableTable(
|
2021-01-17 22:31:28 +01:00
|
|
|
"notes_modules_enseignants",
|
2021-08-14 18:54:32 +02:00
|
|
|
None, # pas d'id dans cette Table d'association
|
|
|
|
(
|
|
|
|
"moduleimpl_id", # associe moduleimpl
|
|
|
|
"ens_id", # a l'id de l'enseignant (User.id)
|
|
|
|
),
|
2021-01-17 22:31:28 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_create(args):
|
2021-01-17 22:31:28 +01:00
|
|
|
"create a moduleimpl"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
r = _moduleimplEditor.create(cnx, args)
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=args["formsemestre_id"]
|
2021-01-17 22:31:28 +01:00
|
|
|
) # > creation moduleimpl
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_delete(oid, formsemestre_id=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"delete moduleimpl (desinscrit tous les etudiants)"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
# --- desinscription des etudiants
|
2021-06-19 23:21:37 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2021-01-17 22:31:28 +01:00
|
|
|
req = (
|
|
|
|
"DELETE FROM notes_moduleimpl_inscription WHERE moduleimpl_id=%(moduleimpl_id)s"
|
|
|
|
)
|
|
|
|
cursor.execute(req, {"moduleimpl_id": oid})
|
|
|
|
# --- suppression des enseignants
|
|
|
|
cursor.execute(
|
|
|
|
"DELETE FROM notes_modules_enseignants WHERE moduleimpl_id=%(moduleimpl_id)s",
|
|
|
|
{"moduleimpl_id": oid},
|
|
|
|
)
|
|
|
|
# --- suppression des references dans les absences
|
|
|
|
cursor.execute(
|
|
|
|
"UPDATE absences SET moduleimpl_id=NULL WHERE moduleimpl_id=%(moduleimpl_id)s",
|
|
|
|
{"moduleimpl_id": oid},
|
|
|
|
)
|
|
|
|
# --- destruction du moduleimpl
|
|
|
|
_moduleimplEditor.delete(cnx, oid)
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_delete
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-10-15 14:00:51 +02:00
|
|
|
def moduleimpl_list(moduleimpl_id=None, formsemestre_id=None, module_id=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"list moduleimpls"
|
|
|
|
args = locals()
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-19 23:21:37 +02:00
|
|
|
modimpls = _moduleimplEditor.list(cnx, args)
|
2021-01-17 22:31:28 +01:00
|
|
|
# Ajoute la liste des enseignants
|
|
|
|
for mo in modimpls:
|
2021-08-20 01:09:55 +02:00
|
|
|
mo["ens"] = do_ens_list(args={"moduleimpl_id": mo["moduleimpl_id"]})
|
2021-09-27 10:20:10 +02:00
|
|
|
return modimpls
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_edit(args, formsemestre_id=None, cnx=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"edit a moduleimpl"
|
|
|
|
if not cnx:
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
_moduleimplEditor.edit(cnx, args)
|
|
|
|
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
|
|
|
) # > modif moduleimpl
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-10-15 14:00:51 +02:00
|
|
|
def moduleimpl_withmodule_list(
|
2021-12-12 12:32:21 +01:00
|
|
|
moduleimpl_id=None, formsemestre_id=None, module_id=None, sort_by_ue=False
|
2021-12-10 15:03:29 +01:00
|
|
|
) -> list:
|
2021-10-15 14:00:51 +02:00
|
|
|
"""Liste les moduleimpls et ajoute dans chacun
|
|
|
|
l'UE, la matière et le module auxquels ils appartiennent.
|
2021-12-12 12:32:21 +01:00
|
|
|
Tri la liste par:
|
|
|
|
- pour les formations classiques: semestre/UE/numero_matiere/numero_module;
|
|
|
|
- pour le BUT: ignore UEs sauf si sort_by_ue et matières dans le tri.
|
|
|
|
|
2022-08-31 19:14:21 +02:00
|
|
|
NB: Cette fonction faisait partie de l'API ScoDoc 7.
|
2021-01-17 22:31:28 +01:00
|
|
|
"""
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_edit_ue
|
|
|
|
from app.scodoc import sco_edit_matiere
|
|
|
|
from app.scodoc import sco_edit_module
|
|
|
|
|
2021-10-15 14:00:51 +02:00
|
|
|
modimpls = moduleimpl_list(
|
2021-06-19 23:21:37 +02:00
|
|
|
**{
|
|
|
|
"moduleimpl_id": moduleimpl_id,
|
|
|
|
"formsemestre_id": formsemestre_id,
|
|
|
|
"module_id": module_id,
|
|
|
|
}
|
|
|
|
)
|
2021-12-10 15:03:29 +01:00
|
|
|
if not modimpls:
|
|
|
|
return []
|
2021-10-15 14:00:51 +02:00
|
|
|
ues = {}
|
|
|
|
matieres = {}
|
|
|
|
modules = {}
|
|
|
|
for mi in modimpls:
|
|
|
|
module_id = mi["module_id"]
|
|
|
|
if not mi["module_id"] in modules:
|
2021-10-16 19:20:36 +02:00
|
|
|
modules[module_id] = sco_edit_module.module_list(
|
2021-10-15 14:00:51 +02:00
|
|
|
args={"module_id": module_id}
|
|
|
|
)[0]
|
|
|
|
mi["module"] = modules[module_id]
|
|
|
|
ue_id = mi["module"]["ue_id"]
|
|
|
|
if not ue_id in ues:
|
2021-10-17 23:19:26 +02:00
|
|
|
ues[ue_id] = sco_edit_ue.ue_list(args={"ue_id": ue_id})[0]
|
2021-10-15 14:00:51 +02:00
|
|
|
mi["ue"] = ues[ue_id]
|
|
|
|
matiere_id = mi["module"]["matiere_id"]
|
|
|
|
if not matiere_id in matieres:
|
2021-10-17 23:19:26 +02:00
|
|
|
matieres[matiere_id] = sco_edit_matiere.matiere_list(
|
2021-10-15 14:00:51 +02:00
|
|
|
args={"matiere_id": matiere_id}
|
|
|
|
)[0]
|
|
|
|
mi["matiere"] = matieres[matiere_id]
|
2021-01-17 22:31:28 +01:00
|
|
|
|
2021-12-10 15:03:29 +01:00
|
|
|
mod = modimpls[0]["module"]
|
|
|
|
formation = models.Formation.query.get(mod["formation_id"])
|
|
|
|
|
|
|
|
if formation.is_apc():
|
|
|
|
# tri par numero_module
|
2021-12-12 12:32:21 +01:00
|
|
|
if sort_by_ue:
|
|
|
|
modimpls.sort(
|
|
|
|
key=lambda x: (
|
|
|
|
x["ue"]["numero"],
|
|
|
|
x["ue"]["ue_id"],
|
|
|
|
x["module"]["module_type"],
|
|
|
|
x["module"]["numero"],
|
|
|
|
x["module"]["code"],
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
modimpls.sort(
|
|
|
|
key=lambda x: (
|
|
|
|
x["module"]["module_type"],
|
|
|
|
x["module"]["numero"],
|
|
|
|
x["module"]["code"],
|
|
|
|
)
|
2021-12-10 15:03:29 +01:00
|
|
|
)
|
|
|
|
else:
|
|
|
|
# Formations classiques, avec matières:
|
|
|
|
# tri par semestre/UE/numero_matiere/numero_module
|
|
|
|
modimpls.sort(
|
|
|
|
key=lambda x: (
|
|
|
|
x["ue"]["numero"],
|
|
|
|
x["ue"]["ue_id"],
|
|
|
|
x["matiere"]["numero"],
|
|
|
|
x["matiere"]["matiere_id"],
|
|
|
|
x["module"]["numero"],
|
|
|
|
x["module"]["code"],
|
|
|
|
)
|
2021-07-09 23:19:30 +02:00
|
|
|
)
|
2021-01-17 22:31:28 +01:00
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
return modimpls
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-10-22 23:09:15 +02:00
|
|
|
def moduleimpls_in_external_ue(ue_id):
|
|
|
|
"""List of modimpls in this ue"""
|
|
|
|
cursor = ndb.SimpleQuery(
|
|
|
|
"""SELECT DISTINCT mi.*
|
|
|
|
FROM notes_ue u, notes_moduleimpl mi, notes_modules m
|
|
|
|
WHERE u.is_external is true
|
|
|
|
AND mi.module_id = m.id AND m.ue_id = %(ue_id)s
|
|
|
|
""",
|
|
|
|
{"ue_id": ue_id},
|
|
|
|
)
|
|
|
|
return cursor.dictfetchall()
|
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def do_moduleimpl_inscription_list(moduleimpl_id=None, etudid=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"list moduleimpl_inscriptions"
|
|
|
|
args = locals()
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-09-27 10:20:10 +02:00
|
|
|
return _moduleimpl_inscriptionEditor.list(cnx, args)
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-10-15 14:00:51 +02:00
|
|
|
def moduleimpl_listeetuds(moduleimpl_id):
|
2021-01-17 22:31:28 +01:00
|
|
|
"retourne liste des etudids inscrits a ce module"
|
2021-08-10 12:57:38 +02:00
|
|
|
req = """SELECT DISTINCT Im.etudid
|
|
|
|
FROM notes_moduleimpl_inscription Im,
|
|
|
|
notes_formsemestre_inscription Isem,
|
|
|
|
notes_moduleimpl M
|
|
|
|
WHERE Isem.etudid = Im.etudid
|
|
|
|
and Im.moduleimpl_id = M.id
|
|
|
|
and M.id = %(moduleimpl_id)s
|
|
|
|
"""
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-19 23:21:37 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2021-01-17 22:31:28 +01:00
|
|
|
cursor.execute(req, {"moduleimpl_id": moduleimpl_id})
|
|
|
|
res = cursor.fetchall()
|
|
|
|
return [x[0] for x in res]
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_inscrit_tout_semestre(moduleimpl_id, formsemestre_id):
|
2021-01-17 22:31:28 +01:00
|
|
|
"inscrit tous les etudiants inscrit au semestre a ce module"
|
|
|
|
# UNUSED
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-19 23:21:37 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2021-01-17 22:31:28 +01:00
|
|
|
req = """INSERT INTO notes_moduleimpl_inscription
|
|
|
|
(moduleimpl_id, etudid)
|
|
|
|
SELECT %(moduleimpl_id)s, I.etudid
|
|
|
|
FROM notes_formsemestre_inscription I
|
2021-08-10 12:57:38 +02:00
|
|
|
WHERE I.formsemestre_id=%(formsemestre_id)s
|
|
|
|
"""
|
2021-01-17 22:31:28 +01:00
|
|
|
args = {"moduleimpl_id": moduleimpl_id, "formsemestre_id": formsemestre_id}
|
|
|
|
cursor.execute(req, args)
|
|
|
|
|
|
|
|
|
|
|
|
# --- Inscriptions aux modules
|
2021-06-19 23:21:37 +02:00
|
|
|
_moduleimpl_inscriptionEditor = ndb.EditableTable(
|
2021-01-17 22:31:28 +01:00
|
|
|
"notes_moduleimpl_inscription",
|
|
|
|
"moduleimpl_inscription_id",
|
|
|
|
("moduleimpl_inscription_id", "etudid", "moduleimpl_id"),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-09-02 18:05:22 +02:00
|
|
|
def do_moduleimpl_inscription_create(args, formsemestre_id=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"create a moduleimpl_inscription"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2022-02-14 13:55:07 +01:00
|
|
|
try:
|
|
|
|
r = _moduleimpl_inscriptionEditor.create(cnx, args)
|
|
|
|
except psycopg2.errors.UniqueViolation as exc:
|
|
|
|
raise ScoValueError(
|
|
|
|
"Inscription impossible car déjà existante: vérifiez la situation"
|
|
|
|
)
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscription
|
2021-09-02 18:05:22 +02:00
|
|
|
scolog.logdb(
|
|
|
|
cnx,
|
|
|
|
method="moduleimpl_inscription",
|
|
|
|
etudid=args["etudid"],
|
|
|
|
msg="inscription module %s" % args["moduleimpl_id"],
|
|
|
|
commit=False,
|
|
|
|
)
|
2021-01-17 22:31:28 +01:00
|
|
|
return r
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_moduleimpl_inscription_delete(oid, formsemestre_id=None):
|
2021-01-17 22:31:28 +01:00
|
|
|
"delete moduleimpl_inscription"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
_moduleimpl_inscriptionEditor.delete(cnx, oid)
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscription
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def do_moduleimpl_inscrit_etuds(moduleimpl_id, formsemestre_id, etudids, reset=False):
|
2021-01-17 22:31:28 +01:00
|
|
|
"""Inscrit les etudiants (liste d'etudids) a ce module.
|
|
|
|
Si reset, desinscrit tous les autres.
|
|
|
|
"""
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formsemestre_inscriptions
|
|
|
|
|
2021-01-17 22:31:28 +01:00
|
|
|
# Verifie qu'ils sont tous bien inscrits au semestre
|
|
|
|
for etudid in etudids:
|
2021-06-17 00:08:37 +02:00
|
|
|
insem = sco_formsemestre_inscriptions.do_formsemestre_inscription_list(
|
2021-08-19 10:28:35 +02:00
|
|
|
args={"formsemestre_id": formsemestre_id, "etudid": etudid}
|
2021-01-17 22:31:28 +01:00
|
|
|
)
|
|
|
|
if not insem:
|
|
|
|
raise ScoValueError("%s n'est pas inscrit au semestre !" % etudid)
|
|
|
|
|
|
|
|
# Desinscriptions
|
|
|
|
if reset:
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-19 23:21:37 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
2021-01-17 22:31:28 +01:00
|
|
|
cursor.execute(
|
|
|
|
"delete from notes_moduleimpl_inscription where moduleimpl_id = %(moduleimpl_id)s",
|
|
|
|
{"moduleimpl_id": moduleimpl_id},
|
|
|
|
)
|
|
|
|
# Inscriptions au module:
|
|
|
|
inmod_set = set(
|
|
|
|
[
|
2021-01-23 22:57:01 +01:00
|
|
|
# hum ?
|
2021-01-17 22:31:28 +01:00
|
|
|
x["etudid"]
|
2021-08-20 01:09:55 +02:00
|
|
|
for x in do_moduleimpl_inscription_list(moduleimpl_id=moduleimpl_id)
|
2021-01-17 22:31:28 +01:00
|
|
|
]
|
|
|
|
)
|
|
|
|
for etudid in etudids:
|
|
|
|
# deja inscrit ?
|
|
|
|
if not etudid in inmod_set:
|
|
|
|
do_moduleimpl_inscription_create(
|
|
|
|
{"moduleimpl_id": moduleimpl_id, "etudid": etudid},
|
|
|
|
formsemestre_id=formsemestre_id,
|
|
|
|
)
|
|
|
|
|
2021-07-19 19:53:01 +02:00
|
|
|
sco_cache.invalidate_formsemestre(
|
|
|
|
formsemestre_id=formsemestre_id
|
2021-06-13 23:37:14 +02:00
|
|
|
) # > moduleimpl_inscrit_etuds
|
2021-01-17 22:31:28 +01:00
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_ens_list(*args, **kw):
|
2021-01-17 22:31:28 +01:00
|
|
|
"liste les enseignants d'un moduleimpl (pas le responsable)"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
ens = _modules_enseignantsEditor.list(cnx, *args, **kw)
|
|
|
|
return ens
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_ens_edit(*args, **kw):
|
2021-01-17 22:31:28 +01:00
|
|
|
"edit ens"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
_modules_enseignantsEditor.edit(cnx, *args, **kw)
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_ens_create(args):
|
2021-01-17 22:31:28 +01:00
|
|
|
"create ens"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-01-17 22:31:28 +01:00
|
|
|
r = _modules_enseignantsEditor.create(cnx, args)
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def can_change_module_resp(moduleimpl_id):
|
2021-01-17 22:31:28 +01:00
|
|
|
"""Check if current user can modify module resp. (raise exception if not).
|
|
|
|
= Admin, et dir des etud. (si option l'y autorise)
|
|
|
|
"""
|
2021-10-15 14:00:51 +02:00
|
|
|
M = moduleimpl_withmodule_list(moduleimpl_id=moduleimpl_id)[0]
|
2021-01-17 22:31:28 +01:00
|
|
|
# -- check lock
|
2021-08-19 10:28:35 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(M["formsemestre_id"])
|
2021-08-10 12:57:38 +02:00
|
|
|
if not sem["etat"]:
|
2021-01-17 22:31:28 +01:00
|
|
|
raise ScoValueError("Modification impossible: semestre verrouille")
|
|
|
|
# -- check access
|
|
|
|
# admin ou resp. semestre avec flag resp_can_change_resp
|
2021-08-22 13:24:36 +02:00
|
|
|
if not current_user.has_permission(Permission.ScoImplement) and (
|
|
|
|
(current_user.id not in sem["responsables"]) or (not sem["resp_can_change_ens"])
|
2021-01-17 22:31:28 +01:00
|
|
|
):
|
2021-08-22 13:24:36 +02:00
|
|
|
raise AccessDenied("Modification impossible pour %s" % current_user)
|
2021-01-17 22:31:28 +01:00
|
|
|
return M, sem
|
|
|
|
|
|
|
|
|
2021-08-22 13:24:36 +02:00
|
|
|
def can_change_ens(moduleimpl_id, raise_exc=True):
|
2021-01-17 22:31:28 +01:00
|
|
|
"check if current user can modify ens list (raise exception if not)"
|
2021-10-15 14:00:51 +02:00
|
|
|
M = moduleimpl_withmodule_list(moduleimpl_id=moduleimpl_id)[0]
|
2021-01-17 22:31:28 +01:00
|
|
|
# -- check lock
|
2021-08-19 10:28:35 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(M["formsemestre_id"])
|
2021-08-10 12:57:38 +02:00
|
|
|
if not sem["etat"]:
|
2021-01-17 22:31:28 +01:00
|
|
|
if raise_exc:
|
|
|
|
raise ScoValueError("Modification impossible: semestre verrouille")
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
# -- check access
|
|
|
|
# admin, resp. module ou resp. semestre
|
|
|
|
if (
|
2021-08-22 13:24:36 +02:00
|
|
|
current_user.id != M["responsable_id"]
|
|
|
|
and not current_user.has_permission(Permission.ScoImplement)
|
|
|
|
and (current_user.id not in sem["responsables"])
|
2021-01-17 22:31:28 +01:00
|
|
|
):
|
|
|
|
if raise_exc:
|
2021-08-22 13:24:36 +02:00
|
|
|
raise AccessDenied("Modification impossible pour %s" % current_user)
|
2021-01-17 22:31:28 +01:00
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return M, sem
|