ScoDoc/app/scodoc/sco_edit_module.py

758 lines
24 KiB
Python
Raw Normal View History

2020-09-26 16:19:37 +02:00
# -*- mode: python -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Gestion scolarite IUT
#
2021-01-01 17:51:08 +01:00
# Copyright (c) 1999 - 2021 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
#
##############################################################################
"""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
from flask import url_for, render_template
from flask import g, request
from flask_login import current_user
2021-11-17 10:28:51 +01:00
from app.models.formations import Matiere, UniteEns
2021-07-31 18:01:10 +02:00
import app.scodoc.notesdb as ndb
import app.scodoc.sco_utils as scu
from app.scodoc.sco_utils import ModuleType
2021-08-29 19:57:32 +02:00
from app import log
2021-11-13 12:09:30 +01:00
from app import models
from app.scodoc.TrivialFormulator import TrivialFormulator
from app.scodoc.sco_permissions import Permission
from app.scodoc.sco_exceptions import ScoValueError, ScoLockedFormError, ScoGenError
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
from app.scodoc import sco_news
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-06-16 18:18:32 +02:00
"create a module"
# create
from app.scodoc import sco_formations
2021-06-16 18:18:32 +02:00
cnx = ndb.GetDBConnexion()
r = _moduleEditor.create(cnx, args)
# news
2021-08-19 10:28:35 +02:00
F = sco_formations.formation_list(args={"formation_id": args["formation_id"]})[0]
2021-06-16 18:18:32 +02:00
sco_news.add(
typ=sco_news.NEWS_FORM,
2021-06-16 18:18:32 +02:00
object=args["formation_id"],
text="Modification de la formation %(acronyme)s" % F,
2021-08-01 10:16:16 +02:00
max_frequency=3,
2021-06-16 18:18:32 +02:00
)
return r
2020-09-26 16:19:37 +02:00
2021-11-17 10:28:51 +01:00
def module_create(matiere_id=None, module_type=None, semestre_id=None):
"""Création d'un module"""
from app.scodoc import sco_formations
from app.scodoc import sco_edit_ue
2021-11-17 10:28:51 +01:00
matiere = Matiere.query.get(matiere_id)
if matiere is None:
2020-09-26 16:19:37 +02:00
raise ScoValueError("invalid matiere !")
2021-11-17 10:28:51 +01:00
ue = matiere.ue
parcours = ue.formation.get_parcours()
is_apc = parcours.APC_SAE
2021-11-17 10:28:51 +01:00
if is_apc and module_type is not None:
object_name = scu.MODULE_TYPE_NAMES[module_type]
else:
object_name = "Module"
2020-09-26 16:19:37 +02:00
H = [
2021-11-17 10:28:51 +01:00
html_sco_header.sco_header(page_title=f"Création {object_name}"),
2021-11-18 00:24:56 +01:00
]
if is_apc:
H += [
f"""<h2>Création {object_name} dans la formation {ue.formation.acronyme}</h2>"""
]
else:
H += [
f"""<h2>Création {object_name} dans la matière {matiere.titre},
(UE {ue.acronyme})</h2>
"""
]
H += [
2021-11-17 10:28:51 +01:00
render_template(
"scodoc/help/modules.html",
is_apc=is_apc,
ue=ue,
semestre_id=semestre_id,
2021-11-18 00:24:56 +01:00
)
2020-09-26 16:19:37 +02:00
]
# cherche le numero adéquat (pour placer le module en fin de liste)
2021-11-17 10:28:51 +01:00
modules = Matiere.query.get(1).modules.all()
if modules:
2021-11-17 10:28:51 +01:00
default_num = max([m.numero for m in modules]) + 10
2020-09-26 16:19:37 +02:00
else:
default_num = 10
2021-11-17 10:28:51 +01:00
descr = [
2020-09-26 16:19:37 +02:00
(
2021-11-17 10:28:51 +01:00
"code",
{
"size": 10,
2021-11-18 00:24:56 +01:00
"explanation": "code du module, ressource ou SAÉ. Exemple M1203, R2.01, ou SAÉ 3.4. Ce code doit être unique dans la formation.",
2021-11-17 10:28:51 +01:00
"allow_null": False,
"validator": lambda val, field, formation_id=ue.formation_id: check_module_code_unicity(
val, field, formation_id
),
},
),
2021-11-18 00:24:56 +01:00
(
"titre",
{
"size": 30,
"explanation": "nom du module. Exemple: <em>Introduction à la démarche ergonomique</em>",
},
),
(
"abbrev",
{
"size": 20,
"explanation": "nom abrégé (pour les bulletins). Exemple: <em>Intro. à l'ergonomie</em>",
},
),
]
semestres_indices = list(range(1, parcours.NB_SEM + 1))
descr += [
(
"semestre_id",
{
"input_type": "menu",
"type": "int",
"title": parcours.SESSION_NAME.capitalize(),
"explanation": "%s du module" % parcours.SESSION_NAME,
"labels": [str(x) for x in semestres_indices],
"allowed_values": semestres_indices,
},
),
]
descr += [
2021-11-17 10:28:51 +01:00
(
"module_type",
{
"input_type": "menu",
"title": "Type",
"explanation": "",
"labels": [x.name.capitalize() for x in scu.ModuleType],
"allowed_values": [str(int(x)) for x in scu.ModuleType],
},
),
(
"heures_cours",
2021-11-18 00:24:56 +01:00
{
"title": "Heures de cours",
"size": 4,
"type": "float",
"explanation": "nombre d'heures de cours (optionnel)",
},
2021-11-17 10:28:51 +01:00
),
(
"heures_td",
{
2021-11-18 00:24:56 +01:00
"title": "Heures de TD",
2021-11-17 10:28:51 +01:00
"size": 4,
"type": "float",
2021-11-18 00:24:56 +01:00
"explanation": "nombre d'heures de Travaux Dirigés (optionnel)",
2021-11-17 10:28:51 +01:00
},
),
(
"heures_tp",
{
2021-11-18 00:24:56 +01:00
"title": "Heures de TP",
2021-11-17 10:28:51 +01:00
"size": 4,
"type": "float",
2021-11-18 00:24:56 +01:00
"explanation": "nombre d'heures de Travaux Pratiques (optionnel)",
2021-11-17 10:28:51 +01:00
},
),
]
if is_apc:
descr += [
2020-09-26 16:19:37 +02:00
(
2021-11-17 10:28:51 +01:00
"sep_ue_coefs",
2020-09-26 16:19:37 +02:00
{
2021-11-17 10:28:51 +01:00
"input_type": "separator",
"title": """
<div>(<em>les coefficients vers les UE se fixent sur la page dédiée</em>)
</div>""",
2020-09-26 16:19:37 +02:00
},
),
2021-11-17 10:28:51 +01:00
]
else:
descr += [
2020-09-26 16:19:37 +02:00
(
"coefficient",
{
"size": 4,
"type": "float",
"explanation": "coefficient dans la formation (PPN)",
"allow_null": False,
},
),
2021-11-17 10:28:51 +01:00
]
2021-11-18 00:24:56 +01:00
2021-11-17 10:28:51 +01:00
descr += [
# ('ects', { 'size' : 4, 'type' : 'float', 'title' : 'ECTS', 'explanation' : 'nombre de crédits ECTS (inutilisés: les crédits sont associés aux UE)' }),
("formation_id", {"default": ue.formation_id, "input_type": "hidden"}),
("ue_id", {"default": ue.id, "input_type": "hidden"}),
("matiere_id", {"default": matiere.id, "input_type": "hidden"}),
(
"code_apogee",
{
"title": "Code Apogée",
"size": 25,
"explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules",
},
),
(
"numero",
{
"size": 2,
"explanation": "numéro (1,2,3,4...) pour ordre d'affichage",
"type": "int",
"default": default_num,
},
2020-09-26 16:19:37 +02:00
),
2021-11-17 10:28:51 +01:00
]
args = scu.get_request_args()
tf = TrivialFormulator(
request.base_url,
args,
descr,
2020-09-26 16:19:37 +02:00
submitlabel="Créer ce module",
)
if tf[0] == 0:
return "\n".join(H) + tf[1] + html_sco_header.sco_footer()
2020-09-26 16:19:37 +02:00
else:
2021-08-20 01:09:55 +02:00
do_module_create(tf[2])
2021-07-31 18:01:10 +02:00
return flask.redirect(
url_for(
2021-10-17 23:19:26 +02:00
"notes.ue_table",
2021-07-31 18:01:10 +02:00
scodoc_dept=g.scodoc_dept,
2021-11-17 10:28:51 +01:00
formation_id=ue.formation_id,
2021-07-31 18:01:10 +02:00
)
2020-09-26 16:19:37 +02:00
)
2021-08-20 01:09:55 +02:00
def do_module_delete(oid):
2021-06-16 18:18:32 +02:00
"delete module"
from app.scodoc import sco_formations
2021-10-16 19:20:36 +02:00
mod = module_list({"module_id": oid})[0]
2021-08-20 01:09:55 +02:00
if module_is_locked(mod["module_id"]):
2021-06-16 18:18:32 +02:00
raise ScoLockedFormError()
# S'il y a des moduleimpls, on ne peut pas detruire le module !
mods = sco_moduleimpl.moduleimpl_list(module_id=oid)
2021-06-16 18:18:32 +02:00
if mods:
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. Mais il est peut être préférable de
laisser ce programme intact et d'en créer une nouvelle version pour la modifier.
</p>
2021-10-17 23:19:26 +02:00
<a href="{url_for('notes.ue_table', scodoc_dept=g.scodoc_dept,
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
2021-08-19 10:28:35 +02:00
F = sco_formations.formation_list(args={"formation_id": mod["formation_id"]})[0]
2021-06-16 18:18:32 +02:00
sco_news.add(
typ=sco_news.NEWS_FORM,
2021-06-16 18:18:32 +02:00
object=mod["formation_id"],
text="Modification de la formation %(acronyme)s" % F,
2021-08-01 10:16:16 +02:00
max_frequency=3,
2021-06-16 18:18:32 +02:00
)
def module_delete(module_id=None):
2020-09-26 16:19:37 +02:00
"""Delete a module"""
if not module_id:
raise ScoValueError("invalid module !")
modules = module_list(args={"module_id": module_id})
if not modules:
2020-09-26 16:19:37 +02:00
raise ScoValueError("Module inexistant !")
mod = modules[0]
2020-09-26 16:19:37 +02:00
H = [
html_sco_header.sco_header(page_title="Suppression d'un module"),
"""<h2>Suppression du module %(titre)s (%(code)s)</h2>""" % mod,
2020-09-26 16:19:37 +02:00
]
dest_url = url_for(
"notes.ue_table",
scodoc_dept=g.scodoc_dept,
formation_id=str(mod["formation_id"]),
)
2020-09-26 16:19:37 +02:00
tf = TrivialFormulator(
request.base_url,
scu.get_request_args(),
2020-09-26 16:19:37 +02:00
(("module_id", {"input_type": "hidden"}),),
initvalues=mod,
2020-09-26 16:19:37 +02:00
submitlabel="Confirmer la suppression",
cancelbutton="Annuler",
)
if tf[0] == 0:
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-08-20 01:09:55 +02:00
def do_module_edit(val):
2021-06-16 18:18:32 +02:00
"edit a module"
2021-07-19 19:53:01 +02:00
from app.scodoc import sco_edit_formation
2021-06-16 18:18:32 +02:00
# check
2021-10-16 19:20:36 +02:00
mod = module_list({"module_id": val["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:
if f in val:
del val[f]
# edit
cnx = ndb.GetDBConnexion()
_moduleEditor.edit(cnx, val)
2021-07-19 19:53:01 +02:00
sco_edit_formation.invalidate_sems_in_formation(mod["formation_id"])
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"
2021-10-16 19:20:36 +02:00
Mods = 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
Mods = [m for m in Mods if m["module_id"] != module_id]
return len(Mods) == 0
def module_edit(module_id=None):
2020-09-26 16:19:37 +02:00
"""Edit a module"""
from app.scodoc import sco_formations
from app.scodoc import sco_tag_module
2020-09-26 16:19:37 +02:00
if not module_id:
raise ScoValueError("invalid module !")
modules = module_list(args={"module_id": module_id})
if not modules:
2020-09-26 16:19:37 +02:00
raise ScoValueError("invalid module !")
module = modules[0]
2021-11-17 10:28:51 +01:00
a_module = models.Module.query.get(module_id)
2021-08-20 01:09:55 +02:00
unlocked = not module_is_locked(module_id)
2021-11-13 12:09:30 +01:00
formation_id = module["formation_id"]
formation = sco_formations.formation_list(args={"formation_id": formation_id})[0]
parcours = sco_codes_parcours.get_parcours_from_code(formation["type_parcours"])
is_apc = parcours.APC_SAE
ues_matieres = ndb.SimpleDictFetch(
"""SELECT ue.acronyme, mat.*, mat.id AS matiere_id
FROM notes_matieres mat, notes_ue ue
WHERE mat.ue_id = ue.id
2021-08-21 00:49:36 +02:00
AND ue.formation_id = %(formation_id)s
ORDER BY ue.numero, mat.numero
""",
2021-11-13 12:09:30 +01:00
{"formation_id": formation_id},
2020-09-26 16:19:37 +02:00
)
mat_names = ["%s / %s" % (x["acronyme"], x["titre"]) for x in ues_matieres]
ue_mat_ids = ["%s!%s" % (x["ue_id"], x["matiere_id"]) for x in ues_matieres]
module["ue_matiere_id"] = "%s!%s" % (module["ue_id"], module["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))
dest_url = url_for(
"notes.ue_table",
scodoc_dept=g.scodoc_dept,
2021-11-13 12:09:30 +01:00
formation_id=str(formation_id),
)
2020-09-26 16:19:37 +02:00
H = [
2021-06-13 18:29:53 +02:00
html_sco_header.sco_header(
page_title="Modification du module %(titre)s" % module,
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",
],
),
"""<h2>Modification du module %(titre)s""" % module,
""" (formation %(acronyme)s, version %(version)s)</h2>""" % formation,
render_template("scodoc/help/modules.html", is_apc=is_apc),
2020-09-26 16:19:37 +02:00
]
if not unlocked:
H.append(
"""<div class="ue_warning"><span>Formation verrouillée, seuls certains éléments peuvent être modifiés</span></div>"""
)
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,
"explanation": "code du module (doit être unique dans la formation)",
"allow_null": False,
"validator": lambda val, field, formation_id=formation_id: check_module_code_unicity(
val, field, formation_id, module_id=module_id
),
},
),
("titre", {"size": 30, "explanation": "nom du module"}),
("abbrev", {"size": 20, "explanation": "nom abrégé (pour bulletins)"}),
(
"module_type",
{
"input_type": "menu",
"title": "Type",
"explanation": "",
"labels": [x.name.capitalize() for x in scu.ModuleType],
"allowed_values": [str(int(x)) for x in scu.ModuleType],
"enabled": unlocked,
},
),
(
"heures_cours",
{"size": 4, "type": "float", "explanation": "nombre d'heures de cours"},
),
(
"heures_td",
{
"size": 4,
"type": "float",
"explanation": "nombre d'heures de Travaux Dirigés",
},
),
(
"heures_tp",
{
"size": 4,
"type": "float",
"explanation": "nombre d'heures de Travaux Pratiques",
},
),
]
if is_apc:
coefs_descr = a_module.ue_coefs_descr()
if coefs_descr:
coefs_descr_txt = ", ".join(["%s: %s" % x for x in coefs_descr])
else:
coefs_descr_txt = """<span class="missing_value">non définis</span>"""
descr += [
2020-09-26 16:19:37 +02:00
(
2021-11-13 12:09:30 +01:00
"ue_coefs",
2020-09-26 16:19:37 +02:00
{
2021-11-13 12:09:30 +01:00
"readonly": True,
"title": "Coefficients vers les UE",
"default": coefs_descr_txt,
"explanation": "passer par la page d'édition de la formation pour modifier les coefficients",
2020-09-26 16:19:37 +02:00
},
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 += [
("formation_id", {"input_type": "hidden"}),
("ue_id", {"input_type": "hidden"}),
("module_id", {"input_type": "hidden"}),
(
"ue_matiere_id",
{
"input_type": "menu" if not is_apc else "hidden",
"title": "Matière",
"explanation": "un module appartient à une seule matière.",
"labels": mat_names,
"allowed_values": ue_mat_ids,
"enabled": unlocked and not is_apc, # pas d'édition des matieres en BUT
},
),
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(),
"explanation": "%s de début du module dans la formation standard"
% parcours.SESSION_NAME,
"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,
"explanation": "(optionnel) code élément pédagogique Apogée ou liste de codes ELP séparés par des virgules",
},
),
(
"numero",
{
"size": 2,
"explanation": "numéro (1,2,3,4...) pour ordre d'affichage",
"type": "int",
},
2020-09-26 16:19:37 +02:00
),
2021-11-13 12:09:30 +01:00
]
2021-11-17 10:28:51 +01:00
# force module semestre_idx to its UE
if a_module.ue.semestre_idx:
module["semestre_id"] = a_module.ue.semestre_idx
# Filet de sécurité si jamais l'UE n'a pas non plus de semestre:
if not module["semestre_id"]:
module["semestre_id"] = 1
2021-11-13 12:09:30 +01:00
tf = TrivialFormulator(
request.base_url,
scu.get_request_args(),
descr,
2020-09-26 16:19:37 +02:00
html_foot_markup="""<div style="width: 90%;"><span class="sco_tag_edit"><textarea data-module_id="{}" class="module_tag_editor">{}</textarea></span></div>""".format(
2021-08-20 01:09:55 +02:00
module_id, ",".join(sco_tag_module.module_tag_list(module_id))
2020-09-26 16:19:37 +02:00
),
initvalues=module,
2020-09-26 16:19:37 +02:00
submitlabel="Modifier ce module",
)
if tf[0] == 0:
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:
# l'UE peut changer
tf[2]["ue_id"], tf[2]["matiere_id"] = tf[2]["ue_matiere_id"].split("!")
# Check unicité code module dans la formation
2021-08-20 01:09:55 +02:00
do_module_edit(tf[2])
2021-07-31 18:01:10 +02:00
return flask.redirect(dest_url)
2020-09-26 16:19:37 +02:00
# Edition en ligne du code Apogee
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)
"""
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 = [
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">',
]
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>")
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(
"""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"
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
def formation_add_malus_modules(formation_id, 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"""
from app.scodoc import sco_edit_ue
2021-10-21 06:32:03 +02:00
ues = sco_edit_ue.ue_list(args={"formation_id": formation_id})
2020-09-26 16:19:37 +02:00
2021-10-21 06:32:03 +02:00
for ue in ues:
2020-09-26 16:19:37 +02:00
# Un seul module de malus par UE:
nb_mod_malus = len(
[
mod
2021-10-16 19:20:36 +02:00
for mod in module_list(args={"ue_id": ue["ue_id"]})
if mod["module_type"] == ModuleType.MALUS
2020-09-26 16:19:37 +02:00
]
)
if nb_mod_malus == 0:
ue_add_malus_module(ue["ue_id"], titre=titre)
2020-09-26 16:19:37 +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
def ue_add_malus_module(ue_id, titre=None, code=None):
2021-01-01 18:40:47 +01:00
"""Add a malus module in this ue"""
from app.scodoc import sco_edit_ue
2021-10-17 23:19:26 +02:00
ue = sco_edit_ue.ue_list(args={"ue_id": ue_id})[0]
2020-09-26 16:19:37 +02:00
if titre is None:
titre = ""
if code is None:
code = "MALUS%d" % ue["numero"]
# Tout module doit avoir un semestre_id (indice 1, 2, ...)
2021-08-20 01:09:55 +02:00
semestre_ids = sco_edit_ue.ue_list_semestre_ids(ue)
2020-09-26 16:19:37 +02:00
if semestre_ids:
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(
"Impossible d'ajouter un malus s'il n'y a pas d'autres modules"
)
# Matiere pour placer le module malus
2021-10-17 23:19:26 +02:00
Matlist = sco_edit_matiere.matiere_list(args={"ue_id": ue_id})
2020-09-26 16:19:37 +02:00
numero = max([mat["numero"] for mat in Matlist]) + 10
2021-06-16 18:18:32 +02:00
matiere_id = sco_edit_matiere.do_matiere_create(
2021-08-20 01:09:55 +02:00
{"ue_id": ue_id, "titre": "Malus", "numero": numero}
2020-09-26 16:19:37 +02:00
)
2021-06-16 18:18:32 +02:00
module_id = do_module_create(
2020-09-26 16:19:37 +02:00
{
"titre": titre,
"code": code,
"coefficient": 0.0, # unused
"ue_id": ue_id,
"matiere_id": matiere_id,
"formation_id": ue["formation_id"],
"semestre_id": semestre_id,
"module_type": ModuleType.MALUS,
2020-09-26 16:19:37 +02:00
},
)
return module_id