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
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
from app import db, log
|
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-04-12 17:12:51 +02:00
|
|
|
from app.models import ScolarNews
|
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.notesdb as ndb
|
|
|
|
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,
|
|
|
|
ScoLockedFormError,
|
|
|
|
ScoGenError,
|
|
|
|
ScoNonEmptyFormationObject,
|
|
|
|
)
|
2023-02-12 13:36:47 +01:00
|
|
|
from app.scodoc import codes_cursus
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_edit_matiere
|
|
|
|
from app.scodoc import sco_moduleimpl
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-06-16 18:18:32 +02:00
|
|
|
_moduleEditor = ndb.EditableTable(
|
|
|
|
"notes_modules",
|
|
|
|
"module_id",
|
|
|
|
(
|
|
|
|
"module_id",
|
|
|
|
"titre",
|
|
|
|
"code",
|
|
|
|
"abbrev",
|
|
|
|
"heures_cours",
|
|
|
|
"heures_td",
|
|
|
|
"heures_tp",
|
|
|
|
"coefficient",
|
|
|
|
"ue_id",
|
|
|
|
"matiere_id",
|
|
|
|
"formation_id",
|
|
|
|
"semestre_id",
|
|
|
|
"numero",
|
|
|
|
"code_apogee",
|
2023-11-08 23:19:58 +01:00
|
|
|
"module_type",
|
|
|
|
"edt_id",
|
2021-06-16 18:18:32 +02:00
|
|
|
#'ects'
|
|
|
|
),
|
|
|
|
sortkey="numero, code, titre",
|
|
|
|
output_formators={
|
|
|
|
"heures_cours": ndb.float_null_is_zero,
|
|
|
|
"heures_td": ndb.float_null_is_zero,
|
|
|
|
"heures_tp": ndb.float_null_is_zero,
|
|
|
|
"numero": ndb.int_null_is_zero,
|
|
|
|
"coefficient": ndb.float_null_is_zero,
|
2024-02-13 13:55:16 +01:00
|
|
|
"module_type": ndb.int_null_is_zero,
|
2021-06-16 18:18:32 +02:00
|
|
|
#'ects' : ndb.float_null_is_null
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-10-16 19:20:36 +02:00
|
|
|
def module_list(*args, **kw):
|
2021-06-16 18:18:32 +02:00
|
|
|
"list modules"
|
|
|
|
cnx = ndb.GetDBConnexion()
|
|
|
|
return _moduleEditor.list(cnx, *args, **kw)
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_module_create(args) -> int:
|
2021-12-10 15:51:43 +01:00
|
|
|
"Create a module. Returns id of new object."
|
2023-07-11 06:57:38 +02:00
|
|
|
formation = db.session.get(Formation, args["formation_id"])
|
2022-09-08 01:20:04 +02:00
|
|
|
# refuse de créer un module APC avec semestres incohérents:
|
|
|
|
if formation.is_apc():
|
2023-07-11 06:57:38 +02:00
|
|
|
ue = db.session.get(UniteEns, args["ue_id"])
|
2022-09-08 01:20:04 +02:00
|
|
|
if int(args.get("semestre_id", 0)) != ue.semestre_idx:
|
2022-09-13 10:50:13 +02:00
|
|
|
raise ScoValueError("Formation incompatible: contacter le support ScoDoc")
|
2021-06-16 18:18:32 +02:00
|
|
|
# create
|
2024-02-14 21:45:58 +01:00
|
|
|
module = Module.create_from_dict(args)
|
|
|
|
db.session.commit()
|
|
|
|
log(f"do_module_create: created {module.id} with {args}")
|
2021-06-16 18:18:32 +02:00
|
|
|
|
|
|
|
# news
|
2022-04-12 17:12:51 +02:00
|
|
|
ScolarNews.add(
|
|
|
|
typ=ScolarNews.NEWS_FORM,
|
|
|
|
obj=formation.id,
|
2022-02-14 18:33:36 +01:00
|
|
|
text=f"Modification de la formation {formation.acronyme}",
|
2021-06-16 18:18:32 +02:00
|
|
|
)
|
2022-02-14 18:33:36 +01:00
|
|
|
formation.invalidate_cached_sems()
|
2024-02-14 21:45:58 +01:00
|
|
|
return module.id
|
2021-06-16 18:18:32 +02:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-02-01 11:37:05 +01: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).
|
|
|
|
"""
|
2022-05-01 23:58:41 +02:00
|
|
|
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-01-04 20:03:38 +01:00
|
|
|
def can_delete_module(module):
|
|
|
|
"True si le module n'est pas utilisée dans des formsemestre"
|
|
|
|
return len(module.modimpls.all()) == 0
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def do_module_delete(oid):
|
2021-06-16 18:18:32 +02:00
|
|
|
"delete module"
|
2022-01-04 20:03:38 +01:00
|
|
|
module = Module.query.get_or_404(oid)
|
|
|
|
mod = module_list({"module_id": oid})[0] # sco7
|
|
|
|
if module_is_locked(module.id):
|
2021-06-16 18:18:32 +02:00
|
|
|
raise ScoLockedFormError()
|
2022-01-04 20:03:38 +01:00
|
|
|
if not can_delete_module(module):
|
|
|
|
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,
|
|
|
|
),
|
|
|
|
)
|
2021-06-16 18:18:32 +02:00
|
|
|
|
|
|
|
# S'il y a des moduleimpls, on ne peut pas detruire le module !
|
2021-10-15 14:00:51 +02:00
|
|
|
mods = sco_moduleimpl.moduleimpl_list(module_id=oid)
|
2021-06-16 18:18:32 +02:00
|
|
|
if mods:
|
2022-05-02 11:13:56 +02:00
|
|
|
err_page = f"""
|
|
|
|
<h3>Destruction du module impossible car il est utilisé dans des
|
|
|
|
semestres existants !</h3>
|
|
|
|
<p class="help">Il faut d'abord supprimer le semestre (ou en retirer
|
|
|
|
ce module).
|
|
|
|
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.
|
2021-09-21 14:01:46 +02:00
|
|
|
</p>
|
2023-11-08 23:19:58 +01:00
|
|
|
<a href="{url_for('notes.ue_table', scodoc_dept=g.scodoc_dept,
|
2021-09-21 14:01:46 +02:00
|
|
|
formation_id=mod["formation_id"])}">reprendre</a>
|
|
|
|
"""
|
2021-06-16 18:18:32 +02:00
|
|
|
raise ScoGenError(err_page)
|
|
|
|
# delete
|
|
|
|
cnx = ndb.GetDBConnexion()
|
|
|
|
_moduleEditor.delete(cnx, oid)
|
|
|
|
|
|
|
|
# news
|
2022-02-14 18:33:36 +01:00
|
|
|
formation = module.formation
|
2022-04-12 17:12:51 +02:00
|
|
|
ScolarNews.add(
|
|
|
|
typ=ScolarNews.NEWS_FORM,
|
|
|
|
obj=mod["formation_id"],
|
2022-02-14 18:33:36 +01:00
|
|
|
text=f"Modification de la formation {formation.acronyme}",
|
2021-06-16 18:18:32 +02:00
|
|
|
)
|
2022-02-14 18:33:36 +01:00
|
|
|
formation.invalidate_cached_sems()
|
2021-06-16 18:18:32 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def module_delete(module_id=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Delete a module"""
|
2022-01-04 20:03:38 +01:00
|
|
|
module = Module.query.get_or_404(module_id)
|
|
|
|
mod = module_list(args={"module_id": module_id})[0] # sco7
|
|
|
|
|
|
|
|
if not can_delete_module(module):
|
|
|
|
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"}),),
|
2021-10-22 23:09:15 +02:00
|
|
|
initvalues=mod,
|
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],
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
elif tf[0] == -1:
|
2021-07-31 18:01:10 +02:00
|
|
|
return flask.redirect(dest_url)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2021-08-20 01:09:55 +02:00
|
|
|
do_module_delete(module_id)
|
2021-07-31 18:01:10 +02:00
|
|
|
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
|
2021-12-29 19:30:49 +01:00
|
|
|
mod = module_list({"module_id": vals["module_id"]})[0]
|
2021-08-20 01:09:55 +02:00
|
|
|
if module_is_locked(mod["module_id"]):
|
2021-06-16 18:18:32 +02:00
|
|
|
# formation verrouillée: empeche de modifier certains champs:
|
2022-07-11 21:39:08 +02:00
|
|
|
vals = vals.copy()
|
2021-06-16 18:18:32 +02:00
|
|
|
protected_fields = ("coefficient", "ue_id", "matiere_id", "semestre_id")
|
|
|
|
for f in protected_fields:
|
2021-12-29 19:30:49 +01:00
|
|
|
if f in vals:
|
|
|
|
del vals[f]
|
2021-06-16 18:18:32 +02:00
|
|
|
# edit
|
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-12-29 19:30:49 +01:00
|
|
|
_moduleEditor.edit(cnx, vals)
|
2023-07-11 06:57:38 +02:00
|
|
|
db.session.get(Formation, mod["formation_id"]).invalidate_cached_sems()
|
2021-06-16 18:18:32 +02:00
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def check_module_code_unicity(code, field, formation_id, module_id=None):
|
2020-09-26 16:19:37 +02:00
|
|
|
"true si code module unique dans la formation"
|
2022-05-02 11:13:56 +02:00
|
|
|
modules = module_list(args={"code": code, "formation_id": formation_id})
|
2020-09-26 16:19:37 +02:00
|
|
|
if module_id: # edition: supprime le module en cours
|
2022-05-02 11:13:56 +02:00
|
|
|
modules = [m for m in modules if m["module_id"] != module_id]
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-05-02 11:13:56 +02:00
|
|
|
return len(modules) == 0
|
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).
|
|
|
|
"""
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_tag_module
|
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
# --- 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:
|
|
|
|
matiere = Matiere.query.get_or_404(matiere_id)
|
|
|
|
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
|
|
|
|
unlocked = not module_is_locked(module_id)
|
|
|
|
|
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
|
|
|
]
|
2022-01-27 11:44:58 +01:00
|
|
|
mat_names = [
|
|
|
|
"S%s / %s" % (mat.ue.semestre_idx, mat.ue.acronyme) for mat in matieres
|
|
|
|
]
|
2022-01-20 13:00:25 +01:00
|
|
|
else:
|
2022-01-27 11:44:58 +01:00
|
|
|
mat_names = ["%s / %s" % (mat.ue.acronyme, mat.titre or "") for mat in matieres]
|
|
|
|
|
2022-05-01 23:58:41 +02:00
|
|
|
if module: # edition
|
|
|
|
ue_mat_ids = ["%s!%s" % (mat.ue.id, mat.id) for mat in matieres]
|
|
|
|
module_dict["ue_matiere_id"] = "%s!%s" % (
|
|
|
|
module_dict["ue_id"],
|
|
|
|
module_dict["matiere_id"],
|
|
|
|
)
|
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,
|
2022-05-01 23:58:41 +02:00
|
|
|
"validator": lambda val, field, formation_id=formation.id: check_module_code_unicity(
|
|
|
|
val, field, 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": [
|
|
|
|
f"S{u.semestre_idx if u.semestre_idx is not None else '.'} / {u.acronyme} {u.titre}"
|
|
|
|
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(),
|
2022-05-22 03:26:39 +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
|
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"
|
|
|
|
>{','.join(sco_tag_module.module_tag_list(module_id))}</textarea></span></div>
|
|
|
|
"""
|
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-09-03 08:24:09 +02:00
|
|
|
matiere_id = sco_edit_matiere.do_matiere_create(
|
|
|
|
{"ue_id": ue.id, "titre": ue.titre or "", "numero": 1},
|
|
|
|
)
|
|
|
|
tf[2]["matiere_id"] = matiere_id
|
|
|
|
|
|
|
|
tf[2]["semestre_id"] = ue.semestre_idx
|
|
|
|
module_id = do_module_create(tf[2])
|
|
|
|
module = db.session.get(Module, module_id)
|
|
|
|
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 !"
|
|
|
|
)
|
|
|
|
# En APC, force le semestre égal à celui de l'UE
|
|
|
|
if is_apc:
|
|
|
|
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
|
|
|
|
if not tf[2].get("code"):
|
|
|
|
raise ScoValueError("Le code du module doit être spécifié.")
|
|
|
|
# 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
|
|
|
# Modifie les AC
|
|
|
|
if "app_critiques" in tf[2]:
|
|
|
|
module.app_critiques = [
|
|
|
|
db.session.get(ApcAppCritique, int(ac_id_str))
|
|
|
|
for ac_id_str in tf[2]["app_critiques"]
|
|
|
|
]
|
|
|
|
db.session.add(module)
|
|
|
|
db.session.commit()
|
|
|
|
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
|
|
|
|
(XXX inutile ou a revoir)
|
|
|
|
"""
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import sco_formations
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
if not formation_id:
|
|
|
|
raise ScoValueError("invalid formation !")
|
2023-02-18 00:13:00 +01:00
|
|
|
formation: Formation = Formation.query.get_or_404(formation_id)
|
2020-09-26 16:19:37 +02:00
|
|
|
H = [
|
2023-02-18 00:13:00 +01:00
|
|
|
f"""<h2>Listes des modules dans la formation {formation.titre} ({formation.acronyme}</h2>
|
|
|
|
<ul class="notes_module_list">
|
|
|
|
""",
|
2020-09-26 16:19:37 +02:00
|
|
|
]
|
2023-09-29 21:17:31 +02:00
|
|
|
editable = current_user.has_permission(Permission.EditFormation)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-02-18 00:13:00 +01:00
|
|
|
for module_dict in module_list(args={"formation_id": formation_id}):
|
|
|
|
H.append('<li class="notes_module_list">%s' % module_dict)
|
2020-09-26 16:19:37 +02:00
|
|
|
if editable:
|
|
|
|
H.append(
|
2023-02-18 00:13:00 +01:00
|
|
|
'<a href="module_edit?module_id=%(module_id)s">modifier</a>'
|
|
|
|
% module_dict
|
|
|
|
)
|
|
|
|
H.append(
|
|
|
|
'<a href="module_delete?module_id=%(module_id)s">supprimer</a>'
|
|
|
|
% module_dict
|
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
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def module_is_locked(module_id):
|
2021-06-13 18:29:53 +02:00
|
|
|
"""True if module should not be modified
|
|
|
|
(used in a locked formsemestre)
|
|
|
|
"""
|
|
|
|
r = ndb.SimpleDictFetch(
|
2021-08-08 17:38:46 +02:00
|
|
|
"""SELECT mi.id
|
|
|
|
FROM notes_modules mod, notes_formsemestre sem, notes_moduleimpl mi
|
|
|
|
WHERE mi.module_id = mod.id
|
|
|
|
AND mi.formsemestre_id = sem.id
|
|
|
|
AND mi.module_id = %(module_id)s
|
|
|
|
AND sem.etat = false
|
2021-06-13 18:29:53 +02:00
|
|
|
""",
|
|
|
|
{"module_id": module_id},
|
|
|
|
)
|
|
|
|
return len(r) > 0
|
|
|
|
|
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
def module_count_moduleimpls(module_id):
|
2021-06-13 18:29:53 +02:00
|
|
|
"Number of moduleimpls using this module"
|
2021-10-15 14:00:51 +02:00
|
|
|
mods = sco_moduleimpl.moduleimpl_list(module_id=module_id)
|
2021-06-13 18:29:53 +02:00
|
|
|
return len(mods)
|
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:
|
2022-06-26 22:45:53 +02:00
|
|
|
if ue_add_malus_module(ue, titre=titre) != None:
|
|
|
|
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(
|
2022-06-26 22:45:53 +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
|