ue_edit: interdit association de 2 UE du meme sem. auy même niveau de comp.

This commit is contained in:
Emmanuel Viennet 2022-06-23 15:04:08 +02:00
parent 99c22bdb83
commit a41f92d550
2 changed files with 35 additions and 6 deletions

View File

@ -9,11 +9,11 @@ Edition associations UE <-> Ref. Compétence
"""
from flask import g, url_for
from app import db, log
from app.models import UniteEns
from app.models import Formation, UniteEns
from app.models.but_refcomp import ApcNiveau
def form_ue_choix_niveau(ue: UniteEns) -> str:
def form_ue_choix_niveau(formation: Formation, ue: UniteEns) -> str:
"""Form. HTML pour associer une UE à un niveau de compétence"""
ref_comp = ue.formation.referentiel_competence
if ref_comp is None:
@ -27,20 +27,39 @@ def form_ue_choix_niveau(ue: UniteEns) -> str:
annee = (ue.semestre_idx + 1) // 2 # 1, 2, 3
niveaux_by_parcours = ref_comp.get_niveaux_by_parcours(annee)
# Les niveaux déjà associés à d'autres UE du même semestre
autres_ues = formation.ues.filter_by(semestre_idx=ue.semestre_idx)
niveaux_autres_ues = {
oue.niveau_competence_id for oue in autres_ues if oue.id != ue.id
}
options = []
if niveaux_by_parcours["TC"]:
if niveaux_by_parcours["TC"]: # TC pour Tronc Commun
options.append("""<optgroup label="Tronc commun">""")
for n in niveaux_by_parcours["TC"]:
if n.id in niveaux_autres_ues:
disabled = "disabled"
else:
disabled = ""
options.append(
f"""<option value="{n.id}" {'selected' if ue.niveau_competence == n else ''}>{n.annee} {n.competence.titre_long} niveau {n.ordre}</option>"""
f"""<option value="{n.id}" {'selected'
if ue.niveau_competence == n else ''}
{disabled}>{n.annee} {n.competence.titre_long}
niveau {n.ordre}</option>"""
)
options.append("""</optgroup>""")
for parcour in ref_comp.parcours:
if len(niveaux_by_parcours[parcour.id]):
options.append(f"""<optgroup label="Parcours {parcour.libelle}">""")
for n in niveaux_by_parcours[parcour.id]:
if n.id in niveaux_autres_ues:
disabled = "disabled"
else:
disabled = ""
options.append(
f"""<option value="{n.id}" {'selected' if ue.niveau_competence == n else ''}>{n.annee} {n.competence.titre_long} niveau {n.ordre}</option>"""
f"""<option value="{n.id}" {'selected'
if ue.niveau_competence == n else ''}
{disabled}>{n.annee} {n.competence.titre_long}
niveau {n.ordre}</option>"""
)
options.append("""</optgroup>""")
options_str = "\n".join(options)
@ -63,6 +82,16 @@ def set_ue_niveau_competence(ue_id: int, niveau_id: int):
"""Associe le niveau et l'UE"""
log(f"set_ue_niveau_competence( {ue_id}, {niveau_id} )")
ue = UniteEns.query.get_or_404(ue_id)
autres_ues = ue.formation.ues.filter_by(semestre_idx=ue.semestre_idx)
niveaux_autres_ues = {
oue.niveau_competence_id for oue in autres_ues if oue.id != ue.id
}
if niveau_id in niveaux_autres_ues:
log(
f"set_ue_niveau_competence: denying association of {ue} to already associated {niveau_id}"
)
return "", 409 # conflict
if niveau_id == "":
# suppression de l'association
ue.niveau_competence = None

View File

@ -423,7 +423,7 @@ def ue_edit(ue_id=None, create=False, formation_id=None, default_semestre_idx=No
if tf[0] == 0:
niveau_competence_div = ""
if ue and is_apc:
niveau_competence_div = apc_edit_ue.form_ue_choix_niveau(ue)
niveau_competence_div = apc_edit_ue.form_ue_choix_niveau(formation, ue)
if ue and ue.modules.count() and ue.semestre_idx is not None:
modules_div = f"""<div id="ue_list_modules">
<div><b>{ue.modules.count()} modules sont rattachés