diff --git a/app/but/apc_edit_ue.py b/app/but/apc_edit_ue.py index 55687f0f..b88e43cf 100644 --- a/app/but/apc_edit_ue.py +++ b/app/but/apc_edit_ue.py @@ -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("""""") for n in niveaux_by_parcours["TC"]: + if n.id in niveaux_autres_ues: + disabled = "disabled" + else: + disabled = "" options.append( - f"""""" + f"""""" ) options.append("""""") for parcour in ref_comp.parcours: if len(niveaux_by_parcours[parcour.id]): options.append(f"""""") for n in niveaux_by_parcours[parcour.id]: + if n.id in niveaux_autres_ues: + disabled = "disabled" + else: + disabled = "" options.append( - f"""""" + f"""""" ) options.append("""""") 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 diff --git a/app/scodoc/sco_edit_ue.py b/app/scodoc/sco_edit_ue.py index a0a4e1d4..a2a6c05c 100644 --- a/app/scodoc/sco_edit_ue.py +++ b/app/scodoc/sco_edit_ue.py @@ -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"""
{ue.modules.count()} modules sont rattachés