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-12-24 22:06:22 +01:00
|
|
|
from typing import Union
|
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
|
|
|
|
)
|
2022-07-06 00:05:14 +02:00
|
|
|
"formsemestre pair du RCUE"
|
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)
|
|
|
|
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-07-04 23:50:55 +02:00
|
|
|
# unused
|
2022-11-24 00:11:59 +01:00
|
|
|
# def find_rcues(
|
|
|
|
# formsemestre: FormSemestre, ue: UniteEns, etud: Identite, inscription_etat: str
|
|
|
|
# ) -> list[RegroupementCoherentUE]:
|
|
|
|
# """Les RCUE (niveau de compétence) à considérer pour cet étudiant dans
|
|
|
|
# ce semestre pour cette UE.
|
|
|
|
|
|
|
|
# Cherche les UEs du même niveau de compétence auxquelles l'étudiant est inscrit.
|
|
|
|
# En cas de redoublement, il peut y en avoir plusieurs, donc plusieurs RCUEs.
|
|
|
|
|
|
|
|
# Résultat: la liste peut être vide.
|
|
|
|
# """
|
|
|
|
# if (ue.niveau_competence is None) or (ue.semestre_idx is None):
|
|
|
|
# return []
|
|
|
|
|
|
|
|
# if ue.semestre_idx % 2: # S1, S3, S5
|
|
|
|
# other_semestre_idx = ue.semestre_idx + 1
|
|
|
|
# else:
|
|
|
|
# other_semestre_idx = ue.semestre_idx - 1
|
|
|
|
|
|
|
|
# cursor = db.session.execute(
|
|
|
|
# text(
|
|
|
|
# """SELECT
|
|
|
|
# ue.id, formsemestre.id
|
|
|
|
# FROM
|
|
|
|
# notes_ue ue,
|
|
|
|
# notes_formsemestre_inscription inscr,
|
|
|
|
# notes_formsemestre formsemestre
|
|
|
|
|
|
|
|
# WHERE
|
|
|
|
# inscr.etudid = :etudid
|
|
|
|
# AND inscr.formsemestre_id = formsemestre.id
|
|
|
|
|
|
|
|
# AND formsemestre.semestre_id = :other_semestre_idx
|
|
|
|
# AND ue.formation_id = formsemestre.formation_id
|
|
|
|
# AND ue.niveau_competence_id = :ue_niveau_competence_id
|
|
|
|
# AND ue.semestre_idx = :other_semestre_idx
|
|
|
|
# """
|
|
|
|
# ),
|
|
|
|
# {
|
|
|
|
# "etudid": etud.id,
|
|
|
|
# "other_semestre_idx": other_semestre_idx,
|
|
|
|
# "ue_niveau_competence_id": ue.niveau_competence_id,
|
|
|
|
# },
|
|
|
|
# )
|
|
|
|
# rcues = []
|
|
|
|
# for ue_id, formsemestre_id in cursor:
|
|
|
|
# other_ue = UniteEns.query.get(ue_id)
|
2023-03-20 11:17:38 +01:00
|
|
|
# other_formsemestre = FormSemestre.get_formsemestre(formsemestre_id)
|
2022-11-24 00:11:59 +01:00
|
|
|
# rcues.append(
|
|
|
|
# RegroupementCoherentUE(
|
|
|
|
# etud, formsemestre, ue, other_formsemestre, other_ue, inscription_etat
|
|
|
|
# )
|
|
|
|
# )
|
|
|
|
# # safety check: 1 seul niveau de comp. concerné:
|
|
|
|
# assert len({rcue.ue_1.niveau_competence_id for rcue in rcues}) == 1
|
|
|
|
# return rcues
|
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:
|
2022-12-20 04:16:38 +01:00
|
|
|
__table_args__ = (db.UniqueConstraint("etudid", "annee_scolaire", "ordre"),)
|
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-15 08:49:05 +02:00
|
|
|
formation_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formations.id"),
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
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,
|
|
|
|
"date": self.date.isoformat(),
|
|
|
|
"code": self.code,
|
|
|
|
"ordre": self.ordre,
|
|
|
|
}
|
|
|
|
|
2023-06-18 09:37:13 +02:00
|
|
|
def html(self) -> str:
|
|
|
|
"Affichage html"
|
|
|
|
return f"""Validation <b>année BUT{self.ordre}</b> émise par
|
|
|
|
{self.formsemestre.html_link_status() if self.formsemestre else "-"}
|
2023-06-21 16:47:24 +02:00
|
|
|
: <b>{self.code}</b>
|
2023-06-18 09:37:13 +02:00
|
|
|
le {self.date.strftime("%d/%m/%Y")} à {self.date.strftime("%Hh%M")}
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
validation = (
|
|
|
|
ApcValidationAnnee.query.filter_by(
|
|
|
|
etudid=etud.id,
|
|
|
|
annee_scolaire=formsemestre.annee_scolaire(),
|
|
|
|
)
|
2023-06-15 08:49:05 +02:00
|
|
|
.join(Formation)
|
2022-06-29 19:25:08 +02:00
|
|
|
.filter(Formation.formation_code == formsemestre.formation.formation_code)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
if validation:
|
|
|
|
decisions["decision_annee"] = validation.to_dict_bul()
|
|
|
|
else:
|
|
|
|
decisions["decision_annee"] = None
|
|
|
|
return decisions
|