forked from ScoDoc/DocScoDoc
371 lines
12 KiB
Python
371 lines
12 KiB
Python
##############################################################################
|
|
# ScoDoc
|
|
# Copyright (c) 1999 - 2022 Emmanuel Viennet. All rights reserved.
|
|
# See LICENSE
|
|
##############################################################################
|
|
|
|
"""Jury BUT: affichage/formulaire
|
|
"""
|
|
|
|
import re
|
|
|
|
import flask
|
|
from flask import flash, url_for
|
|
from flask import g, request
|
|
|
|
from app import db
|
|
from app.but import jury_but
|
|
from app.but.jury_but import DecisionsProposeesAnnee, DecisionsProposeesUE
|
|
from app.comp import res_sem
|
|
from app.comp.res_but import ResultatsSemestreBUT
|
|
from app.models import (
|
|
FormSemestre,
|
|
FormSemestreInscription,
|
|
Identite,
|
|
UniteEns,
|
|
ScolarAutorisationInscription,
|
|
)
|
|
from app.scodoc import html_sco_header
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
|
from app.scodoc import sco_utils as scu
|
|
|
|
|
|
def show_etud(deca: DecisionsProposeesAnnee, read_only: bool = True) -> str:
|
|
"""Affichage des décisions annuelles BUT
|
|
Si pas read_only, menus sélection codes jury.
|
|
"""
|
|
H = []
|
|
if deca.code_valide and not read_only:
|
|
erase_span = f"""<a href="{
|
|
url_for("notes.formsemestre_jury_but_erase",
|
|
scodoc_dept=g.scodoc_dept, formsemestre_id=deca.formsemestre_id,
|
|
etudid=deca.etud.id)}" class="stdlink">effacer décisions</a>"""
|
|
else:
|
|
erase_span = ""
|
|
|
|
H.append(
|
|
f"""
|
|
<div class="but_section_annee">
|
|
<div>
|
|
<b>Décision de jury pour l'année :</b> {
|
|
_gen_but_select("code_annee", deca.codes, deca.code_valide,
|
|
disabled=True, klass="manual")
|
|
}
|
|
<span>({'non ' if deca.code_valide is None else ''}enregistrée)</span>
|
|
<span>{erase_span}</span>
|
|
</div>
|
|
<div class="but_explanation">{deca.explanation}</div>
|
|
</div>
|
|
"""
|
|
)
|
|
|
|
H.append(
|
|
f"""
|
|
<div><b>Niveaux de compétences et unités d'enseignement :</b></div>
|
|
<div class="but_annee">
|
|
<div class="titre"></div>
|
|
<div class="titre">S{1}</div>
|
|
<div class="titre">S{2}</div>
|
|
<div class="titre">RCUE</div>
|
|
"""
|
|
)
|
|
for niveau in deca.niveaux_competences:
|
|
H.append(
|
|
f"""<div class="but_niveau_titre">
|
|
<div title="{niveau.competence.titre_long}">{niveau.competence.titre}</div>
|
|
</div>"""
|
|
)
|
|
dec_rcue = deca.decisions_rcue_by_niveau.get(niveau.id)
|
|
if dec_rcue is None:
|
|
break
|
|
# Semestre impair
|
|
H.append(
|
|
_gen_but_niveau_ue(
|
|
dec_rcue.rcue.ue_1,
|
|
deca.decisions_ues[dec_rcue.rcue.ue_1.id].moy_ue,
|
|
# dec_rcue.rcue.moy_ue_1,
|
|
deca.decisions_ues[dec_rcue.rcue.ue_1.id],
|
|
disabled=read_only,
|
|
)
|
|
)
|
|
# Semestre pair
|
|
H.append(
|
|
_gen_but_niveau_ue(
|
|
dec_rcue.rcue.ue_2,
|
|
deca.decisions_ues[dec_rcue.rcue.ue_2.id].moy_ue,
|
|
# dec_rcue.rcue.moy_ue_2,
|
|
deca.decisions_ues[dec_rcue.rcue.ue_2.id],
|
|
disabled=read_only,
|
|
)
|
|
)
|
|
# RCUE
|
|
H.append(
|
|
f"""<div class="but_niveau_rcue
|
|
{'recorded' if dec_rcue.code_valide is not None else ''}
|
|
">
|
|
<div class="but_note">{scu.fmt_note(dec_rcue.rcue.moy_rcue)}</div>
|
|
<div class="but_code">{
|
|
_gen_but_select("code_rcue_"+str(niveau.id),
|
|
dec_rcue.codes,
|
|
dec_rcue.code_valide,
|
|
disabled=True, klass="manual"
|
|
)
|
|
}</div>
|
|
</div>"""
|
|
)
|
|
H.append("</div>") # but_annee
|
|
return "\n".join(H)
|
|
|
|
|
|
def _gen_but_select(
|
|
name: str,
|
|
codes: list[str],
|
|
code_valide: str,
|
|
disabled: bool = False,
|
|
klass: str = "",
|
|
) -> str:
|
|
"Le menu html select avec les codes"
|
|
h = "\n".join(
|
|
[
|
|
f"""<option value="{code}"
|
|
{'selected' if code == code_valide else ''}
|
|
class="{'recorded' if code == code_valide else ''}"
|
|
>{code}</option>"""
|
|
for code in codes
|
|
]
|
|
)
|
|
return f"""<select required name="{name}"
|
|
class="but_code {klass}"
|
|
onchange="change_menu_code(this);"
|
|
{"disabled" if disabled else ""}
|
|
>{h}</select>
|
|
"""
|
|
|
|
|
|
def _gen_but_niveau_ue(
|
|
ue: UniteEns, moy_ue: float, dec_ue: DecisionsProposeesUE, disabled=False
|
|
):
|
|
return f"""<div class="but_niveau_ue {
|
|
'recorded' if dec_ue.code_valide is not None else ''}
|
|
">
|
|
<div title="{ue.titre}">{ue.acronyme}</div>
|
|
<div class="but_note">{scu.fmt_note(moy_ue)}</div>
|
|
<div class="but_code">{
|
|
_gen_but_select("code_ue_"+str(ue.id),
|
|
dec_ue.codes,
|
|
dec_ue.code_valide, disabled=disabled
|
|
)
|
|
}</div>
|
|
</div>"""
|
|
|
|
|
|
def jury_but_semestriel(
|
|
formsemestre: FormSemestre,
|
|
etud: Identite,
|
|
read_only: bool,
|
|
navigation_div: str = "",
|
|
) -> str:
|
|
"""Formulaire saisie décision d'UE d'un semestre BUT isolé (pas jury annuel)"""
|
|
res: ResultatsSemestreBUT = res_sem.load_formsemestre_results(formsemestre)
|
|
parcour, ues = jury_but.list_ue_parcour_etud(formsemestre, etud, res)
|
|
inscription_etat = etud.inscription_etat(formsemestre.id)
|
|
semestre_terminal = (
|
|
formsemestre.semestre_id >= formsemestre.formation.get_parcours().NB_SEM
|
|
)
|
|
est_autorise_a_passer = (formsemestre.semestre_id + 1) in (
|
|
a.semestre_id
|
|
for a in ScolarAutorisationInscription.query.filter_by(
|
|
etudid=etud.id,
|
|
origin_formsemestre_id=formsemestre.id,
|
|
)
|
|
)
|
|
decisions_ues = {
|
|
ue.id: DecisionsProposeesUE(etud, formsemestre, ue, inscription_etat)
|
|
for ue in ues
|
|
}
|
|
for dec_ue in decisions_ues.values():
|
|
dec_ue.compute_codes()
|
|
|
|
if request.method == "POST":
|
|
if not read_only:
|
|
for key in request.form:
|
|
code = request.form[key]
|
|
# Codes d'UE
|
|
m = re.match(r"^code_ue_(\d+)$", key)
|
|
if m:
|
|
ue_id = int(m.group(1))
|
|
dec_ue = decisions_ues.get(ue_id)
|
|
if not dec_ue:
|
|
raise ScoValueError(f"UE invalide ue_id={ue_id}")
|
|
dec_ue.record(code)
|
|
db.session.commit()
|
|
flash("codes enregistrés")
|
|
if not semestre_terminal:
|
|
if request.form.get("autorisation_passage"):
|
|
if not est_autorise_a_passer:
|
|
ScolarAutorisationInscription.autorise_etud(
|
|
etud.id,
|
|
formsemestre.formation.formation_code,
|
|
formsemestre.id,
|
|
formsemestre.semestre_id + 1,
|
|
)
|
|
db.session.commit()
|
|
flash(
|
|
f"autorisation de passage en S{formsemestre.semestre_id + 1} enregistrée"
|
|
)
|
|
else:
|
|
if est_autorise_a_passer:
|
|
ScolarAutorisationInscription.delete_autorisation_etud(
|
|
etud.id, formsemestre.id
|
|
)
|
|
db.session.commit()
|
|
flash(
|
|
f"autorisation de passage en S{formsemestre.semestre_id + 1} annulée"
|
|
)
|
|
return flask.redirect(
|
|
url_for(
|
|
"notes.formsemestre_validation_but",
|
|
scodoc_dept=g.scodoc_dept,
|
|
formsemestre_id=formsemestre.id,
|
|
etudid=etud.id,
|
|
)
|
|
)
|
|
# GET
|
|
if formsemestre.semestre_id % 2 == 0:
|
|
warning = f"""<div class="warning">
|
|
Cet étudiant de S{formsemestre.semestre_id} ne peut pas passer
|
|
en jury BUT annuel car il lui manque le semestre précédent.
|
|
</div>"""
|
|
else:
|
|
warning = ""
|
|
H = [
|
|
html_sco_header.sco_header(
|
|
page_title="Validation BUT",
|
|
formsemestre_id=formsemestre.id,
|
|
etudid=etud.id,
|
|
cssstyles=("css/jury_but.css",),
|
|
javascripts=("js/jury_but.js",),
|
|
),
|
|
f"""
|
|
<div class="jury_but">
|
|
<div>
|
|
<div class="bull_head">
|
|
<div>
|
|
<div class="titre_parcours">Jury BUT S{formsemestre.id}
|
|
- Parcours {(parcour.libelle if parcour else False) or "non spécifié"}
|
|
</div>
|
|
<div class="nom_etud">{etud.nomprenom}</div>
|
|
</div>
|
|
<div class="bull_photo"><a href="{
|
|
url_for("scolar.ficheEtud", scodoc_dept=g.scodoc_dept, etudid=etud.id)
|
|
}">{etud.photo_html(title="fiche de " + etud.nomprenom)}</a>
|
|
</div>
|
|
</div>
|
|
<h3>Jury sur un semestre BUT isolé</h3>
|
|
{warning}
|
|
</div>
|
|
|
|
<form method="POST">
|
|
""",
|
|
]
|
|
if (not read_only) and any([dec.code_valide for dec in decisions_ues.values()]):
|
|
erase_span = f"""<a href="{
|
|
url_for("notes.formsemestre_jury_but_erase",
|
|
scodoc_dept=g.scodoc_dept, formsemestre_id=formsemestre.id,
|
|
etudid=etud.id, only_one_sem=1)}" class="stdlink">effacer décisions</a>"""
|
|
else:
|
|
erase_span = "aucune décision enregistrée pour ce semestre"
|
|
|
|
H.append(
|
|
f"""
|
|
<div class="but_section_annee">
|
|
<span>{erase_span}</span>
|
|
</div>
|
|
<div><b>Unités d'enseignement de S{formsemestre.semestre_id}:</b></div>
|
|
<div class="but_annee">
|
|
<div class="titre"></div>
|
|
<div class="titre"></div>
|
|
<div class="titre"></div>
|
|
<div class="titre"></div>
|
|
"""
|
|
)
|
|
for ue in ues:
|
|
dec_ue = decisions_ues[ue.id]
|
|
H.append("""<div class="but_niveau_titre"><div></div></div>""")
|
|
H.append(
|
|
_gen_but_niveau_ue(
|
|
ue,
|
|
dec_ue.moy_ue,
|
|
dec_ue,
|
|
disabled=read_only,
|
|
)
|
|
)
|
|
H.append(
|
|
"""<div style=""></div>
|
|
<div class=""></div>"""
|
|
)
|
|
H.append("</div>") # but_annee
|
|
|
|
if read_only:
|
|
H.append(
|
|
"""<div class="but_explanation">
|
|
Vous n'avez pas la permission de modifier ces décisions.
|
|
Les champs entourés en vert sont enregistrés.</div>"""
|
|
)
|
|
else:
|
|
if formsemestre.semestre_id < formsemestre.formation.get_parcours().NB_SEM:
|
|
H.append(
|
|
f"""
|
|
<div class="but_settings">
|
|
<input type="checkbox" name="autorisation_passage" value="1" {
|
|
"checked" if est_autorise_a_passer else ""}>
|
|
<em>autoriser à passer dans le semestre S{formsemestre.semestre_id+1}</em>
|
|
</input>
|
|
</div>
|
|
"""
|
|
)
|
|
else:
|
|
H.append("""<div class="help">dernier semestre de la formation.</div>""")
|
|
H.append(
|
|
"""
|
|
<div class="but_buttons">
|
|
<input type="submit" value="Enregistrer ces décisions">
|
|
</div>
|
|
"""
|
|
)
|
|
H.append(navigation_div)
|
|
return "\n".join(H)
|
|
|
|
|
|
# -------------
|
|
def infos_fiche_etud_html(etudid: int) -> str:
|
|
"""Section html pour fiche etudiant
|
|
provisoire pour BUT 2022
|
|
"""
|
|
etud: Identite = Identite.query.get_or_404(etudid)
|
|
inscriptions = (
|
|
FormSemestreInscription.query.join(FormSemestreInscription.formsemestre)
|
|
.filter(
|
|
FormSemestreInscription.etudid == etud.id,
|
|
)
|
|
.order_by(FormSemestre.date_debut)
|
|
)
|
|
formsemestres_but = [
|
|
i.formsemestre for i in inscriptions if i.formsemestre.formation.is_apc()
|
|
]
|
|
if len(formsemestres_but) == 0:
|
|
return ""
|
|
|
|
# temporaire quick & dirty: affiche le dernier
|
|
try:
|
|
deca = DecisionsProposeesAnnee(etud, formsemestres_but[-1])
|
|
if len(deca.rcues_annee) > 0:
|
|
return f"""<div class="infos_but">
|
|
{show_etud(deca, read_only=True)}
|
|
</div>
|
|
"""
|
|
except ScoValueError:
|
|
pass
|
|
|
|
return ""
|