2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2022-01-01 14:49:42 +01:00
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
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,
|
|
|
|
)
|
2021-06-19 23:21:37 +02:00
|
|
|
from app.scodoc import html_sco_header
|
|
|
|
from app.scodoc import sco_codes_parcours
|
|
|
|
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",
|
|
|
|
"module_type"
|
|
|
|
#'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,
|
|
|
|
"module_type": ndb.int_null_is_zero
|
|
|
|
#'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."
|
2021-06-16 18:18:32 +02:00
|
|
|
# create
|
|
|
|
cnx = ndb.GetDBConnexion()
|
|
|
|
r = _moduleEditor.create(cnx, args)
|
|
|
|
|
|
|
|
# news
|
2022-02-14 18:33:36 +01:00
|
|
|
formation = Formation.query.get(args["formation_id"])
|
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}",
|
2022-04-13 00:32:31 +02:00
|
|
|
max_frequency=10 * 60,
|
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
|
|
|
return r
|
|
|
|
|
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>
|
2021-10-17 23:19:26 +02: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}",
|
2022-04-13 00:32:31 +02:00
|
|
|
max_frequency=10 * 60,
|
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 = [
|
2021-07-29 16:31:15 +02:00
|
|
|
html_sco_header.sco_header(page_title="Suppression d'un module"),
|
2022-06-08 21:16:09 +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:
|
2021-07-29 10:19:00 +02:00
|
|
|
return "\n".join(H) + tf[1] + html_sco_header.sco_footer()
|
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:
|
|
|
|
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)
|
2021-12-16 16:27:35 +01:00
|
|
|
Formation.query.get(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)
|
|
|
|
|
|
|
|
parcours = sco_codes_parcours.get_parcours_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
|
2022-05-01 23:58:41 +02:00
|
|
|
if ((module is not None) and (module.matiere.id == mat.id))
|
|
|
|
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
|
|
|
|
).all()
|
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 = [
|
2021-06-13 18:29:53 +02:00
|
|
|
html_sco_header.sco_header(
|
2022-05-01 23:58:41 +02:00
|
|
|
page_title=page_title,
|
2020-09-26 16:19:37 +02:00
|
|
|
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",
|
2022-05-22 03:26:39 +02:00
|
|
|
"js/module_edit.js",
|
2020-09-26 16:19:37 +02:00
|
|
|
],
|
|
|
|
),
|
2022-05-01 23:58:41 +02:00
|
|
|
f"""<h2>{title}</h2>""",
|
2022-01-20 13:00:25 +01:00
|
|
|
render_template(
|
|
|
|
"scodoc/help/modules.html",
|
|
|
|
is_apc=is_apc,
|
2022-05-01 23:58:41 +02:00
|
|
|
semestre_id=semestre_id,
|
2022-01-20 13:00:25 +01:00
|
|
|
formsemestres=FormSemestre.query.filter(
|
|
|
|
ModuleImpl.formsemestre_id == FormSemestre.id,
|
|
|
|
ModuleImpl.module_id == module_id,
|
2022-02-02 21:13:39 +01:00
|
|
|
)
|
|
|
|
.order_by(FormSemestre.date_debut)
|
2022-05-01 23:58:41 +02:00
|
|
|
.all()
|
|
|
|
if not create
|
|
|
|
else None,
|
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 |= {
|
|
|
|
scu.ModuleType(module.module_type)
|
|
|
|
if module.module_type
|
|
|
|
else scu.ModuleType.STANDARD
|
|
|
|
}
|
|
|
|
# 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:
|
|
|
|
default_num = max([m.numero or 0 for m in modules]) + 10
|
|
|
|
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",
|
|
|
|
{
|
|
|
|
"size": 30,
|
|
|
|
"explanation": """nom du module. Exemple:
|
|
|
|
<em>Introduction à la démarche ergonomique</em>""",
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"abbrev",
|
|
|
|
{
|
|
|
|
"size": 20,
|
|
|
|
"explanation": """nom abrégé (pour bulletins).
|
|
|
|
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-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-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-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": (
|
|
|
|
"UE de rattachement, utilisée notamment pour les malus"
|
|
|
|
+ (
|
|
|
|
" (module utilisé, ne peut pas être changé de semestre)"
|
|
|
|
if in_use
|
|
|
|
else ""
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if is_apc
|
|
|
|
else "un module appartient à une seule matière.",
|
|
|
|
"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
|
2022-03-01 19:27:03 +01:00
|
|
|
séparés par des virgules (ce code est propre à chaque établissement, se rapprocher
|
|
|
|
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",
|
|
|
|
{
|
|
|
|
"size": 2,
|
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,
|
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",
|
2022-05-22 03:26:39 +02:00
|
|
|
"labels": [parcour.libelle 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"],
|
|
|
|
"explanation": """Parcours dans lesquels est utilisé ce module.<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:
|
|
|
|
annee = f"BUT{orig_semestre_idx//2 + 1}"
|
|
|
|
app_critiques = ApcAppCritique.app_critiques_ref_comp(ref_comp, annee)
|
|
|
|
descr += (
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"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.
|
|
|
|
(si vous changez le semestre, revenez ensuite sur cette page
|
|
|
|
pour associer les AC.)
|
|
|
|
""",
|
2022-05-02 14:39:06 +02:00
|
|
|
},
|
|
|
|
)
|
|
|
|
]
|
|
|
|
if (ue.niveau_competence is not None)
|
|
|
|
else [
|
|
|
|
(
|
|
|
|
"app_critiques",
|
|
|
|
{
|
|
|
|
"input_type": "separator",
|
|
|
|
"title": f"""<span class="fontred">{scu.EMO_WARNING }
|
2022-05-22 03:26:39 +02:00
|
|
|
L'UE <a class="stdlink" href="{
|
|
|
|
url_for("notes.ue_edit", scodoc_dept=g.scodoc_dept, ue_id=ue.id)
|
|
|
|
}">{ue.acronyme} {ue.titre}</a>
|
2022-05-02 14:39:06 +02: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:
|
2022-05-01 23:58:41 +02:00
|
|
|
<a class="stdlink" href="{ url_for('notes.refcomp_assoc_formation',
|
|
|
|
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:
|
|
|
|
if module.ue.semestre_idx is None:
|
|
|
|
# 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,
|
2022-05-22 03:26:39 +02:00
|
|
|
html_foot_markup=f"""<div class="sco_tag_module_edit"><span
|
|
|
|
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>
|
|
|
|
"""
|
2022-05-02 10:54:52 +02: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:
|
2022-02-02 21:13:39 +01:00
|
|
|
return "\n".join(H) + tf[1] + html_sco_header.sco_footer()
|
2020-09-26 16:19:37 +02:00
|
|
|
elif 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
|
|
|
)
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2022-05-01 23:58:41 +02:00
|
|
|
if create:
|
|
|
|
if not matiere_id:
|
|
|
|
# formulaire avec choix UE de rattachement
|
|
|
|
ue = UniteEns.query.get(tf[2]["ue_id"])
|
|
|
|
if ue is None:
|
|
|
|
raise ValueError("UE invalide")
|
|
|
|
matiere = ue.matieres.first()
|
|
|
|
if matiere:
|
|
|
|
tf[2]["matiere_id"] = matiere.id
|
|
|
|
else:
|
|
|
|
matiere_id = sco_edit_matiere.do_matiere_create(
|
|
|
|
{"ue_id": ue.id, "titre": ue.titre, "numero": 1},
|
|
|
|
)
|
|
|
|
tf[2]["matiere_id"] = matiere_id
|
|
|
|
|
|
|
|
tf[2]["semestre_id"] = ue.semestre_idx
|
|
|
|
module_id = do_module_create(tf[2])
|
|
|
|
module = Module.query.get(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 = UniteEns.query.get(tf[2]["ue_id"])
|
|
|
|
if selected_ue is None:
|
|
|
|
raise ValueError("UE invalide")
|
|
|
|
tf[2]["semestre_id"] = selected_ue.semestre_idx
|
|
|
|
# Check unicité code module dans la formation
|
|
|
|
# ??? TODO
|
|
|
|
#
|
|
|
|
do_module_edit(tf[2])
|
|
|
|
# Modifie les parcours
|
2022-05-22 03:26:39 +02:00
|
|
|
if ("parcours" in tf[2]) and formation.referentiel_competence:
|
|
|
|
if "-1" in tf[2]["parcours"]: # "tous"
|
|
|
|
module.parcours = formation.referentiel_competence.parcours.all()
|
|
|
|
else:
|
|
|
|
module.parcours = [
|
|
|
|
ApcParcours.query.get(int(parcour_id_str))
|
|
|
|
for parcour_id_str in tf[2]["parcours"]
|
|
|
|
]
|
2022-05-02 14:39:06 +02:00
|
|
|
# Modifie les AC
|
|
|
|
if "app_critiques" in tf[2]:
|
|
|
|
module.app_critiques = [
|
|
|
|
ApcAppCritique.query.get(int(ac_id_str))
|
|
|
|
for ac_id_str in tf[2]["app_critiques"]
|
|
|
|
]
|
2022-05-01 23:58:41 +02:00
|
|
|
db.session.add(module)
|
|
|
|
db.session.commit()
|
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,
|
2022-05-22 03:26:39 +02:00
|
|
|
semestre_idx=tf[2]["semestre_id"] if is_apc else 1,
|
2021-12-11 18:37:13 +01:00
|
|
|
)
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Edition en ligne du code Apogee
|
2021-09-27 10:20:10 +02:00
|
|
|
def edit_module_set_code_apogee(id=None, value=None):
|
2021-06-24 23:09:06 +02:00
|
|
|
"Set UE code apogee"
|
2020-09-26 16:19:37 +02:00
|
|
|
module_id = id
|
2021-11-17 10:28:51 +01:00
|
|
|
value = str(value).strip("-_ \t")
|
2020-09-26 16:19:37 +02:00
|
|
|
log("edit_module_set_code_apogee: module_id=%s code_apogee=%s" % (module_id, value))
|
|
|
|
|
2021-10-16 19:20:36 +02:00
|
|
|
modules = module_list(args={"module_id": module_id})
|
2020-09-26 16:19:37 +02:00
|
|
|
if not modules:
|
2021-06-24 23:09:06 +02:00
|
|
|
return "module invalide" # should not occur
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-08-20 01:09:55 +02:00
|
|
|
do_module_edit({"module_id": module_id, "code_apogee": value})
|
2020-09-26 16:19:37 +02:00
|
|
|
if not value:
|
2021-02-04 20:02:44 +01:00
|
|
|
value = scu.APO_MISSING_CODE_STR
|
2020-09-26 16:19:37 +02:00
|
|
|
return value
|
|
|
|
|
|
|
|
|
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 !")
|
2021-08-19 10:28:35 +02:00
|
|
|
F = sco_formations.formation_list(args={"formation_id": formation_id})[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
H = [
|
2021-07-29 16:31:15 +02:00
|
|
|
html_sco_header.sco_header(page_title="Liste des modules de %(titre)s" % F),
|
2020-09-26 16:19:37 +02:00
|
|
|
"""<h2>Listes des modules dans la formation %(titre)s (%(acronyme)s)</h2>"""
|
|
|
|
% F,
|
|
|
|
'<ul class="notes_module_list">',
|
|
|
|
]
|
2021-09-18 13:42:19 +02:00
|
|
|
editable = current_user.has_permission(Permission.ScoChangeFormation)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-10-16 19:20:36 +02:00
|
|
|
for Mod in module_list(args={"formation_id": formation_id}):
|
2020-09-26 16:19:37 +02:00
|
|
|
H.append('<li class="notes_module_list">%s' % Mod)
|
|
|
|
if editable:
|
|
|
|
H.append('<a href="module_edit?module_id=%(module_id)s">modifier</a>' % Mod)
|
|
|
|
H.append(
|
|
|
|
'<a href="module_delete?module_id=%(module_id)s">supprimer</a>' % Mod
|
|
|
|
)
|
|
|
|
H.append("</li>")
|
|
|
|
H.append("</ul>")
|
2021-07-29 10:19:00 +02:00
|
|
|
H.append(html_sco_header.sco_footer())
|
2020-09-26 16:19:37 +02:00
|
|
|
return "\n".join(H)
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
if ue.type == sco_codes_parcours.UE_STANDARD:
|
|
|
|
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
|