2022-02-06 16:09:17 +01:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
2023-11-22 23:31:16 +01:00
|
|
|
"""Notes, décisions de jury
|
2022-02-06 16:09:17 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
from app import db
|
2023-01-11 19:09:03 +01:00
|
|
|
from app import log
|
2022-02-06 16:09:17 +01:00
|
|
|
from app.models import SHORT_STR_LEN
|
|
|
|
from app.models import CODE_STR_LEN
|
2022-06-25 03:52:28 +02:00
|
|
|
from app.models.events import Scolog
|
2023-06-25 11:49:11 +02:00
|
|
|
from app.scodoc import sco_cache
|
|
|
|
from app.scodoc import sco_utils as scu
|
2023-07-17 10:37:12 +02:00
|
|
|
from app.scodoc.codes_cursus import CODES_UE_VALIDES
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScolarFormSemestreValidation(db.Model):
|
2023-06-15 21:53:05 +02:00
|
|
|
"""Décisions de jury (sur semestre ou UEs)"""
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
__tablename__ = "scolar_formsemestre_validation"
|
|
|
|
# Assure unicité de la décision:
|
|
|
|
__table_args__ = (db.UniqueConstraint("etudid", "formsemestre_id", "ue_id"),)
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
formsemestre_validation_id = db.synonym("id")
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
2022-05-26 03:55:03 +02:00
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
2022-02-06 16:09:17 +01:00
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
ue_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_ue.id"),
|
|
|
|
index=True,
|
|
|
|
)
|
|
|
|
code = db.Column(db.String(CODE_STR_LEN), nullable=False, index=True)
|
|
|
|
# NULL pour les UE, True|False pour les semestres:
|
|
|
|
assidu = db.Column(db.Boolean)
|
|
|
|
event_date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
2022-06-22 11:44:03 +02:00
|
|
|
# NULL sauf si compense un semestre: (pas utilisé pour BUT)
|
2022-02-06 16:09:17 +01:00
|
|
|
compense_formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
|
|
|
moy_ue = db.Column(db.Float)
|
|
|
|
# (normalement NULL) indice du semestre, utile seulement pour
|
|
|
|
# UE "antérieures" et si la formation définit des UE utilisées
|
|
|
|
# dans plusieurs semestres (cas R&T IUTV v2)
|
|
|
|
semestre_id = db.Column(db.Integer)
|
|
|
|
# Si UE validée dans le cursus d'un autre etablissement
|
|
|
|
is_external = db.Column(
|
|
|
|
db.Boolean, default=False, server_default="false", index=True
|
|
|
|
)
|
|
|
|
|
|
|
|
ue = db.relationship("UniteEns", lazy="select", uselist=False)
|
2023-07-02 12:09:17 +02:00
|
|
|
etud = db.relationship("Identite", backref="validations")
|
2022-10-01 10:39:46 +02:00
|
|
|
formsemestre = db.relationship(
|
|
|
|
"FormSemestre", lazy="select", uselist=False, foreign_keys=[formsemestre_id]
|
|
|
|
)
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
def __repr__(self):
|
2023-06-18 09:37:13 +02:00
|
|
|
return f"""{self.__class__.__name__}(sem={self.formsemestre_id}, etuid={
|
|
|
|
self.etudid}, code={self.code}, ue={self.ue}, moy_ue={self.moy_ue})"""
|
2022-02-06 16:09:17 +01:00
|
|
|
|
2022-10-01 10:39:46 +02:00
|
|
|
def __str__(self):
|
|
|
|
if self.ue_id:
|
2022-10-03 10:28:46 +02:00
|
|
|
# Note: si l'objet vient d'être créé, ue_id peut exister mais pas ue !
|
2023-06-18 09:37:13 +02:00
|
|
|
return f"""décision sur UE {self.ue.acronyme if self.ue else self.ue_id
|
2023-06-28 21:25:38 +02:00
|
|
|
} ({self.ue_id}): {self.code}"""
|
2023-06-18 09:37:13 +02:00
|
|
|
return f"""décision sur semestre {self.formsemestre.titre_mois()} du {
|
2024-04-02 23:37:23 +02:00
|
|
|
self.event_date.strftime(scu.DATE_FMT)}"""
|
2022-10-01 10:39:46 +02:00
|
|
|
|
2023-06-25 11:49:11 +02:00
|
|
|
def delete(self):
|
|
|
|
"Efface cette validation"
|
|
|
|
log(f"{self.__class__.__name__}.delete({self})")
|
|
|
|
etud = self.etud
|
|
|
|
db.session.delete(self)
|
|
|
|
db.session.commit()
|
|
|
|
sco_cache.invalidate_formsemestre_etud(etud)
|
|
|
|
|
2022-07-07 16:24:52 +02:00
|
|
|
def to_dict(self) -> dict:
|
2022-10-01 10:39:46 +02:00
|
|
|
"as a dict"
|
2022-07-07 16:24:52 +02:00
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
|
|
|
return d
|
|
|
|
|
2023-06-19 22:07:31 +02:00
|
|
|
def html(self, detail=False) -> str:
|
2023-06-18 09:37:13 +02:00
|
|
|
"Affichage html"
|
|
|
|
if self.ue_id is not None:
|
2023-06-25 11:49:11 +02:00
|
|
|
moyenne = (
|
|
|
|
f", moyenne {scu.fmt_note(self.moy_ue)}/20 "
|
|
|
|
if self.moy_ue is not None
|
|
|
|
else ""
|
|
|
|
)
|
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-25 11:49:11 +02:00
|
|
|
return f"""Validation
|
|
|
|
{'<span class="redboldtext">externe</span>' if self.is_external else ""}
|
|
|
|
de l'UE <b>{self.ue.acronyme}</b>
|
2023-06-20 21:01:40 +02:00
|
|
|
{('parcours <span class="parcours">'
|
|
|
|
+ ", ".join([p.code for p in self.ue.parcours]))
|
|
|
|
+ "</span>"
|
|
|
|
if self.ue.parcours else ""}
|
2023-06-30 17:26:41 +02:00
|
|
|
{("émise par " + link)}
|
2023-06-25 11:49:11 +02:00
|
|
|
: <b>{self.code}</b>{moyenne}
|
2024-04-02 23:37:23 +02:00
|
|
|
le {self.event_date.strftime(scu.DATEATIME_FMT)}
|
|
|
|
"""
|
2023-06-18 09:37:13 +02:00
|
|
|
else:
|
|
|
|
return f"""Validation du semestre S{
|
|
|
|
self.formsemestre.semestre_id if self.formsemestre else "?"}
|
2023-06-20 21:01:40 +02:00
|
|
|
{self.formsemestre.html_link_status() if self.formsemestre else ""}
|
|
|
|
: <b>{self.code}</b>
|
2024-04-02 23:37:23 +02:00
|
|
|
le {self.event_date.strftime(scu.DATEATIME_FMT)}
|
2023-06-18 09:37:13 +02:00
|
|
|
"""
|
|
|
|
|
2023-07-17 10:37:12 +02:00
|
|
|
def ects(self) -> float:
|
|
|
|
"Les ECTS acquis par cette validation. (0 si ce n'est pas une validation d'UE)"
|
|
|
|
return (
|
2024-02-22 16:46:19 +01:00
|
|
|
self.ue.ects or 0.0
|
2023-07-17 10:37:12 +02:00
|
|
|
if (self.ue is not None) and (self.code in CODES_UE_VALIDES)
|
|
|
|
else 0.0
|
|
|
|
)
|
|
|
|
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
class ScolarAutorisationInscription(db.Model):
|
|
|
|
"""Autorisation d'inscription dans un semestre"""
|
|
|
|
|
|
|
|
__tablename__ = "scolar_autorisation_inscription"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
autorisation_inscription_id = db.synonym("id")
|
|
|
|
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
2022-05-26 03:55:03 +02:00
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
2022-02-06 16:09:17 +01:00
|
|
|
)
|
|
|
|
formation_code = db.Column(db.String(SHORT_STR_LEN), nullable=False)
|
2022-06-25 03:52:28 +02:00
|
|
|
# Indice du semestre où on peut s'inscrire:
|
2022-02-06 16:09:17 +01:00
|
|
|
semestre_id = db.Column(db.Integer)
|
|
|
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
origin_formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
2023-06-18 09:37:13 +02:00
|
|
|
origin_formsemestre = db.relationship("FormSemestre", lazy="select", uselist=False)
|
2022-02-06 16:09:17 +01:00
|
|
|
|
2023-01-11 13:37:02 +01:00
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f"""{self.__class__.__name__}(id={self.id}, etudid={
|
|
|
|
self.etudid}, semestre_id={self.semestre_id})"""
|
|
|
|
|
2022-07-07 16:24:52 +02:00
|
|
|
def to_dict(self) -> dict:
|
2022-10-01 10:39:46 +02:00
|
|
|
"as a dict"
|
2022-07-07 16:24:52 +02:00
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
|
|
|
return d
|
|
|
|
|
2023-06-18 09:37:13 +02:00
|
|
|
def html(self) -> str:
|
|
|
|
"Affichage html"
|
2023-06-30 17:26:41 +02:00
|
|
|
link = (
|
|
|
|
self.origin_formsemestre.html_link_status(
|
|
|
|
label=f"{self.origin_formsemestre.titre_formation(with_sem_idx=1)}",
|
|
|
|
title=self.origin_formsemestre.titre_annee(),
|
|
|
|
)
|
|
|
|
if self.origin_formsemestre
|
|
|
|
else "externe/antérieure"
|
|
|
|
)
|
2023-06-18 09:37:13 +02:00
|
|
|
return f"""Autorisation de passage vers <b>S{self.semestre_id}</b> émise par
|
2023-06-30 17:26:41 +02:00
|
|
|
{link}
|
2024-04-02 23:37:23 +02:00
|
|
|
le {self.date.strftime(scu.DATEATIME_FMT)}
|
|
|
|
"""
|
2023-06-18 09:37:13 +02:00
|
|
|
|
2022-06-25 03:52:28 +02:00
|
|
|
@classmethod
|
|
|
|
def autorise_etud(
|
|
|
|
cls,
|
|
|
|
etudid: int,
|
|
|
|
formation_code: str,
|
|
|
|
origin_formsemestre_id: int,
|
|
|
|
semestre_id: int,
|
|
|
|
):
|
2024-07-08 23:14:42 +02:00
|
|
|
"""Ajoute une autorisation (don't commit)"""
|
2022-06-25 03:52:28 +02:00
|
|
|
autorisation = cls(
|
|
|
|
etudid=etudid,
|
|
|
|
formation_code=formation_code,
|
|
|
|
origin_formsemestre_id=origin_formsemestre_id,
|
|
|
|
semestre_id=semestre_id,
|
|
|
|
)
|
|
|
|
db.session.add(autorisation)
|
2022-12-25 01:35:18 +01:00
|
|
|
Scolog.logdb(
|
|
|
|
"autorise_etud", etudid=etudid, msg=f"Passage vers S{semestre_id}: autorisé"
|
|
|
|
)
|
2023-01-11 19:09:03 +01:00
|
|
|
log(f"ScolarAutorisationInscription: recording {autorisation}")
|
2022-06-25 03:52:28 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def delete_autorisation_etud(
|
|
|
|
cls,
|
|
|
|
etudid: int,
|
|
|
|
origin_formsemestre_id: int,
|
|
|
|
):
|
2023-02-27 17:45:20 +01:00
|
|
|
"""Efface les autorisations de cet étudiant venant du sem. origine"""
|
2022-06-25 03:52:28 +02:00
|
|
|
autorisations = cls.query.filter_by(
|
|
|
|
etudid=etudid, origin_formsemestre_id=origin_formsemestre_id
|
|
|
|
)
|
|
|
|
for autorisation in autorisations:
|
|
|
|
db.session.delete(autorisation)
|
2023-01-11 19:09:03 +01:00
|
|
|
log(f"ScolarAutorisationInscription: deleting {autorisation}")
|
2022-06-25 03:52:28 +02:00
|
|
|
Scolog.logdb(
|
|
|
|
"autorise_etud",
|
|
|
|
etudid=etudid,
|
2022-12-25 01:35:18 +01:00
|
|
|
msg=f"Passage vers S{autorisation.semestre_id}: effacé",
|
2022-06-25 03:52:28 +02:00
|
|
|
)
|
|
|
|
db.session.flush()
|