2022-10-28 11:42:52 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
"""Gestion de l'assiduité (assiduités + justificatifs)
|
|
|
|
"""
|
|
|
|
from app import db
|
2022-12-14 17:41:57 +01:00
|
|
|
from app.models import ModuleImpl, ModuleImplInscription
|
2022-11-03 10:29:30 +01:00
|
|
|
from app.models.etudiants import Identite
|
2023-01-05 17:47:32 +01:00
|
|
|
from app.scodoc.sco_utils import EtatAssiduite, localize_datetime, is_period_overlapping
|
|
|
|
from app.scodoc.sco_exceptions import ScoValueError
|
2022-11-03 10:29:30 +01:00
|
|
|
from datetime import datetime
|
2022-10-28 11:42:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Assiduite(db.Model):
|
|
|
|
"""
|
|
|
|
Représente une assiduité:
|
|
|
|
- une plage horaire lié à un état et un étudiant
|
|
|
|
- un module si spécifiée
|
2023-01-30 15:12:31 +01:00
|
|
|
- une description si spécifiée
|
2022-10-28 11:42:52 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "assiduites"
|
|
|
|
|
2022-11-03 10:29:30 +01:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2023-01-05 17:47:32 +01:00
|
|
|
assiduite_id = db.synonym("id")
|
2022-10-28 11:42:52 +02:00
|
|
|
|
|
|
|
date_debut = db.Column(
|
|
|
|
db.DateTime(timezone=True), server_default=db.func.now(), nullable=False
|
|
|
|
)
|
|
|
|
date_fin = db.Column(
|
|
|
|
db.DateTime(timezone=True), server_default=db.func.now(), nullable=False
|
|
|
|
)
|
|
|
|
|
|
|
|
moduleimpl_id = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("notes_moduleimpl.id", ondelete="SET NULL"),
|
|
|
|
)
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
|
|
|
index=True,
|
|
|
|
nullable=False,
|
|
|
|
)
|
2022-11-03 10:29:30 +01:00
|
|
|
etat = db.Column(db.Integer, nullable=False)
|
2022-10-28 11:42:52 +02:00
|
|
|
|
2023-01-30 15:12:31 +01:00
|
|
|
desc = db.Column(db.Text)
|
|
|
|
|
2022-10-28 11:42:52 +02:00
|
|
|
def to_dict(self) -> dict:
|
|
|
|
data = {
|
2023-01-05 17:47:32 +01:00
|
|
|
"assiduite_id": self.assiduite_id,
|
2022-10-28 11:42:52 +02:00
|
|
|
"etudid": self.etudid,
|
2022-11-03 10:29:30 +01:00
|
|
|
"moduleimpl_id": self.moduleimpl_id,
|
2022-10-28 11:42:52 +02:00
|
|
|
"date_debut": self.date_debut,
|
|
|
|
"date_fin": self.date_fin,
|
|
|
|
"etat": self.etat,
|
2023-01-30 15:12:31 +01:00
|
|
|
"desc": self.desc,
|
2022-10-28 11:42:52 +02:00
|
|
|
}
|
|
|
|
return data
|
|
|
|
|
2022-11-03 10:29:30 +01:00
|
|
|
@classmethod
|
|
|
|
def create_assiduite(
|
|
|
|
cls,
|
|
|
|
etud: Identite,
|
|
|
|
date_debut: datetime,
|
|
|
|
date_fin: datetime,
|
|
|
|
etat: EtatAssiduite,
|
2023-01-05 17:47:32 +01:00
|
|
|
moduleimpl: ModuleImpl = None,
|
2023-01-30 15:12:31 +01:00
|
|
|
description: str = None,
|
2022-11-03 10:29:30 +01:00
|
|
|
) -> object or int:
|
2023-01-05 17:47:32 +01:00
|
|
|
"""Créer une nouvelle assiduité pour l'étudiant"""
|
2022-11-03 10:29:30 +01:00
|
|
|
# Vérification de non duplication des périodes
|
2022-12-14 17:41:57 +01:00
|
|
|
assiduites: list[Assiduite] = etud.assiduites.all()
|
2022-12-19 21:32:45 +01:00
|
|
|
|
|
|
|
date_debut = localize_datetime(date_debut)
|
|
|
|
date_fin = localize_datetime(date_fin)
|
2022-11-03 10:29:30 +01:00
|
|
|
assiduites = [
|
|
|
|
ass
|
|
|
|
for ass in assiduites
|
2023-01-05 17:47:32 +01:00
|
|
|
if is_period_overlapping(
|
2022-12-19 21:32:45 +01:00
|
|
|
(date_debut, date_fin),
|
2022-12-14 17:41:57 +01:00
|
|
|
(ass.date_debut, ass.date_fin),
|
|
|
|
)
|
2022-11-03 10:29:30 +01:00
|
|
|
]
|
|
|
|
if len(assiduites) != 0:
|
2023-01-05 17:47:32 +01:00
|
|
|
raise ScoValueError(
|
|
|
|
"Duplication des assiduités (la période rentrée rentre en conflit avec une assiduité enregistrée)"
|
|
|
|
)
|
2022-11-03 10:29:30 +01:00
|
|
|
|
2023-01-05 17:47:32 +01:00
|
|
|
if moduleimpl is not None:
|
|
|
|
# Vérification de l'existence du module pour l'étudiant
|
|
|
|
if moduleimpl.est_inscrit(etud):
|
2022-11-03 10:29:30 +01:00
|
|
|
nouv_assiduite = Assiduite(
|
2022-12-14 17:41:57 +01:00
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
2022-11-03 10:29:30 +01:00
|
|
|
etat=etat,
|
|
|
|
etudiant=etud,
|
2023-01-05 17:47:32 +01:00
|
|
|
moduleimpl_id=moduleimpl.id,
|
2023-01-30 15:12:31 +01:00
|
|
|
desc=description,
|
2022-11-03 10:29:30 +01:00
|
|
|
)
|
|
|
|
else:
|
2023-01-05 17:47:32 +01:00
|
|
|
raise ScoValueError("L'étudiant n'est pas inscrit au moduleimpl")
|
2022-11-03 10:29:30 +01:00
|
|
|
else:
|
|
|
|
nouv_assiduite = Assiduite(
|
2022-12-19 21:32:45 +01:00
|
|
|
date_debut=date_debut,
|
|
|
|
date_fin=date_fin,
|
2022-11-03 10:29:30 +01:00
|
|
|
etat=etat,
|
|
|
|
etudiant=etud,
|
2023-01-30 15:12:31 +01:00
|
|
|
desc=description,
|
2022-11-03 10:29:30 +01:00
|
|
|
)
|
2022-12-14 17:41:57 +01:00
|
|
|
|
2022-11-03 10:29:30 +01:00
|
|
|
return nouv_assiduite
|
|
|
|
|
2022-10-28 11:42:52 +02:00
|
|
|
|
|
|
|
class Justificatif(db.Model):
|
|
|
|
"""
|
|
|
|
Représente un justificatif:
|
|
|
|
- une plage horaire lié à un état et un étudiant
|
|
|
|
- une raison si spécifiée
|
|
|
|
- un fichier si spécifié
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "justificatifs"
|
|
|
|
|
2023-01-05 17:47:32 +01:00
|
|
|
justif_id = db.Column(db.Integer, primary_key=True)
|
2022-10-28 11:42:52 +02:00
|
|
|
|
|
|
|
date_debut = db.Column(
|
|
|
|
db.DateTime(timezone=True), server_default=db.func.now(), nullable=False
|
|
|
|
)
|
|
|
|
date_fin = db.Column(
|
|
|
|
db.DateTime(timezone=True), server_default=db.func.now(), nullable=False
|
|
|
|
)
|
|
|
|
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
|
|
|
index=True,
|
|
|
|
nullable=False,
|
|
|
|
)
|
|
|
|
etat = db.Column(
|
|
|
|
db.Integer,
|
|
|
|
)
|
|
|
|
|
|
|
|
raison = db.Column(db.Text())
|
2023-01-05 17:47:32 +01:00
|
|
|
|
|
|
|
"""
|
2023-01-30 15:12:31 +01:00
|
|
|
Les justificatifs sont enregistrés dans
|
|
|
|
<archivedir>/justificatifs/<dept_id>/<etudid>/<nom_fichier.extension>
|
2023-01-05 17:47:32 +01:00
|
|
|
|
2023-01-30 15:12:31 +01:00
|
|
|
d'après sco_archives.py#JustificatifArchiver
|
2023-01-05 17:47:32 +01:00
|
|
|
"""
|
2023-01-30 15:12:31 +01:00
|
|
|
fichier = db.Column(db.Text())
|
2022-10-28 11:42:52 +02:00
|
|
|
|
|
|
|
def to_dict(self) -> dict:
|
|
|
|
data = {
|
2023-01-05 17:47:32 +01:00
|
|
|
"justif_id": self.assiduite_id,
|
2022-10-28 11:42:52 +02:00
|
|
|
"etudid": self.etudid,
|
|
|
|
"date_debut": self.date_debut,
|
|
|
|
"date_fin": self.date_fin,
|
|
|
|
"etat": self.etat,
|
2022-11-03 10:29:30 +01:00
|
|
|
"raison": self.raison,
|
|
|
|
"fichier": self.fichier,
|
2022-10-28 11:42:52 +02:00
|
|
|
}
|
|
|
|
return data
|