2022-04-29 08:17:04 +02:00
|
|
|
##############################################################################
|
|
|
|
# ScoDoc
|
|
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
|
|
# See LICENSE
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Edition associations UE <-> Ref. Compétence
|
|
|
|
"""
|
|
|
|
from flask import g, url_for
|
|
|
|
from app import db, log
|
2022-06-23 15:04:08 +02:00
|
|
|
from app.models import Formation, UniteEns
|
2022-04-29 08:17:04 +02:00
|
|
|
from app.models.but_refcomp import ApcNiveau
|
2022-06-23 15:33:01 +02:00
|
|
|
from app.scodoc import sco_codes_parcours
|
2022-04-29 08:17:04 +02:00
|
|
|
|
|
|
|
|
2022-06-23 15:04:08 +02:00
|
|
|
def form_ue_choix_niveau(formation: Formation, ue: UniteEns) -> str:
|
2022-04-29 08:17:04 +02:00
|
|
|
"""Form. HTML pour associer une UE à un niveau de compétence"""
|
2022-06-23 15:33:01 +02:00
|
|
|
if ue.type != sco_codes_parcours.UE_STANDARD:
|
|
|
|
return ""
|
2022-04-29 08:17:04 +02:00
|
|
|
ref_comp = ue.formation.referentiel_competence
|
|
|
|
if ref_comp is None:
|
2022-05-22 03:26:39 +02:00
|
|
|
return f"""<div class="ue_choix_niveau">
|
|
|
|
<div class="warning">Pas de référentiel de compétence associé à cette formation !</div>
|
|
|
|
<div><a class="stdlink" href="{ url_for('notes.refcomp_assoc_formation',
|
|
|
|
scodoc_dept=g.scodoc_dept, formation_id=ue.formation.id)
|
|
|
|
}">associer un référentiel de compétence</a>
|
|
|
|
</div>
|
|
|
|
</div>"""
|
2022-09-07 23:36:50 +02:00
|
|
|
annee = 1 if ue.semestre_idx is None else (ue.semestre_idx + 1) // 2 # 1, 2, 3
|
2022-04-29 08:17:04 +02:00
|
|
|
niveaux_by_parcours = ref_comp.get_niveaux_by_parcours(annee)
|
|
|
|
|
2022-06-23 15:04:08 +02:00
|
|
|
# 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
|
|
|
|
}
|
2022-04-29 08:17:04 +02:00
|
|
|
options = []
|
2022-06-23 15:04:08 +02:00
|
|
|
if niveaux_by_parcours["TC"]: # TC pour Tronc Commun
|
2022-04-29 08:17:04 +02:00
|
|
|
options.append("""<optgroup label="Tronc commun">""")
|
|
|
|
for n in niveaux_by_parcours["TC"]:
|
2022-06-23 15:04:08 +02:00
|
|
|
if n.id in niveaux_autres_ues:
|
|
|
|
disabled = "disabled"
|
|
|
|
else:
|
|
|
|
disabled = ""
|
2022-04-29 08:17:04 +02:00
|
|
|
options.append(
|
2022-06-23 15:04:08 +02:00
|
|
|
f"""<option value="{n.id}" {'selected'
|
|
|
|
if ue.niveau_competence == n else ''}
|
|
|
|
{disabled}>{n.annee} {n.competence.titre_long}
|
|
|
|
niveau {n.ordre}</option>"""
|
2022-04-29 08:17:04 +02:00
|
|
|
)
|
|
|
|
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]:
|
2022-06-23 15:04:08 +02:00
|
|
|
if n.id in niveaux_autres_ues:
|
|
|
|
disabled = "disabled"
|
|
|
|
else:
|
|
|
|
disabled = ""
|
2022-04-29 08:17:04 +02:00
|
|
|
options.append(
|
2022-06-23 15:04:08 +02:00
|
|
|
f"""<option value="{n.id}" {'selected'
|
|
|
|
if ue.niveau_competence == n else ''}
|
|
|
|
{disabled}>{n.annee} {n.competence.titre_long}
|
|
|
|
niveau {n.ordre}</option>"""
|
2022-04-29 08:17:04 +02:00
|
|
|
)
|
|
|
|
options.append("""</optgroup>""")
|
|
|
|
options_str = "\n".join(options)
|
|
|
|
return f"""
|
2022-05-22 03:26:39 +02:00
|
|
|
<div class="ue_choix_niveau">
|
2022-07-14 22:20:24 +02:00
|
|
|
<form class="form_ue_choix_niveau">
|
2022-04-29 08:17:04 +02:00
|
|
|
<b>Niveau de compétence associé:</b>
|
2022-07-09 12:55:23 +02:00
|
|
|
<select onchange="set_ue_niveau_competence(this);"
|
|
|
|
data-ue_id="{ue.id}"
|
|
|
|
data-setter="{
|
2022-04-29 08:17:04 +02:00
|
|
|
url_for( "notes.set_ue_niveau_competence", scodoc_dept=g.scodoc_dept)
|
|
|
|
}">
|
|
|
|
<option value="" {'selected' if ue.niveau_competence is None else ''}>aucun</option>
|
|
|
|
{options_str}
|
|
|
|
</select>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def set_ue_niveau_competence(ue_id: int, niveau_id: int):
|
|
|
|
"""Associe le niveau et l'UE"""
|
|
|
|
ue = UniteEns.query.get_or_404(ue_id)
|
2022-06-23 15:04:08 +02:00
|
|
|
|
|
|
|
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
|
2022-04-29 08:17:04 +02:00
|
|
|
if niveau_id == "":
|
2022-07-09 12:55:23 +02:00
|
|
|
niveau = ""
|
2022-04-29 08:17:04 +02:00
|
|
|
# suppression de l'association
|
|
|
|
ue.niveau_competence = None
|
|
|
|
else:
|
|
|
|
niveau = ApcNiveau.query.get_or_404(niveau_id)
|
|
|
|
ue.niveau_competence = niveau
|
|
|
|
db.session.add(ue)
|
|
|
|
db.session.commit()
|
2022-07-09 12:55:23 +02:00
|
|
|
log(f"set_ue_niveau_competence( {ue}, {niveau} )")
|
|
|
|
|
2022-04-29 08:17:04 +02:00
|
|
|
return "", 204
|