2022-02-06 16:09:17 +01:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
|
|
|
"""Notes, décisions de jury, évènements scolaires
|
|
|
|
"""
|
|
|
|
|
|
|
|
from app import db
|
|
|
|
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
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ScolarFormSemestreValidation(db.Model):
|
|
|
|
"""Décisions de jury"""
|
|
|
|
|
|
|
|
__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)
|
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):
|
2022-06-20 17:56:27 +02:00
|
|
|
return f"{self.__class__.__name__}({self.formsemestre_id}, {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 !
|
|
|
|
return f"""décision sur UE {self.ue.acronyme if self.ue else self.ue_id}: {self.code}"""
|
2022-10-01 10:39:46 +02:00
|
|
|
return f"""décision sur semestre {self.formsemestre.titre_mois()} du {self.event_date.strftime("%d/%m/%Y")}"""
|
|
|
|
|
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
|
|
|
|
|
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"),
|
|
|
|
)
|
|
|
|
|
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
|
|
|
|
|
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,
|
|
|
|
):
|
|
|
|
"""Enregistre une autorisation, remplace celle émanant du même semestre si elle existe."""
|
|
|
|
cls.delete_autorisation_etud(etudid, origin_formsemestre_id)
|
|
|
|
autorisation = cls(
|
|
|
|
etudid=etudid,
|
|
|
|
formation_code=formation_code,
|
|
|
|
origin_formsemestre_id=origin_formsemestre_id,
|
|
|
|
semestre_id=semestre_id,
|
|
|
|
)
|
|
|
|
db.session.add(autorisation)
|
|
|
|
Scolog.logdb("autorise_etud", etudid=etudid, msg=f"passage vers S{semestre_id}")
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def delete_autorisation_etud(
|
|
|
|
cls,
|
|
|
|
etudid: int,
|
|
|
|
origin_formsemestre_id: int,
|
|
|
|
):
|
|
|
|
"""Efface les autorisations de cette étudiant venant du sem. origine"""
|
|
|
|
autorisations = cls.query.filter_by(
|
|
|
|
etudid=etudid, origin_formsemestre_id=origin_formsemestre_id
|
|
|
|
)
|
|
|
|
for autorisation in autorisations:
|
|
|
|
db.session.delete(autorisation)
|
|
|
|
Scolog.logdb(
|
|
|
|
"autorise_etud",
|
|
|
|
etudid=etudid,
|
|
|
|
msg=f"annule passage vers S{autorisation.semestre_id}",
|
|
|
|
)
|
|
|
|
db.session.flush()
|
|
|
|
|
2022-02-06 16:09:17 +01:00
|
|
|
|
|
|
|
class ScolarEvent(db.Model):
|
|
|
|
"""Evenement dans le parcours scolaire d'un étudiant"""
|
|
|
|
|
|
|
|
__tablename__ = "scolar_events"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
event_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
|
|
|
)
|
|
|
|
event_date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
|
|
|
ue_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_ue.id"),
|
|
|
|
)
|
|
|
|
# 'CREATION', 'INSCRIPTION', 'DEMISSION',
|
|
|
|
# 'AUT_RED', 'EXCLUS', 'VALID_UE', 'VALID_SEM'
|
|
|
|
# 'ECHEC_SEM'
|
|
|
|
# 'UTIL_COMPENSATION'
|
|
|
|
event_type = db.Column(db.String(SHORT_STR_LEN))
|
|
|
|
# Semestre compensé par formsemestre_id:
|
|
|
|
comp_formsemestre_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_formsemestre.id"),
|
|
|
|
)
|
2022-09-30 22:43:39 +02:00
|
|
|
etud = db.relationship("Identite", lazy="select", backref="events", uselist=False)
|
|
|
|
formsemestre = db.relationship(
|
|
|
|
"FormSemestre", lazy="select", uselist=False, foreign_keys=[formsemestre_id]
|
|
|
|
)
|
2022-07-07 16:24:52 +02:00
|
|
|
|
|
|
|
def to_dict(self) -> dict:
|
2022-09-30 22:43:39 +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
|
2022-09-30 22:43:39 +02:00
|
|
|
|
|
|
|
def __repr__(self) -> str:
|
|
|
|
return f"{self.__class__.__name__}({self.event_type}, {self.event_date.isoformat()}, {self.formsemestre})"
|