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
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
"""Ajout/Modification/Suppression modules
|
2020-09-26 16:19:37 +02:00
|
|
|
(portage from DTML)
|
|
|
|
"""
|
2021-07-31 18:01:10 +02:00
|
|
|
import flask
|
2022-06-26 22:45:53 +02:00
|
|
|
from flask import flash, url_for, render_template
|
2021-11-12 22:17:46 +01:00
|
|
|
from flask import g, request
|
2021-09-18 13:42:19 +02:00
|
|
|
from flask_login import current_user
|
2022-01-19 23:02:15 +01:00
|
|
|
|
2024-10-14 16:40:05 +02:00
|
|
|
from app import db
|
2022-01-19 23:02:15 +01:00
|
|
|
from app import models
|
2021-12-29 19:30:49 +01:00
|
|
|
from app.models import APO_CODE_STR_LEN
|
2022-01-19 23:02:15 +01:00
|
|
|
from app.models import Formation, Matiere, Module, UniteEns
|
2022-01-20 13:00:25 +01:00
|
|
|
from app.models import FormSemestre, ModuleImpl
|
2022-05-02 14:39:06 +02:00
|
|
|
from app.models.but_refcomp import ApcAppCritique, ApcParcours
|
2021-07-31 18:01:10 +02:00
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
|
|
|
from app.scodoc.TrivialFormulator import TrivialFormulator
|
|
|
|
from app.scodoc.sco_permissions import Permission
|
2022-01-04 20:03:38 +01:00
|
|
|
from app.scodoc.sco_exceptions import (
|
|
|
|
ScoValueError,
|
|
|
|
ScoNonEmptyFormationObject,
|
|
|
|
)
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc import codes_cursus
|
2021-06-16 18:18:32 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def module_delete(module_id=None):
|
2024-10-14 16:40:05 +02:00
|
|
|
"""Formulaire suppression d'un module"""
|
2022-01-04 20:03:38 +01:00
|
|
|
module = Module.query.get_or_404(module_id)
|
|
|
|
|
2024-10-14 16:40:05 +02:00
|
|
|
if not module.can_be_deleted():
|
2022-01-04 20:03:38 +01:00
|
|
|
raise ScoNonEmptyFormationObject(
|
|
|
|
"Module",
|
|
|
|
msg=module.titre,
|
|
|
|
dest_url=url_for(
|
|
|
|
"notes.ue_table",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formation_id=module.formation_id,
|
|
|
|
semestre_idx=module.ue.semestre_idx,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
H = [
|
2024-08-24 08:06:46 +02:00
|
|
|
f"""<h2>Suppression du module {module.titre or "<em>sans titre</em>"}
|
|
|
|
({module.code})</h2>""",
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
|
2021-10-22 23:09:15 +02:00
|
|
|
dest_url = url_for(
|
|
|
|
"notes.ue_table",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
2022-05-10 11:04:24 +02:00
|
|
|
formation_id=module.formation_id,
|
|
|
|
semestre_idx=module.ue.semestre_idx,
|
2021-10-22 23:09:15 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
tf = TrivialFormulator(
|
2021-09-18 10:10:02 +02:00
|
|
|
request.base_url,
|
2021-09-27 16:42:14 +02:00
|
|
|
scu.get_request_args(),
|
2020-09-26 16:19:37 +02:00
|
|
|
(("module_id", {"input_type": "hidden"}),),
|
2024-10-14 16:40:05 +02:00
|
|
|
initvalues=module.to_dict(),
|
2020-09-26 16:19:37 +02:00
|
|
|
submitlabel="Confirmer la suppression",
|
|
|
|
cancelbutton="Annuler",
|
|
|
|
)
|
|
|
|
if tf[0] == 0:
|
2024-08-24 08:06:46 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page_dept.j2",
|
|
|
|
title="Suppression d'un module",
|
|
|
|
content="\n".join(H) + tf[1],
|
|
|
|
)
|
2024-10-14 16:40:05 +02:00
|
|
|
if tf[0] == -1: # cancel
|
2021-07-31 18:01:10 +02:00
|
|
|
return flask.redirect(dest_url)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-10-14 16:40:05 +02:00
|
|
|
module.delete()
|
|
|
|
return flask.redirect(dest_url)
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-12-29 19:30:49 +01:00
|
|
|
def do_module_edit(vals: dict) -> None:
|
2021-06-16 18:18:32 +02:00
|
|
|
"edit a module"
|
|
|
|
# check
|
2024-10-14 16:40:05 +02:00
|
|
|
module = Module.get_instance(vals["module_id"])
|
2021-06-16 18:18:32 +02:00
|
|
|
# edit
|
2024-10-14 16:40:05 +02:00
|
|
|
modif = module.from_dict(vals)
|
|
|
|
if modif:
|
|
|
|
module.formation.invalidate_cached_sems()
|
2021-06-16 18:18:32 +02:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2024-10-14 16:40:05 +02:00
|
|
|
def module_create(
|
|
|
|
matiere_id=None, module_type=None, semestre_id=None, formation_id=None
|
|
|
|
):
|
|
|
|
"""Formulaire de création d'un module
|
|
|
|
Si matiere_id est spécifié, le module sera créé dans cette matière (cas normal).
|
|
|
|
Sinon, donne le choix de l'UE de rattachement et utilise la première
|
|
|
|
matière de cette UE (si elle n'existe pas, la crée).
|
|
|
|
"""
|
|
|
|
return module_edit(
|
|
|
|
create=True,
|
|
|
|
matiere_id=matiere_id,
|
|
|
|
module_type=module_type,
|
|
|
|
semestre_id=semestre_id,
|
|
|
|
formation_id=formation_id,
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
def module_edit(
|
|
|
|
module_id=None,
|
|
|
|
create=False,
|
|
|
|
matiere_id=None,
|
|
|
|
module_type=None,
|
|
|
|
semestre_id=None,
|
|
|
|
formation_id=None,
|
|
|
|
):
|
|
|
|
"""Formulaire édition ou création module.
|
|
|
|
Si create, création nouveau module.
|
|
|
|
Si matiere_id est spécifié, le module sera créé dans cette matière (cas normal).
|
|
|
|
Sinon, donne le choix de l'UE de rattachement et utilise la première matière
|
|
|
|
de cette UE (si elle n'existe pas, la crée).
|
|
|
|
"""
|
|
|
|
# --- Détermination de la formation
|
2022-05-29 17:31:29 +02:00
|
|
|
orig_semestre_idx = semestre_id
|
2022-05-02 14:39:06 +02:00
|
|
|
ue = None
|
2022-05-01 23:58:41 +02:00
|
|
|
if create:
|
|
|
|
if matiere_id:
|
2024-10-14 16:40:05 +02:00
|
|
|
matiere = Matiere.get_instance(matiere_id)
|
2022-05-01 23:58:41 +02:00
|
|
|
ue = matiere.ue
|
|
|
|
formation = ue.formation
|
|
|
|
orig_semestre_idx = ue.semestre_idx if semestre_id is None else semestre_id
|
|
|
|
else:
|
|
|
|
formation = Formation.query.get_or_404(formation_id)
|
|
|
|
module = None
|
|
|
|
unlocked = True
|
|
|
|
else:
|
|
|
|
if not module_id:
|
|
|
|
raise ValueError("missing module_id !")
|
|
|
|
module = models.Module.query.get_or_404(module_id)
|
2022-05-02 14:39:06 +02:00
|
|
|
ue = module.ue
|
2022-05-01 23:58:41 +02:00
|
|
|
module_dict = module.to_dict()
|
|
|
|
formation = module.formation
|
2024-10-14 16:40:05 +02:00
|
|
|
unlocked = not module.is_locked()
|
2022-05-01 23:58:41 +02:00
|
|
|
|
2023-02-12 13:36:47 +01:00
|
|
|
parcours = codes_cursus.get_cursus_from_code(formation.type_parcours)
|
2022-01-20 13:00:25 +01:00
|
|
|
is_apc = parcours.APC_SAE # BUT
|
2022-05-01 23:58:41 +02:00
|
|
|
if not create:
|
|
|
|
orig_semestre_idx = module.ue.semestre_idx if is_apc else module.semestre_id
|
|
|
|
if orig_semestre_idx is None:
|
|
|
|
orig_semestre_idx = 1
|
|
|
|
# il y a-t-il des modimpls ?
|
|
|
|
in_use = (module is not None) and (len(module.modimpls.all()) > 0)
|
2022-01-27 11:44:58 +01:00
|
|
|
matieres = Matiere.query.filter(
|
2022-05-01 23:58:41 +02:00
|
|
|
Matiere.ue_id == UniteEns.id, UniteEns.formation_id == formation.id
|
2022-01-27 11:44:58 +01:00
|
|
|
).order_by(UniteEns.semestre_idx, UniteEns.numero, Matiere.numero)
|
2022-01-20 13:00:25 +01:00
|
|
|
if in_use:
|
2022-01-27 11:44:58 +01:00
|
|
|
# restreint aux matières du même semestre
|
2022-05-01 23:58:41 +02:00
|
|
|
matieres = matieres.filter(UniteEns.semestre_idx == module.ue.semestre_idx)
|
2022-01-27 11:44:58 +01:00
|
|
|
|
|
|
|
if is_apc:
|
2022-02-18 19:36:51 +01:00
|
|
|
# ne conserve que la 1ere matière de chaque UE,
|
|
|
|
# et celle à laquelle ce module est rattaché
|
|
|
|
matieres = [
|
|
|
|
mat
|
|
|
|
for mat in matieres
|
2023-02-19 13:35:45 +01:00
|
|
|
if (module and module.matiere and (module.matiere.id == mat.id))
|
2022-05-01 23:58:41 +02:00
|
|
|
or (mat.id == mat.ue.matieres.first().id)
|
2022-02-18 19:36:51 +01:00
|
|
|
]
|
2024-10-14 16:40:05 +02:00
|
|
|
mat_names = [f"S{mat.ue.semestre_idx} / {mat.ue.acronyme}" for mat in matieres]
|
2022-01-20 13:00:25 +01:00
|
|
|
else:
|
2024-10-14 16:40:05 +02:00
|
|
|
mat_names = ["{mat.ue.acronyme} / {mat.titre or ''}" for mat in matieres]
|
2022-01-27 11:44:58 +01:00
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
if module: # edition
|
2024-10-14 16:40:05 +02:00
|
|
|
ue_mat_ids = [f"{mat.ue.id}!{mat.id}" for mat in matieres]
|
|
|
|
module_dict["ue_matiere_id"] = (
|
|
|
|
f"{module_dict['ue_id']}!{module_dict['matiere_id']}"
|
2022-05-01 23:58:41 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-09 17:47:06 +02:00
|
|
|
semestres_indices = list(range(1, parcours.NB_SEM + 1))
|
2022-05-29 17:31:29 +02:00
|
|
|
# Toutes les UEs de la formation (tout parcours):
|
2022-05-01 23:58:41 +02:00
|
|
|
ues = formation.ues.order_by(
|
|
|
|
UniteEns.semestre_idx, UniteEns.numero, UniteEns.acronyme
|
2022-10-30 22:42:10 +01:00
|
|
|
)
|
|
|
|
if is_apc and create and semestre_id is not None:
|
|
|
|
ues = ues.filter_by(semestre_idx=semestre_id)
|
2022-05-29 17:31:29 +02:00
|
|
|
# L'UE de rattachement par défaut: 1ere du semestre
|
|
|
|
ue_default = (
|
|
|
|
formation.ues.filter_by(semestre_idx=orig_semestre_idx)
|
|
|
|
.order_by(UniteEns.numero, UniteEns.acronyme)
|
|
|
|
.first()
|
|
|
|
)
|
2022-05-01 23:58:41 +02:00
|
|
|
|
|
|
|
# --- Titre de la page
|
|
|
|
if create:
|
|
|
|
if is_apc and module_type is not None:
|
|
|
|
object_name = scu.MODULE_TYPE_NAMES[module_type]
|
|
|
|
else:
|
|
|
|
object_name = "Module"
|
|
|
|
page_title = f"Création {object_name}"
|
|
|
|
if matiere_id:
|
|
|
|
title = f"""Création {object_name} dans la matière
|
|
|
|
{matiere.titre},
|
|
|
|
(UE {ue.acronyme}), semestre {ue.semestre_idx}
|
|
|
|
"""
|
|
|
|
else:
|
|
|
|
title = f"""Création {object_name} dans la formation
|
|
|
|
{formation.acronyme}"""
|
|
|
|
else:
|
2022-05-26 03:55:03 +02:00
|
|
|
page_title = f"Modification du module {module.code or module.titre or ''}"
|
2022-05-01 23:58:41 +02:00
|
|
|
title = f"""Modification du module {module.code or ''} {module.titre or ''}
|
|
|
|
(formation {formation.acronyme}, version {formation.version})
|
|
|
|
"""
|
2021-12-11 18:37:13 +01:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
H = [
|
2022-05-01 23:58:41 +02:00
|
|
|
f"""<h2>{title}</h2>""",
|
2022-01-20 13:00:25 +01:00
|
|
|
render_template(
|
2023-01-30 22:25:17 +01:00
|
|
|
"scodoc/help/modules.j2",
|
2022-01-20 13:00:25 +01:00
|
|
|
is_apc=is_apc,
|
2022-05-01 23:58:41 +02:00
|
|
|
semestre_id=semestre_id,
|
2024-02-13 13:55:16 +01:00
|
|
|
formsemestres=(
|
|
|
|
FormSemestre.query.filter(
|
|
|
|
ModuleImpl.formsemestre_id == FormSemestre.id,
|
|
|
|
ModuleImpl.module_id == module_id,
|
|
|
|
)
|
|
|
|
.order_by(FormSemestre.date_debut)
|
|
|
|
.all()
|
|
|
|
if not create
|
|
|
|
else None
|
|
|
|
),
|
2023-01-30 22:25:17 +01:00
|
|
|
create=create,
|
2022-01-20 13:00:25 +01:00
|
|
|
),
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
if not unlocked:
|
|
|
|
H.append(
|
2022-05-02 11:13:56 +02:00
|
|
|
"""<div class="ue_warning"><span>Formation verrouillée, seuls
|
|
|
|
certains éléments peuvent être modifiés</span></div>"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2022-02-01 11:37:05 +01:00
|
|
|
if is_apc:
|
|
|
|
module_types = scu.ModuleType # tous les types
|
|
|
|
else:
|
|
|
|
# ne propose pas SAE et Ressources, sauf si déjà de ce type...
|
2022-05-01 23:58:41 +02:00
|
|
|
module_types = set(scu.ModuleType) - {
|
|
|
|
scu.ModuleType.RESSOURCE,
|
|
|
|
scu.ModuleType.SAE,
|
2022-02-26 20:35:34 +01:00
|
|
|
}
|
2022-05-01 23:58:41 +02:00
|
|
|
if module:
|
|
|
|
module_types |= {
|
2024-02-13 13:55:16 +01:00
|
|
|
(
|
|
|
|
scu.ModuleType(module.module_type)
|
|
|
|
if module.module_type
|
|
|
|
else scu.ModuleType.STANDARD
|
|
|
|
)
|
2022-05-01 23:58:41 +02:00
|
|
|
}
|
|
|
|
# Numéro du module
|
|
|
|
# cherche le numero adéquat (pour placer le module en fin de liste)
|
|
|
|
if module:
|
|
|
|
default_num = module.numero
|
|
|
|
else:
|
|
|
|
modules = formation.modules.all()
|
|
|
|
if modules:
|
2024-09-03 08:24:09 +02:00
|
|
|
default_num = max(m.numero or 0 for m in modules) + 10
|
2022-05-01 23:58:41 +02:00
|
|
|
else:
|
|
|
|
default_num = 10
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-11-13 12:09:30 +01:00
|
|
|
descr = [
|
2020-09-26 16:19:37 +02:00
|
|
|
(
|
2021-11-13 12:09:30 +01:00
|
|
|
"code",
|
|
|
|
{
|
|
|
|
"size": 10,
|
2022-05-02 11:13:56 +02:00
|
|
|
"explanation": """code du module (issu du programme, exemple M1203,
|
|
|
|
R2.01, ou SAÉ 3.4. Doit être unique dans la formation)""",
|
2021-11-13 12:09:30 +01:00
|
|
|
"allow_null": False,
|
2024-10-14 16:40:05 +02:00
|
|
|
"validator": lambda val, _, formation_id=formation.id: Module.check_module_code_unicity(
|
|
|
|
val, formation_id, module_id=module.id if module else None
|
2021-11-13 12:09:30 +01:00
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
2022-05-01 23:58:41 +02:00
|
|
|
(
|
|
|
|
"titre",
|
|
|
|
{
|
2024-04-06 12:33:07 +02:00
|
|
|
"size": 64,
|
2022-05-01 23:58:41 +02:00
|
|
|
"explanation": """nom du module. Exemple:
|
|
|
|
<em>Introduction à la démarche ergonomique</em>""",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"abbrev",
|
|
|
|
{
|
2024-04-06 12:33:07 +02:00
|
|
|
"size": 32,
|
|
|
|
"explanation": """(optionnel) nom abrégé pour bulletins.
|
2022-05-01 23:58:41 +02:00
|
|
|
Exemple: <em>Intro. à l'ergonomie</em>""",
|
|
|
|
},
|
|
|
|
),
|
2021-11-13 12:09:30 +01:00
|
|
|
(
|
|
|
|
"module_type",
|
|
|
|
{
|
|
|
|
"input_type": "menu",
|
|
|
|
"title": "Type",
|
|
|
|
"explanation": "",
|
2022-02-01 11:37:05 +01:00
|
|
|
"labels": [x.name.capitalize() for x in module_types],
|
|
|
|
"allowed_values": [str(int(x)) for x in module_types],
|
2021-11-13 12:09:30 +01:00
|
|
|
"enabled": unlocked,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"heures_cours",
|
2022-01-27 11:44:58 +01:00
|
|
|
{
|
2022-05-01 23:58:41 +02:00
|
|
|
"title": "Heures cours :",
|
2022-01-27 11:44:58 +01:00
|
|
|
"size": 4,
|
|
|
|
"type": "float",
|
2022-08-29 15:23:44 +02:00
|
|
|
"min_value": 0,
|
2022-05-01 23:58:41 +02:00
|
|
|
"explanation": "nombre d'heures de cours (optionnel)",
|
2022-01-27 11:44:58 +01:00
|
|
|
},
|
2021-11-13 12:09:30 +01:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"heures_td",
|
|
|
|
{
|
2022-05-01 23:58:41 +02:00
|
|
|
"title": "Heures de TD :",
|
2021-11-13 12:09:30 +01:00
|
|
|
"size": 4,
|
|
|
|
"type": "float",
|
2022-08-29 15:23:44 +02:00
|
|
|
"min_value": 0,
|
2022-05-01 23:58:41 +02:00
|
|
|
"explanation": "nombre d'heures de Travaux Dirigés (optionnel)",
|
2021-11-13 12:09:30 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"heures_tp",
|
|
|
|
{
|
2022-05-01 23:58:41 +02:00
|
|
|
"title": "Heures de TP :",
|
2021-11-13 12:09:30 +01:00
|
|
|
"size": 4,
|
|
|
|
"type": "float",
|
2022-08-29 15:23:44 +02:00
|
|
|
"min_value": 0,
|
2022-05-01 23:58:41 +02:00
|
|
|
"explanation": "nombre d'heures de Travaux Pratiques (optionnel)",
|
2021-11-13 12:09:30 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
if is_apc:
|
2022-05-01 23:58:41 +02:00
|
|
|
if module:
|
|
|
|
coefs_lst = module.ue_coefs_list()
|
|
|
|
if coefs_lst:
|
|
|
|
coefs_descr_txt = ", ".join(
|
|
|
|
[f"{ue.acronyme}: {c}" for (ue, c) in coefs_lst]
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
coefs_descr_txt = """<span class="missing_value">non définis</span>"""
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"ue_coefs",
|
|
|
|
{
|
|
|
|
"readonly": True,
|
|
|
|
"title": "Coefficients vers les UE ",
|
|
|
|
"default": coefs_descr_txt,
|
2022-05-02 11:13:56 +02:00
|
|
|
"explanation": """ <br>(passer par la page d'édition de la
|
|
|
|
formation pour modifier les coefficients)""",
|
2022-05-01 23:58:41 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
2021-11-13 12:09:30 +01:00
|
|
|
else:
|
2022-05-01 23:58:41 +02:00
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"sep_ue_coefs",
|
|
|
|
{
|
|
|
|
"input_type": "separator",
|
|
|
|
"title": """
|
|
|
|
<div>(<em>les coefficients vers les UE se fixent sur la page dédiée</em>)
|
|
|
|
</div>""",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
2021-11-13 12:09:30 +01:00
|
|
|
else: # Module classique avec coef scalaire:
|
|
|
|
descr += [
|
2020-09-26 16:19:37 +02:00
|
|
|
(
|
|
|
|
"coefficient",
|
|
|
|
{
|
|
|
|
"size": 4,
|
|
|
|
"type": "float",
|
|
|
|
"explanation": "coefficient dans la formation (PPN)",
|
|
|
|
"allow_null": False,
|
|
|
|
"enabled": unlocked,
|
|
|
|
},
|
|
|
|
),
|
2021-11-13 12:09:30 +01:00
|
|
|
]
|
|
|
|
descr += [
|
2021-12-08 21:49:13 +01:00
|
|
|
(
|
2022-05-01 23:58:41 +02:00
|
|
|
"formation_id",
|
2021-12-08 21:49:13 +01:00
|
|
|
{
|
2022-05-01 23:58:41 +02:00
|
|
|
"input_type": "hidden",
|
|
|
|
"default": formation.id,
|
2021-12-08 21:49:13 +01:00
|
|
|
},
|
|
|
|
),
|
2022-05-29 17:31:29 +02:00
|
|
|
(
|
|
|
|
"semestre_id",
|
|
|
|
{
|
|
|
|
"input_type": "hidden",
|
|
|
|
"default": orig_semestre_idx,
|
|
|
|
},
|
|
|
|
),
|
2021-11-17 10:28:51 +01:00
|
|
|
]
|
2022-05-01 23:58:41 +02:00
|
|
|
if module:
|
|
|
|
descr += [
|
|
|
|
("ue_id", {"input_type": "hidden"}),
|
|
|
|
("module_id", {"input_type": "hidden"}),
|
|
|
|
(
|
|
|
|
"ue_matiere_id",
|
|
|
|
{
|
|
|
|
"input_type": "menu",
|
|
|
|
"title": "Rattachement :" if is_apc else "Matière :",
|
|
|
|
"explanation": (
|
2024-02-13 13:55:16 +01:00
|
|
|
(
|
|
|
|
"UE de rattachement, utilisée notamment pour les malus"
|
|
|
|
+ (
|
|
|
|
" (module utilisé, ne peut pas être changé de semestre)"
|
|
|
|
if in_use
|
|
|
|
else ""
|
|
|
|
)
|
2022-05-01 23:58:41 +02:00
|
|
|
)
|
2024-02-13 13:55:16 +01:00
|
|
|
if is_apc
|
|
|
|
else "un module appartient à une seule matière."
|
|
|
|
),
|
2022-05-01 23:58:41 +02:00
|
|
|
"labels": mat_names,
|
|
|
|
"allowed_values": ue_mat_ids,
|
|
|
|
"enabled": unlocked,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
else: # Création
|
|
|
|
if matiere_id:
|
|
|
|
descr += [
|
|
|
|
("ue_id", {"default": ue.id, "input_type": "hidden"}),
|
|
|
|
("matiere_id", {"default": matiere_id, "input_type": "hidden"}),
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
# choix de l'UE de rattachement
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"ue_id",
|
|
|
|
{
|
|
|
|
"input_type": "menu",
|
|
|
|
"type": "int",
|
|
|
|
"title": "UE de rattachement",
|
|
|
|
"explanation": "utilisée notamment pour les malus",
|
|
|
|
"labels": [
|
2024-10-14 16:40:05 +02:00
|
|
|
f"""S{u.semestre_idx if u.semestre_idx is not None else '.'
|
|
|
|
} / {u.acronyme} {u.titre}"""
|
2022-05-01 23:58:41 +02:00
|
|
|
for u in ues
|
|
|
|
],
|
|
|
|
"allowed_values": [u.id for u in ues],
|
2022-05-29 17:31:29 +02:00
|
|
|
"default": ue_default.id if ue_default is not None else "",
|
2022-05-01 23:58:41 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
2021-11-17 10:28:51 +01:00
|
|
|
if is_apc:
|
|
|
|
# le semestre du module est toujours celui de son UE
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"semestre_id",
|
|
|
|
{
|
|
|
|
"input_type": "hidden",
|
|
|
|
"type": "int",
|
|
|
|
"readonly": True,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"semestre_id",
|
|
|
|
{
|
|
|
|
"input_type": "menu",
|
|
|
|
"type": "int",
|
|
|
|
"title": parcours.SESSION_NAME.capitalize(),
|
2024-10-14 16:40:05 +02:00
|
|
|
"explanation": f"""{parcours.SESSION_NAME
|
|
|
|
} de début du module dans la formation standard""",
|
2021-11-17 10:28:51 +01:00
|
|
|
"labels": [str(x) for x in semestres_indices],
|
|
|
|
"allowed_values": semestres_indices,
|
|
|
|
"enabled": unlocked,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
|
|
|
descr += [
|
2021-11-13 12:09:30 +01:00
|
|
|
(
|
|
|
|
"code_apogee",
|
|
|
|
{
|
|
|
|
"title": "Code Apogée",
|
|
|
|
"size": 25,
|
2022-05-22 03:26:39 +02:00
|
|
|
"explanation": """(optionnel) code élément pédagogique Apogée ou liste de codes ELP
|
2023-11-08 23:19:58 +01:00
|
|
|
séparés par des virgules (ce code est propre à chaque établissement, se rapprocher
|
2022-03-01 19:27:03 +01:00
|
|
|
du référent Apogée).
|
|
|
|
""",
|
2021-12-29 19:30:49 +01:00
|
|
|
"validator": lambda val, _: len(val) < APO_CODE_STR_LEN,
|
2021-11-13 12:09:30 +01:00
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"numero",
|
|
|
|
{
|
2023-01-30 22:25:17 +01:00
|
|
|
"title": "Numéro",
|
|
|
|
"size": 4,
|
2022-05-01 23:58:41 +02:00
|
|
|
"explanation": "numéro (1, 2, 3, 4, ...) pour ordre d'affichage",
|
2021-11-13 12:09:30 +01:00
|
|
|
"type": "int",
|
2022-05-01 23:58:41 +02:00
|
|
|
"default": default_num,
|
2024-02-14 21:45:58 +01:00
|
|
|
"allow_null": True,
|
2021-11-13 12:09:30 +01:00
|
|
|
},
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
2021-11-13 12:09:30 +01:00
|
|
|
]
|
2022-05-02 14:39:06 +02:00
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
if is_apc:
|
2022-05-02 14:39:06 +02:00
|
|
|
# Choix des parcours
|
2022-05-01 23:58:41 +02:00
|
|
|
ref_comp = formation.referentiel_competence
|
|
|
|
if ref_comp:
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"parcours",
|
|
|
|
{
|
|
|
|
"input_type": "checkbox",
|
|
|
|
"vertical": True,
|
2022-05-02 10:54:52 +02:00
|
|
|
"dom_id": "tf_module_parcours",
|
2024-02-22 17:22:56 +01:00
|
|
|
"labels": [
|
|
|
|
f" {parcour.libelle} (<b>{parcour.code}</b>)"
|
|
|
|
for parcour in ref_comp.parcours
|
|
|
|
]
|
|
|
|
+ [" Tous (tronc commun)"],
|
2022-05-01 23:58:41 +02:00
|
|
|
"allowed_values": [
|
|
|
|
str(parcour.id) for parcour in ref_comp.parcours
|
2022-05-22 03:26:39 +02:00
|
|
|
]
|
|
|
|
+ ["-1"],
|
2024-06-23 21:13:40 +02:00
|
|
|
"explanation": """Parcours dans lesquels est utilisé ce module (inutile
|
|
|
|
hors BUT, pour les modules standards et dans les UEs de bonus).
|
|
|
|
<br>
|
|
|
|
Attention: si le module ne doit pas avoir les mêmes coefficients suivant
|
|
|
|
le parcours, il faut en créer plusieurs versions, car dans ScoDoc chaque
|
|
|
|
module a ses coefficients.
|
|
|
|
""",
|
2022-05-01 23:58:41 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
|
|
|
if module:
|
|
|
|
module_dict["parcours"] = [
|
|
|
|
str(parcour.id) for parcour in module.parcours
|
|
|
|
]
|
2022-05-02 14:39:06 +02:00
|
|
|
module_dict["app_critiques"] = [
|
|
|
|
str(app_crit.id) for app_crit in module.app_critiques
|
|
|
|
]
|
|
|
|
# Choix des Apprentissages Critiques
|
|
|
|
if ue is not None:
|
2022-07-03 08:38:12 +02:00
|
|
|
annee = f"BUT{(orig_semestre_idx+1)//2}"
|
2022-05-02 14:39:06 +02:00
|
|
|
app_critiques = ApcAppCritique.app_critiques_ref_comp(ref_comp, annee)
|
2023-01-14 00:17:43 +01:00
|
|
|
if ue.niveau_competence is not None:
|
|
|
|
descr += [
|
2022-05-02 14:39:06 +02:00
|
|
|
(
|
|
|
|
"app_critiques",
|
|
|
|
{
|
|
|
|
"title": "Apprentissages Critiques",
|
|
|
|
"input_type": "checkbox",
|
|
|
|
"vertical": True,
|
|
|
|
"dom_id": "tf_module_app_critiques",
|
|
|
|
"labels": [
|
2022-05-22 03:26:39 +02:00
|
|
|
f"{app_crit.code} {app_crit.libelle}"
|
|
|
|
for app_crit in app_critiques
|
2022-05-02 14:39:06 +02:00
|
|
|
],
|
|
|
|
"allowed_values": [
|
|
|
|
str(app_crit.id) for app_crit in app_critiques
|
|
|
|
],
|
2022-05-22 03:26:39 +02:00
|
|
|
"html_data": [],
|
|
|
|
"explanation": """Apprentissages Critiques liés à ce module.
|
2023-01-14 00:17:43 +01:00
|
|
|
(si vous changez le semestre, revenez ensuite sur cette page
|
|
|
|
pour associer les AC.)
|
|
|
|
""",
|
2022-05-02 14:39:06 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
2023-01-14 00:17:43 +01:00
|
|
|
else:
|
2023-02-12 13:36:47 +01:00
|
|
|
if module.ue.type == codes_cursus.UE_STANDARD:
|
2023-01-14 00:17:43 +01:00
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"app_critiques",
|
|
|
|
{
|
|
|
|
"input_type": "separator",
|
|
|
|
"title": f"""<span class="fontred">{scu.EMO_WARNING }
|
|
|
|
L'UE <a class="stdlink" href="{
|
|
|
|
url_for("notes.ue_edit", scodoc_dept=g.scodoc_dept, ue_id=ue.id)
|
2024-02-13 13:55:16 +01:00
|
|
|
}">{ue.acronyme} {ue.titre or ''}</a>
|
2023-01-14 00:17:43 +01:00
|
|
|
n'est pas associée à un niveau de compétences
|
|
|
|
</span>""",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
2022-05-01 23:58:41 +02:00
|
|
|
else:
|
|
|
|
descr += [
|
|
|
|
(
|
|
|
|
"parcours",
|
|
|
|
{
|
|
|
|
"input_type": "separator",
|
2022-05-02 14:39:06 +02:00
|
|
|
"title": f"""<span class="fontred">{scu.EMO_WARNING }
|
|
|
|
Pas de parcours:
|
2023-11-08 23:19:58 +01:00
|
|
|
<a class="stdlink" href="{ url_for('notes.refcomp_assoc_formation',
|
2022-05-01 23:58:41 +02:00
|
|
|
scodoc_dept=g.scodoc_dept, formation_id=formation.id)
|
|
|
|
}">associer un référentiel de compétence</a>
|
|
|
|
</span>""",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
2021-11-17 10:28:51 +01:00
|
|
|
# force module semestre_idx to its UE
|
2022-05-01 23:58:41 +02:00
|
|
|
if module:
|
2023-02-17 20:40:57 +01:00
|
|
|
if (not module.ue) or (module.ue.semestre_idx is None):
|
2022-05-01 23:58:41 +02:00
|
|
|
# Filet de sécurité si jamais l'UE n'a pas non plus de semestre:
|
|
|
|
module_dict["semestre_id"] = 1
|
|
|
|
else:
|
|
|
|
module_dict["semestre_id"] = module.ue.semestre_idx
|
2024-10-11 14:06:02 +02:00
|
|
|
tags = module.tags if module else []
|
2021-11-13 12:09:30 +01:00
|
|
|
tf = TrivialFormulator(
|
|
|
|
request.base_url,
|
|
|
|
scu.get_request_args(),
|
|
|
|
descr,
|
2024-02-13 13:55:16 +01:00
|
|
|
html_foot_markup=(
|
2024-08-24 08:06:46 +02:00
|
|
|
f"""<div class="scobox sco_tag_module_edit"><span
|
2022-05-22 03:26:39 +02:00
|
|
|
class="sco_tag_edit"><textarea data-module_id="{module_id}" class="module_tag_editor"
|
2024-10-11 14:06:02 +02:00
|
|
|
>{
|
|
|
|
','.join(t.title for t in tags)
|
|
|
|
}</textarea></span></div>
|
2022-05-22 03:26:39 +02:00
|
|
|
"""
|
2024-02-13 13:55:16 +01:00
|
|
|
if not create
|
|
|
|
else ""
|
|
|
|
),
|
2022-05-01 23:58:41 +02:00
|
|
|
initvalues=module_dict if module else {},
|
|
|
|
submitlabel="Modifier ce module" if module else "Créer ce module",
|
|
|
|
cancelbutton="Annuler",
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2022-01-30 09:05:51 +01:00
|
|
|
#
|
2020-09-26 16:19:37 +02:00
|
|
|
if tf[0] == 0:
|
2024-08-24 08:06:46 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page_dept.j2",
|
|
|
|
title=page_title,
|
|
|
|
cssstyles=["libjs/jQuery-tagEditor/jquery.tag-editor.css"],
|
|
|
|
javascripts=[
|
|
|
|
"libjs/jQuery-tagEditor/jquery.tag-editor.min.js",
|
|
|
|
"libjs/jQuery-tagEditor/jquery.caret.min.js",
|
|
|
|
"js/module_tag_editor.js",
|
|
|
|
"js/module_edit.js",
|
|
|
|
],
|
|
|
|
content="\n".join(H)
|
2022-11-02 10:41:31 +01:00
|
|
|
+ tf[1]
|
2022-11-07 12:44:20 +01:00
|
|
|
+ (
|
|
|
|
f"""
|
2022-11-02 10:41:31 +01:00
|
|
|
<form action="module_clone" class="clone_form" method="post">
|
|
|
|
<input type="hidden" name="module_id" value="{module_id}">
|
|
|
|
<button type="submit">Créer une copie de ce module</button>
|
|
|
|
</form>
|
|
|
|
"""
|
2022-11-07 12:44:20 +01:00
|
|
|
if not create
|
|
|
|
else ""
|
2024-08-24 08:06:46 +02:00
|
|
|
),
|
2022-11-02 10:41:31 +01:00
|
|
|
)
|
2024-09-03 08:24:09 +02:00
|
|
|
if tf[0] == -1:
|
2021-12-11 18:37:13 +01:00
|
|
|
return flask.redirect(
|
|
|
|
url_for(
|
|
|
|
"notes.ue_table",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
2022-05-01 23:58:41 +02:00
|
|
|
formation_id=formation.id,
|
|
|
|
semestre_idx=orig_semestre_idx,
|
2021-12-11 18:37:13 +01:00
|
|
|
)
|
|
|
|
)
|
2024-09-03 08:24:09 +02:00
|
|
|
if isinstance(tf[2]["numero"], str):
|
|
|
|
tf[2]["numero"] = tf[2]["numero"].strip()
|
|
|
|
if not isinstance(tf[2]["numero"], int) and not tf[2]["numero"]:
|
|
|
|
tf[2]["numero"] = tf[2]["numero"] or default_num
|
|
|
|
# Les parcours sont affectés ensuite
|
|
|
|
form_parcours = tf[2].pop("parcours", [])
|
|
|
|
if create:
|
|
|
|
if not matiere_id:
|
|
|
|
# formulaire avec choix UE de rattachement
|
|
|
|
ue = db.session.get(UniteEns, tf[2]["ue_id"])
|
|
|
|
if ue is None:
|
|
|
|
raise ValueError("UE invalide")
|
|
|
|
matiere = ue.matieres.first()
|
|
|
|
if matiere:
|
|
|
|
tf[2]["matiere_id"] = matiere.id
|
2022-05-22 03:26:39 +02:00
|
|
|
else:
|
2024-10-11 14:06:02 +02:00
|
|
|
matiere = Matiere.create_from_dict(
|
|
|
|
{
|
|
|
|
"ue_id": ue.id,
|
|
|
|
"titre": ue.titre or "",
|
|
|
|
"numero": 1,
|
|
|
|
}
|
2024-09-03 08:24:09 +02:00
|
|
|
)
|
2024-10-11 14:06:02 +02:00
|
|
|
tf[2]["matiere_id"] = matiere.id
|
2024-09-03 08:24:09 +02:00
|
|
|
|
|
|
|
tf[2]["semestre_id"] = ue.semestre_idx
|
2024-10-14 16:40:05 +02:00
|
|
|
module = Module.create_from_dict(tf[2], news=True)
|
2024-09-03 08:24:09 +02:00
|
|
|
else: # EDITION MODULE
|
|
|
|
# l'UE de rattachement peut changer
|
|
|
|
tf[2]["ue_id"], tf[2]["matiere_id"] = tf[2]["ue_matiere_id"].split("!")
|
|
|
|
x, y = tf[2]["ue_matiere_id"].split("!")
|
|
|
|
tf[2]["ue_id"] = int(x)
|
|
|
|
tf[2]["matiere_id"] = int(y)
|
|
|
|
old_ue_id = module.ue.id
|
|
|
|
new_ue_id = tf[2]["ue_id"]
|
|
|
|
if (old_ue_id != new_ue_id) and in_use:
|
|
|
|
new_ue = UniteEns.query.get_or_404(new_ue_id)
|
|
|
|
if new_ue.semestre_idx != module.ue.semestre_idx:
|
|
|
|
# pas changer de semestre un module utilisé !
|
|
|
|
raise ScoValueError(
|
|
|
|
"Module utilisé: il ne peut pas être changé de semestre !"
|
|
|
|
)
|
2024-10-21 19:48:42 +02:00
|
|
|
if not tf[2].get("code"):
|
|
|
|
raise ScoValueError("Le code du module doit être spécifié.")
|
|
|
|
|
2024-09-03 08:24:09 +02:00
|
|
|
if is_apc:
|
2024-10-21 19:48:42 +02:00
|
|
|
# En APC, force le semestre égal à celui de l'UE
|
2024-09-03 08:24:09 +02:00
|
|
|
selected_ue = db.session.get(UniteEns, tf[2]["ue_id"])
|
|
|
|
if selected_ue is None:
|
|
|
|
raise ValueError("UE invalide")
|
|
|
|
tf[2]["semestre_id"] = selected_ue.semestre_idx
|
2024-10-21 19:48:42 +02:00
|
|
|
# Et vérifie que les AC sont bien dans ce ref. comp.
|
|
|
|
if "app_critiques" in tf[2]:
|
|
|
|
tf[2]["app_critiques"] = Module.convert_app_critiques(
|
|
|
|
tf[2]["app_critiques"], formation.referentiel_competence
|
|
|
|
)
|
|
|
|
|
2024-09-03 08:24:09 +02:00
|
|
|
# Check unicité code module dans la formation
|
|
|
|
# ??? TODO
|
|
|
|
#
|
|
|
|
do_module_edit(tf[2])
|
|
|
|
# Modifie les parcours
|
|
|
|
if form_parcours is not None and formation.referentiel_competence:
|
|
|
|
if "-1" in form_parcours: # "tous"
|
|
|
|
module.parcours = formation.referentiel_competence.parcours.all()
|
|
|
|
else:
|
|
|
|
module.parcours = [
|
|
|
|
db.session.get(ApcParcours, int(parcour_id_str))
|
|
|
|
for parcour_id_str in form_parcours
|
2022-05-02 14:39:06 +02:00
|
|
|
]
|
2024-09-03 08:24:09 +02:00
|
|
|
db.session.add(module)
|
|
|
|
db.session.commit()
|
2024-10-14 16:40:05 +02:00
|
|
|
module.formation.invalidate_cached_sems()
|
2024-09-03 08:24:09 +02:00
|
|
|
return flask.redirect(
|
|
|
|
url_for(
|
|
|
|
"notes.ue_table",
|
|
|
|
scodoc_dept=g.scodoc_dept,
|
|
|
|
formation_id=formation.id,
|
|
|
|
semestre_idx=tf[2]["semestre_id"] if is_apc else 1,
|
2021-12-11 18:37:13 +01:00
|
|
|
)
|
2024-09-03 08:24:09 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-10-16 19:20:36 +02:00
|
|
|
def module_table(formation_id):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Liste des modules de la formation
|
2024-10-14 16:40:05 +02:00
|
|
|
(affichage debug)
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2024-10-14 16:40:05 +02:00
|
|
|
formation = Formation.get_formation(formation_id)
|
|
|
|
editable = current_user.has_permission(Permission.EditFormation)
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
H = [
|
2024-10-14 16:40:05 +02:00
|
|
|
f"""<h2>Listes des modules dans la formation
|
|
|
|
{formation.titre} ({formation.acronyme} (debug)
|
|
|
|
</h2>
|
2023-02-18 00:13:00 +01:00
|
|
|
<ul class="notes_module_list">
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
|
|
|
|
2024-10-14 16:40:05 +02:00
|
|
|
for module in formation.modules:
|
|
|
|
m_dict = module.to_dict()
|
|
|
|
m_dict["parcours"] = [p.code for p in module.parcours]
|
|
|
|
str_module = str(m_dict).replace(",", ",\n")
|
|
|
|
H.append(
|
|
|
|
f'<li class="notes_module_list"><pre style="margin-bottom: 1px;">{str_module}</pre>'
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
if editable:
|
|
|
|
H.append(
|
2024-10-14 16:40:05 +02:00
|
|
|
f"""
|
|
|
|
<a class="stdlink" href="{
|
|
|
|
url_for('notes.module_edit', scodoc_dept=g.scodoc_dept, module_id=module.id)
|
|
|
|
}">modifier</a>
|
|
|
|
<a class="stdlink" href="{
|
|
|
|
url_for('notes.module_delete', scodoc_dept=g.scodoc_dept, module_id=module.id)
|
|
|
|
}">supprimer</a>
|
|
|
|
"""
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
H.append("</li>")
|
|
|
|
H.append("</ul>")
|
2024-08-24 08:06:46 +02:00
|
|
|
return render_template(
|
|
|
|
"sco_page_dept.j2",
|
|
|
|
title=f"Liste des modules de {formation.titre}",
|
|
|
|
content="\n".join(H),
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-06-26 22:45:53 +02:00
|
|
|
def formation_add_malus_modules(
|
|
|
|
formation_id: int, semestre_id: int = None, titre=None, redirect=True
|
|
|
|
):
|
2021-01-01 18:40:47 +01:00
|
|
|
"""Création d'un module de "malus" dans chaque UE d'une formation"""
|
2021-06-19 23:21:37 +02:00
|
|
|
|
2022-06-08 21:16:09 +02:00
|
|
|
formation = Formation.query.get_or_404(formation_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-06-26 22:45:53 +02:00
|
|
|
nb = 0
|
|
|
|
ues = formation.ues
|
|
|
|
if semestre_id is not None:
|
|
|
|
ues = ues.filter_by(semestre_idx=semestre_id)
|
|
|
|
for ue in ues:
|
2023-02-12 13:36:47 +01:00
|
|
|
if ue.type == codes_cursus.UE_STANDARD:
|
2024-10-14 16:40:05 +02:00
|
|
|
if ue_add_malus_module(ue, titre=titre) is not None:
|
2022-06-26 22:45:53 +02:00
|
|
|
nb += 1
|
|
|
|
|
|
|
|
flash(f"Modules de malus ajoutés dans {nb} UEs du S{semestre_id}")
|
2022-06-08 21:16:09 +02:00
|
|
|
|
|
|
|
formation.invalidate_cached_sems()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
if redirect:
|
2021-10-21 06:32:03 +02:00
|
|
|
return flask.redirect(
|
|
|
|
url_for(
|
|
|
|
"notes.ue_table", scodoc_dept=g.scodoc_dept, formation_id=formation_id
|
|
|
|
)
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2022-06-08 21:16:09 +02:00
|
|
|
def ue_add_malus_module(ue: UniteEns, titre=None, code=None) -> int:
|
|
|
|
"""Add a malus module in this ue.
|
|
|
|
If already exists, do nothing.
|
|
|
|
Returns id of malus module.
|
|
|
|
"""
|
|
|
|
modules_malus = [m for m in ue.modules if m.module_type == scu.ModuleType.MALUS]
|
|
|
|
if len(modules_malus) > 0:
|
2022-06-26 22:45:53 +02:00
|
|
|
return None # déjà existant
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-06-26 22:45:53 +02:00
|
|
|
titre = titre or f"Malus {ue.acronyme}"
|
2022-06-08 21:16:09 +02:00
|
|
|
code = code or f"MALUS{ue.numero}"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Tout module doit avoir un semestre_id (indice 1, 2, ...)
|
2022-06-08 21:16:09 +02:00
|
|
|
if ue.semestre_idx is None:
|
|
|
|
semestre_ids = sorted(list(set([m.semestre_id for m in ue.modules])))
|
|
|
|
if len(semestre_ids) > 0:
|
|
|
|
semestre_id = semestre_ids[0]
|
|
|
|
else:
|
|
|
|
# c'est ennuyeux: dans ce cas, on pourrait demander à indiquer explicitement
|
|
|
|
# le semestre ? ou affecter le malus au semestre 1 ???
|
|
|
|
raise ScoValueError(
|
2024-10-14 16:40:05 +02:00
|
|
|
"""Impossible d'ajouter un malus si l'UE n'a pas de numéro de semestre
|
|
|
|
et ne comporte pas d'autres modules"""
|
2022-06-08 21:16:09 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2022-06-08 21:16:09 +02:00
|
|
|
semestre_id = ue.semestre_idx
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
# Matiere pour placer le module malus
|
2022-06-08 21:16:09 +02:00
|
|
|
titre_matiere_malus = "Malus"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-06-08 21:16:09 +02:00
|
|
|
matieres_malus = [mat for mat in ue.matieres if mat.titre == titre_matiere_malus]
|
|
|
|
if len(matieres_malus) > 0:
|
|
|
|
# matière Malus déjà existante, l'utilise
|
|
|
|
matiere = matieres_malus[0]
|
|
|
|
else:
|
|
|
|
if ue.matieres.count() > 0:
|
2022-06-27 09:32:26 +02:00
|
|
|
numero = max([(mat.numero or 0) for mat in ue.matieres]) + 10
|
2022-06-08 21:16:09 +02:00
|
|
|
else:
|
|
|
|
numero = 0
|
|
|
|
matiere = Matiere(ue_id=ue.id, titre=titre_matiere_malus, numero=numero)
|
|
|
|
db.session.add(matiere)
|
|
|
|
|
|
|
|
module = Module(
|
|
|
|
titre=titre,
|
|
|
|
code=code,
|
|
|
|
coefficient=0.0,
|
|
|
|
ue=ue,
|
|
|
|
matiere=matiere,
|
|
|
|
formation=ue.formation,
|
|
|
|
semestre_id=semestre_id,
|
|
|
|
module_type=scu.ModuleType.MALUS,
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
2022-06-08 21:16:09 +02:00
|
|
|
db.session.add(module)
|
|
|
|
db.session.commit()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-06-08 21:16:09 +02:00
|
|
|
return module.id
|