2022-05-29 17:34:03 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
2022-06-09 07:39:58 +02:00
|
|
|
"""Décisions de jury (validations) des RCUE et années du BUT
|
2022-05-29 17:34:03 +02:00
|
|
|
"""
|
|
|
|
|
2022-06-09 07:39:58 +02:00
|
|
|
from app import db
|
2022-05-29 17:34:03 +02:00
|
|
|
from app.models import CODE_STR_LEN
|
2022-06-09 07:39:58 +02:00
|
|
|
from app.models.but_refcomp import ApcNiveau
|
2022-06-20 17:56:27 +02:00
|
|
|
from app.models.etudiants import Identite
|
2022-06-29 19:25:08 +02:00
|
|
|
from app.models.formations import Formation
|
2022-06-09 07:39:58 +02:00
|
|
|
from app.models.formsemestre import FormSemestre
|
2022-12-24 22:06:22 +01:00
|
|
|
from app.models.ues import UniteEns
|
2022-05-29 17:34:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ApcValidationRCUE(db.Model):
|
|
|
|
"""Validation des niveaux de compétences
|
|
|
|
|
|
|
|
aka "regroupements cohérents d'UE" dans le jargon BUT.
|
|
|
|
|
2023-06-28 21:25:38 +02:00
|
|
|
Le formsemestre est l'origine, utilisé pour effacer
|
2022-05-29 17:34:03 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "apc_validation_rcue"
|
|
|
|
# Assure unicité de la décision:
|
|
|
|
__table_args__ = (
|
|
|
|
db.UniqueConstraint("etudid", "formsemestre_id", "ue1_id", "ue2_id"),
|
|
|
|
)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
|
|
|
index=True,
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("notes_formsemestre.id"), index=True, nullable=True
|
|
|
|
)
|
2023-07-02 12:09:17 +02:00
|
|
|
"formsemestre origine du RCUE (celui d'où a été émis la validation)"
|
2022-05-29 17:34:03 +02:00
|
|
|
# Les deux UE associées à ce niveau:
|
|
|
|
ue1_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), nullable=False)
|
|
|
|
ue2_id = db.Column(db.Integer, db.ForeignKey("notes_ue.id"), nullable=False)
|
|
|
|
# optionnel, le parcours dans lequel se trouve la compétence:
|
2023-02-09 11:56:20 +01:00
|
|
|
parcours_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("apc_parcours.id", ondelete="set null"), nullable=True
|
|
|
|
)
|
2022-05-29 17:34:03 +02:00
|
|
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
code = db.Column(db.String(CODE_STR_LEN), nullable=False, index=True)
|
|
|
|
|
|
|
|
etud = db.relationship("Identite", backref="apc_validations_rcues")
|
|
|
|
formsemestre = db.relationship("FormSemestre", backref="apc_validations_rcues")
|
|
|
|
ue1 = db.relationship("UniteEns", foreign_keys=ue1_id)
|
|
|
|
ue2 = db.relationship("UniteEns", foreign_keys=ue2_id)
|
|
|
|
parcour = db.relationship("ApcParcours")
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-10-01 10:39:46 +02:00
|
|
|
return f"""<{self.__class__.__name__} {self.id} {self.etud} {
|
|
|
|
self.ue1}/{self.ue2}:{self.code!r}>"""
|
|
|
|
|
|
|
|
def __str__(self):
|
2022-12-24 22:06:22 +01:00
|
|
|
return f"""Décision sur RCUE {self.ue1.acronyme}/{self.ue2.acronyme}: {
|
|
|
|
self.code} enregistrée le {self.date.strftime("%d/%m/%Y")}"""
|
|
|
|
|
2023-06-18 09:37:13 +02:00
|
|
|
def html(self) -> str:
|
2022-12-24 22:06:22 +01:00
|
|
|
"description en HTML"
|
|
|
|
return f"""Décision sur RCUE {self.ue1.acronyme}/{self.ue2.acronyme}:
|
|
|
|
<b>{self.code}</b>
|
2023-01-11 13:37:02 +01:00
|
|
|
<em>enregistrée le {self.date.strftime("%d/%m/%Y")}
|
|
|
|
à {self.date.strftime("%Hh%M")}</em>"""
|
2022-05-29 17:34:03 +02:00
|
|
|
|
2023-01-23 19:08:00 +01:00
|
|
|
def annee(self) -> str:
|
|
|
|
"""l'année BUT concernée: "BUT1", "BUT2" ou "BUT3" """
|
|
|
|
niveau = self.niveau()
|
|
|
|
return niveau.annee if niveau else None
|
|
|
|
|
2022-06-09 07:39:58 +02:00
|
|
|
def niveau(self) -> ApcNiveau:
|
|
|
|
"""Le niveau de compétence associé à cet RCUE."""
|
|
|
|
# Par convention, il est donné par la seconde UE
|
|
|
|
return self.ue2.niveau_competence
|
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
def to_dict(self):
|
|
|
|
"as a dict"
|
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
2023-07-18 16:41:02 +02:00
|
|
|
d["etud"] = self.etud.to_dict_short()
|
|
|
|
d["ue1"] = self.ue1.to_dict()
|
|
|
|
d["ue2"] = self.ue2.to_dict()
|
|
|
|
|
2023-01-17 01:05:48 +01:00
|
|
|
return d
|
|
|
|
|
2022-06-29 19:25:08 +02:00
|
|
|
def to_dict_bul(self) -> dict:
|
2022-07-08 18:09:45 +02:00
|
|
|
"Export dict pour bulletins: le code et le niveau de compétence"
|
2022-09-08 01:22:22 +02:00
|
|
|
niveau = self.niveau()
|
|
|
|
return {
|
|
|
|
"code": self.code,
|
|
|
|
"niveau": None if niveau is None else niveau.to_dict_bul(),
|
|
|
|
}
|
2022-06-29 19:25:08 +02:00
|
|
|
|
2023-02-12 23:03:12 +01:00
|
|
|
def to_dict_codes(self) -> dict:
|
|
|
|
"Dict avec seulement les ids et la date - pour cache table jury"
|
|
|
|
return {
|
|
|
|
"id": self.id,
|
|
|
|
"code": self.code,
|
|
|
|
"date": self.date,
|
|
|
|
"etudid": self.etudid,
|
|
|
|
"niveau_id": self.niveau().id,
|
|
|
|
"formsemestre_id": self.formsemestre_id,
|
|
|
|
}
|
|
|
|
|
2022-06-09 07:39:58 +02:00
|
|
|
|
2022-05-29 17:34:03 +02:00
|
|
|
class ApcValidationAnnee(db.Model):
|
|
|
|
"""Validation des années du BUT"""
|
|
|
|
|
|
|
|
__tablename__ = "apc_validation_annee"
|
|
|
|
# Assure unicité de la décision:
|
2023-06-28 10:09:56 +02:00
|
|
|
__table_args__ = (
|
2023-06-30 09:34:29 +02:00
|
|
|
db.UniqueConstraint("etudid", "ordre", "referentiel_competence_id"),
|
|
|
|
)
|
2022-05-29 17:34:03 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
|
|
|
index=True,
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
ordre = db.Column(db.Integer, nullable=False)
|
|
|
|
"numéro de l'année: 1, 2, 3"
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("notes_formsemestre.id"), nullable=True
|
|
|
|
)
|
2023-06-28 21:25:38 +02:00
|
|
|
"le semestre origine, normalement l'IMPAIR (le 1er) de l'année"
|
2023-06-30 09:34:29 +02:00
|
|
|
referentiel_competence_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("apc_referentiel_competences.id"), nullable=False
|
2023-06-15 08:49:05 +02:00
|
|
|
)
|
|
|
|
annee_scolaire = db.Column(db.Integer, nullable=False) # eg 2021
|
2022-05-29 17:34:03 +02:00
|
|
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
code = db.Column(db.String(CODE_STR_LEN), nullable=False, index=True)
|
|
|
|
|
|
|
|
etud = db.relationship("Identite", backref="apc_validations_annees")
|
|
|
|
formsemestre = db.relationship("FormSemestre", backref="apc_validations_annees")
|
|
|
|
|
|
|
|
def __repr__(self):
|
2022-12-24 22:06:22 +01:00
|
|
|
return f"""<{self.__class__.__name__} {self.id} {self.etud
|
|
|
|
} BUT{self.ordre}/{self.annee_scolaire}:{self.code!r}>"""
|
2022-06-29 19:25:08 +02:00
|
|
|
|
2022-10-01 10:39:46 +02:00
|
|
|
def __str__(self):
|
|
|
|
return f"""décision sur année BUT{self.ordre} {self.annee_scolaire} : {self.code}"""
|
|
|
|
|
2022-06-29 19:25:08 +02:00
|
|
|
def to_dict_bul(self) -> dict:
|
|
|
|
"dict pour bulletins"
|
|
|
|
return {
|
|
|
|
"annee_scolaire": self.annee_scolaire,
|
2023-06-30 09:34:29 +02:00
|
|
|
"date": self.date.isoformat() if self.date else "",
|
2022-06-29 19:25:08 +02:00
|
|
|
"code": self.code,
|
|
|
|
"ordre": self.ordre,
|
|
|
|
}
|
|
|
|
|
2023-06-18 09:37:13 +02:00
|
|
|
def html(self) -> str:
|
|
|
|
"Affichage html"
|
2023-06-30 09:34:29 +02:00
|
|
|
date_str = (
|
|
|
|
f"""le {self.date.strftime("%d/%m/%Y")} à {self.date.strftime("%Hh%M")}"""
|
|
|
|
if self.date
|
|
|
|
else "(sans date)"
|
|
|
|
)
|
2023-06-30 17:26:41 +02:00
|
|
|
link = (
|
|
|
|
self.formsemestre.html_link_status(
|
|
|
|
label=f"{self.formsemestre.titre_formation(with_sem_idx=1)}",
|
|
|
|
title=self.formsemestre.titre_annee(),
|
|
|
|
)
|
|
|
|
if self.formsemestre
|
|
|
|
else "externe/antérieure"
|
|
|
|
)
|
2023-06-18 09:37:13 +02:00
|
|
|
return f"""Validation <b>année BUT{self.ordre}</b> émise par
|
2023-06-30 17:26:41 +02:00
|
|
|
{link}
|
2023-06-21 16:47:24 +02:00
|
|
|
: <b>{self.code}</b>
|
2023-06-30 09:34:29 +02:00
|
|
|
{date_str}
|
2023-06-18 09:37:13 +02:00
|
|
|
"""
|
|
|
|
|
2022-06-29 19:25:08 +02:00
|
|
|
|
|
|
|
def dict_decision_jury(etud: Identite, formsemestre: FormSemestre) -> dict:
|
|
|
|
"""
|
2022-07-08 18:09:45 +02:00
|
|
|
Un dict avec les décisions de jury BUT enregistrées:
|
|
|
|
- decision_rcue : list[dict]
|
2023-06-15 08:49:05 +02:00
|
|
|
- decision_annee : dict (décision issue de ce semestre seulement (à confirmer ?))
|
2022-06-29 19:25:08 +02:00
|
|
|
Ne reprend pas les décisions d'UE, non spécifiques au BUT.
|
|
|
|
"""
|
|
|
|
decisions = {}
|
|
|
|
# --- RCUEs: seulement sur semestres pairs XXX à améliorer
|
|
|
|
if formsemestre.semestre_id % 2 == 0:
|
|
|
|
# validations émises depuis ce formsemestre:
|
2023-06-17 14:56:04 +02:00
|
|
|
validations_rcues = (
|
|
|
|
ApcValidationRCUE.query.filter_by(
|
|
|
|
etudid=etud.id, formsemestre_id=formsemestre.id
|
|
|
|
)
|
|
|
|
.join(UniteEns, UniteEns.id == ApcValidationRCUE.ue1_id)
|
|
|
|
.order_by(UniteEns.numero, UniteEns.acronyme)
|
2022-06-29 19:25:08 +02:00
|
|
|
)
|
|
|
|
decisions["decision_rcue"] = [v.to_dict_bul() for v in validations_rcues]
|
2022-09-11 07:52:18 +02:00
|
|
|
titres_rcues = []
|
|
|
|
for dec_rcue in decisions["decision_rcue"]:
|
|
|
|
niveau = dec_rcue["niveau"]
|
|
|
|
if niveau is None:
|
|
|
|
titres_rcues.append(f"""pas de compétence: code {dec_rcue["code"]}""")
|
|
|
|
else:
|
|
|
|
titres_rcues.append(
|
2022-12-24 22:06:22 +01:00
|
|
|
f"""{niveau["competence"]["titre"]} {niveau["ordre"]}: {
|
|
|
|
dec_rcue["code"]}"""
|
2022-09-11 07:52:18 +02:00
|
|
|
)
|
|
|
|
decisions["descr_decisions_rcue"] = ", ".join(titres_rcues)
|
2022-07-08 23:58:27 +02:00
|
|
|
decisions["descr_decisions_niveaux"] = (
|
|
|
|
"Niveaux de compétences: " + decisions["descr_decisions_rcue"]
|
|
|
|
)
|
2022-06-29 19:25:08 +02:00
|
|
|
else:
|
|
|
|
decisions["decision_rcue"] = []
|
2022-07-08 23:58:27 +02:00
|
|
|
decisions["descr_decisions_rcue"] = ""
|
|
|
|
decisions["descr_decisions_niveaux"] = ""
|
2022-06-29 19:25:08 +02:00
|
|
|
# --- Année: prend la validation pour l'année scolaire de ce semestre
|
2023-06-30 09:34:29 +02:00
|
|
|
validation = ApcValidationAnnee.query.filter_by(
|
|
|
|
etudid=etud.id,
|
|
|
|
annee_scolaire=formsemestre.annee_scolaire(),
|
|
|
|
referentiel_competence_id=formsemestre.formation.referentiel_competence_id,
|
|
|
|
).first()
|
2022-06-29 19:25:08 +02:00
|
|
|
if validation:
|
|
|
|
decisions["decision_annee"] = validation.to_dict_bul()
|
|
|
|
else:
|
|
|
|
decisions["decision_annee"] = None
|
|
|
|
return decisions
|