2021-08-07 15:20:30 +02:00
|
|
|
# -*- coding: UTF-8 -*
|
|
|
|
|
|
|
|
"""Définition d'un étudiant
|
|
|
|
et données rattachées (adresses, annotations, ...)
|
|
|
|
"""
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
import datetime
|
2021-12-26 19:15:47 +01:00
|
|
|
from functools import cached_property
|
2023-03-18 21:56:08 +01:00
|
|
|
from operator import attrgetter
|
|
|
|
|
2022-08-07 19:56:25 +02:00
|
|
|
from flask import abort, has_request_context, url_for
|
2021-12-26 19:15:47 +01:00
|
|
|
from flask import g, request
|
2022-02-11 18:27:10 +01:00
|
|
|
import sqlalchemy
|
2022-03-06 22:40:20 +01:00
|
|
|
from sqlalchemy import desc, text
|
2021-12-21 15:33:21 +01:00
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
from app import db, log
|
2021-12-14 23:03:59 +01:00
|
|
|
from app import models
|
2023-11-23 17:08:18 +01:00
|
|
|
from app.models.departements import Departement
|
2023-11-22 23:31:16 +01:00
|
|
|
from app.models.scolar_event import ScolarEvent
|
2021-12-30 23:58:38 +01:00
|
|
|
from app.scodoc import notesdb as ndb
|
2022-01-09 21:02:07 +01:00
|
|
|
from app.scodoc.sco_bac import Baccalaureat
|
2024-02-02 18:23:35 +01:00
|
|
|
from app.scodoc.sco_exceptions import ScoGenError, ScoInvalidParamError, ScoValueError
|
2022-02-12 22:57:46 +01:00
|
|
|
import app.scodoc.sco_utils as scu
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
2023-12-22 15:21:07 +01:00
|
|
|
class Identite(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""étudiant"""
|
|
|
|
|
|
|
|
__tablename__ = "identite"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
etudid = db.synonym("id")
|
|
|
|
|
2023-10-25 23:07:34 +02:00
|
|
|
# ForeignKey ondelete set the cascade at the database level
|
|
|
|
admission_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("admissions.id", ondelete="CASCADE"), nullable=True
|
|
|
|
)
|
2023-10-15 14:42:03 +02:00
|
|
|
admission = db.relationship(
|
|
|
|
"Admission",
|
|
|
|
back_populates="etud",
|
|
|
|
uselist=False,
|
2023-10-25 23:07:34 +02:00
|
|
|
cascade="all,delete", # cascade also defined at ORM level
|
2023-10-15 14:42:03 +02:00
|
|
|
single_parent=True,
|
|
|
|
)
|
|
|
|
dept_id = db.Column(
|
|
|
|
db.Integer, db.ForeignKey("departement.id"), index=True, nullable=False
|
|
|
|
)
|
|
|
|
departement = db.relationship("Departement", back_populates="etudiants")
|
2021-08-07 15:20:30 +02:00
|
|
|
nom = db.Column(db.Text())
|
|
|
|
prenom = db.Column(db.Text())
|
|
|
|
nom_usuel = db.Column(db.Text())
|
2023-03-12 21:22:19 +01:00
|
|
|
"optionnel (si present, affiché à la place du nom)"
|
2021-08-07 15:20:30 +02:00
|
|
|
civilite = db.Column(db.String(1), nullable=False)
|
2023-03-13 06:39:36 +01:00
|
|
|
|
2023-10-16 22:51:31 +02:00
|
|
|
# données d'état-civil. Si présent (non null) remplace les données d'usage dans les documents
|
2023-06-01 17:58:30 +02:00
|
|
|
# officiels (bulletins, PV): voir nomprenom_etat_civil()
|
2023-10-16 22:51:31 +02:00
|
|
|
civilite_etat_civil = db.Column(db.String(1), nullable=True)
|
|
|
|
prenom_etat_civil = db.Column(db.Text(), nullable=True)
|
2023-03-13 06:39:36 +01:00
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
date_naissance = db.Column(db.Date)
|
|
|
|
lieu_naissance = db.Column(db.Text())
|
|
|
|
dept_naissance = db.Column(db.Text())
|
|
|
|
nationalite = db.Column(db.Text())
|
|
|
|
statut = db.Column(db.Text())
|
2023-10-15 14:42:03 +02:00
|
|
|
boursier = db.Column(
|
|
|
|
db.Boolean(), nullable=False, default=False, server_default="false"
|
|
|
|
)
|
|
|
|
"True si boursier"
|
2021-08-07 15:20:30 +02:00
|
|
|
photo_filename = db.Column(db.Text())
|
2021-08-15 22:20:07 +02:00
|
|
|
# Codes INE et NIP pas unique car le meme etud peut etre ds plusieurs dept
|
2022-01-10 15:15:26 +01:00
|
|
|
code_nip = db.Column(db.Text(), index=True)
|
|
|
|
code_ine = db.Column(db.Text(), index=True)
|
2021-08-27 22:16:10 +02:00
|
|
|
# Ancien id ScoDoc7 pour les migrations de bases anciennes
|
2021-11-01 15:16:51 +01:00
|
|
|
# ne pas utiliser après migrate_scodoc7_dept_archives
|
2021-08-27 22:16:10 +02:00
|
|
|
scodoc7_id = db.Column(db.Text(), nullable=True)
|
2023-10-15 14:42:03 +02:00
|
|
|
|
|
|
|
# ----- Contraintes
|
|
|
|
__table_args__ = (
|
|
|
|
# Define a unique constraint on (dept_id, code_nip) when code_nip is not NULL
|
|
|
|
db.UniqueConstraint("dept_id", "code_nip", name="unique_dept_nip_except_null"),
|
|
|
|
db.Index(
|
|
|
|
"unique_dept_nip_except_null",
|
|
|
|
"dept_id",
|
|
|
|
"code_nip",
|
|
|
|
unique=True,
|
|
|
|
postgresql_where=(code_nip.isnot(None)),
|
|
|
|
),
|
|
|
|
# Define a unique constraint on (dept_id, code_ine) when code_ine is not NULL
|
|
|
|
db.UniqueConstraint("dept_id", "code_ine", name="unique_dept_ine_except_null"),
|
|
|
|
db.Index(
|
|
|
|
"unique_dept_ine_except_null",
|
|
|
|
"dept_id",
|
|
|
|
"code_ine",
|
|
|
|
unique=True,
|
|
|
|
postgresql_where=(code_ine.isnot(None)),
|
|
|
|
),
|
2023-10-17 22:12:28 +02:00
|
|
|
db.CheckConstraint("civilite IN ('M', 'F', 'X')"), # non nullable
|
|
|
|
db.CheckConstraint("civilite_etat_civil IN ('M', 'F', 'X')"), # nullable
|
2023-10-15 14:42:03 +02:00
|
|
|
)
|
|
|
|
# ----- Relations
|
|
|
|
adresses = db.relationship(
|
|
|
|
"Adresse", back_populates="etud", cascade="all,delete", lazy="dynamic"
|
|
|
|
)
|
2024-02-11 12:05:43 +01:00
|
|
|
annotations = db.relationship(
|
|
|
|
"EtudAnnotation",
|
|
|
|
backref="etudiant",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2021-09-28 09:14:04 +02:00
|
|
|
billets = db.relationship("BilletAbsence", backref="etudiant", lazy="dynamic")
|
2022-05-18 20:43:01 +02:00
|
|
|
#
|
2022-12-01 13:00:14 +01:00
|
|
|
dispense_ues = db.relationship(
|
|
|
|
"DispenseUE",
|
|
|
|
back_populates="etud",
|
|
|
|
cascade="all, delete",
|
|
|
|
passive_deletes=True,
|
|
|
|
)
|
2024-09-09 16:21:51 +02:00
|
|
|
itemsuivis = db.relationship(
|
|
|
|
"ItemSuivi",
|
|
|
|
backref="etudiant",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2024-11-04 21:26:18 +01:00
|
|
|
notes = db.relationship(
|
|
|
|
"NotesNotes",
|
|
|
|
backref="etudiant",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2024-11-08 00:15:39 +01:00
|
|
|
notes_log = db.relationship(
|
|
|
|
"NotesNotesLog",
|
|
|
|
backref="etudiant",
|
|
|
|
cascade="all, delete-orphan",
|
|
|
|
lazy="dynamic",
|
|
|
|
)
|
2023-04-17 15:34:00 +02:00
|
|
|
# Relations avec les assiduites et les justificatifs
|
2023-09-05 08:41:40 +02:00
|
|
|
assiduites = db.relationship(
|
|
|
|
"Assiduite", back_populates="etudiant", lazy="dynamic", cascade="all, delete"
|
|
|
|
)
|
2023-07-29 18:32:29 +02:00
|
|
|
justificatifs = db.relationship(
|
2023-09-05 08:41:40 +02:00
|
|
|
"Justificatif", back_populates="etudiant", lazy="dynamic", cascade="all, delete"
|
2023-07-29 18:32:29 +02:00
|
|
|
)
|
2023-04-17 15:34:00 +02:00
|
|
|
|
2024-01-20 14:49:36 +01:00
|
|
|
# Champs "protégés" par ViewEtudData (RGPD)
|
2024-02-19 14:10:55 +01:00
|
|
|
protected_attrs = {"boursier", "nationalite"}
|
2024-01-20 14:49:36 +01:00
|
|
|
|
2021-11-20 16:35:09 +01:00
|
|
|
def __repr__(self):
|
2022-05-21 07:41:09 +02:00
|
|
|
return (
|
|
|
|
f"<Etud {self.id}/{self.departement.acronym} {self.nom!r} {self.prenom!r}>"
|
|
|
|
)
|
2021-11-20 16:35:09 +01:00
|
|
|
|
2023-09-25 23:51:38 +02:00
|
|
|
def clone(self, not_copying=(), new_dept_id: int = None):
|
|
|
|
"""Clone, not copying the given attrs
|
2023-10-08 10:01:23 +02:00
|
|
|
Clone aussi les adresses et infos d'admission.
|
2023-09-25 23:51:38 +02:00
|
|
|
Si new_dept_id est None, le nouvel étudiant n'a pas de département.
|
|
|
|
Attention: la copie n'a pas d'id avant le prochain flush ou commit.
|
|
|
|
"""
|
|
|
|
if new_dept_id == self.dept_id:
|
|
|
|
raise ScoValueError(
|
|
|
|
"clonage étudiant: le département destination est identique à celui de départ"
|
|
|
|
)
|
2023-09-26 22:40:34 +02:00
|
|
|
# Vérifie les contraintes d'unicité
|
|
|
|
# ("dept_id", "code_nip") et ("dept_id", "code_ine")
|
|
|
|
if (
|
|
|
|
self.code_nip is not None
|
|
|
|
and Identite.query.filter_by(
|
|
|
|
dept_id=new_dept_id, code_nip=self.code_nip
|
|
|
|
).count()
|
|
|
|
> 0
|
|
|
|
) or (
|
|
|
|
self.code_ine is not None
|
|
|
|
and Identite.query.filter_by(
|
|
|
|
dept_id=new_dept_id, code_ine=self.code_ine
|
|
|
|
).count()
|
|
|
|
> 0
|
|
|
|
):
|
|
|
|
raise ScoValueError(
|
2023-10-25 23:07:34 +02:00
|
|
|
"""clonage étudiant: un étudiant de même code existe déjà
|
2023-09-26 22:40:34 +02:00
|
|
|
dans le département destination"""
|
|
|
|
)
|
2023-09-25 23:51:38 +02:00
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("id", None) # get rid of id
|
|
|
|
d.pop("_sa_instance_state", None) # get rid of SQLAlchemy special attr
|
|
|
|
d.pop("departement", None) # relationship
|
|
|
|
d["dept_id"] = new_dept_id
|
|
|
|
for k in not_copying:
|
|
|
|
d.pop(k, None)
|
|
|
|
copy = self.__class__(**d)
|
|
|
|
db.session.add(copy)
|
2023-10-08 10:01:23 +02:00
|
|
|
copy.adresses = [adr.clone() for adr in self.adresses]
|
2023-10-15 14:42:03 +02:00
|
|
|
copy.admission = self.admission.clone()
|
2023-09-25 23:51:38 +02:00
|
|
|
log(
|
|
|
|
f"cloning etud <{self.id} {self.nom!r} {self.prenom!r}> in dept_id={new_dept_id}"
|
|
|
|
)
|
|
|
|
return copy
|
|
|
|
|
2023-06-19 22:07:31 +02:00
|
|
|
def html_link_fiche(self) -> str:
|
|
|
|
"lien vers la fiche"
|
2024-07-06 23:28:20 +02:00
|
|
|
return (
|
|
|
|
f"""<a class="etudlink" href="{self.url_fiche()}">{self.nom_prenom()}</a>"""
|
|
|
|
)
|
2023-11-22 23:31:16 +01:00
|
|
|
|
|
|
|
def url_fiche(self) -> str:
|
|
|
|
"url de la fiche étudiant"
|
|
|
|
return url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=self.departement.acronym, etudid=self.id
|
2023-11-22 23:31:16 +01:00
|
|
|
)
|
2023-06-19 22:07:31 +02:00
|
|
|
|
2021-12-26 19:15:47 +01:00
|
|
|
@classmethod
|
2023-03-20 11:17:38 +01:00
|
|
|
def from_request(cls, etudid=None, code_nip=None) -> "Identite":
|
2022-09-03 11:41:56 +02:00
|
|
|
"""Étudiant à partir de l'etudid ou du code_nip, soit
|
2021-12-26 19:15:47 +01:00
|
|
|
passés en argument soit retrouvés directement dans la requête web.
|
|
|
|
Erreur 404 si inexistant.
|
|
|
|
"""
|
|
|
|
args = make_etud_args(etudid=etudid, code_nip=code_nip)
|
2023-03-20 11:17:38 +01:00
|
|
|
return cls.query.filter_by(**args).first_or_404()
|
|
|
|
|
|
|
|
@classmethod
|
2024-06-30 23:00:42 +02:00
|
|
|
def get_etud(cls, etudid: int, accept_none=False) -> "Identite":
|
|
|
|
"""Etudiant ou 404 (ou None si accept_none),
|
|
|
|
cherche uniquement dans le département courant.
|
|
|
|
Si accept_none, return None si l'id est invalide ou ne correspond
|
|
|
|
pas à un étudiant.
|
|
|
|
"""
|
2024-06-01 14:27:02 +02:00
|
|
|
if not isinstance(etudid, int):
|
|
|
|
try:
|
|
|
|
etudid = int(etudid)
|
|
|
|
except (TypeError, ValueError):
|
2024-06-30 23:00:42 +02:00
|
|
|
if accept_none:
|
|
|
|
return None
|
2024-09-10 23:16:27 +02:00
|
|
|
abort(404, f"etudid invalide {request.url if request else ''}")
|
2024-06-30 23:00:42 +02:00
|
|
|
|
|
|
|
query = (
|
|
|
|
cls.query.filter_by(id=etudid, dept_id=g.scodoc_dept_id)
|
|
|
|
if g.scodoc_dept
|
|
|
|
else cls.query.filter_by(id=etudid)
|
|
|
|
)
|
|
|
|
if accept_none:
|
|
|
|
return query.first()
|
|
|
|
return query.first_or_404()
|
2021-12-26 19:15:47 +01:00
|
|
|
|
2022-12-07 23:04:11 +01:00
|
|
|
@classmethod
|
2023-10-15 14:42:03 +02:00
|
|
|
def create_etud(cls, **args) -> "Identite":
|
2023-10-18 14:28:43 +02:00
|
|
|
"""Crée un étudiant, avec admission et adresse vides.
|
|
|
|
(added to session but not flushed nor commited)
|
|
|
|
"""
|
|
|
|
return cls.create_from_dict(args)
|
2023-10-15 14:42:03 +02:00
|
|
|
|
|
|
|
@classmethod
|
2023-11-23 17:08:18 +01:00
|
|
|
def create_from_dict(cls, args) -> "Identite":
|
2023-10-15 14:42:03 +02:00
|
|
|
"""Crée un étudiant à partir d'un dict, avec admission et adresse vides.
|
2023-11-23 17:08:18 +01:00
|
|
|
If required dept_id or dept are not specified, set it to the current dept.
|
|
|
|
args: dict with args in application.
|
|
|
|
Les clés adresses et admission ne SONT PAS utilisées.
|
2023-10-15 14:42:03 +02:00
|
|
|
(added to session but not flushed nor commited)
|
|
|
|
"""
|
2024-09-04 04:09:31 +02:00
|
|
|
check_etud_duplicate_code(args, "code_nip", dest_url=None)
|
|
|
|
check_etud_duplicate_code(args, "code_ine", dest_url=None)
|
2023-11-23 17:08:18 +01:00
|
|
|
if not "dept_id" in args:
|
|
|
|
if "dept" in args:
|
|
|
|
departement = Departement.query.filter_by(acronym=args["dept"]).first()
|
|
|
|
if departement:
|
|
|
|
args["dept_id"] = departement.id
|
|
|
|
if not "dept_id" in args:
|
|
|
|
args["dept_id"] = g.scodoc_dept_id
|
|
|
|
etud: Identite = super().create_from_dict(args)
|
|
|
|
if args.get("admission_id", None) is None:
|
2023-10-15 14:42:03 +02:00
|
|
|
etud.admission = Admission()
|
|
|
|
etud.adresses.append(Adresse(typeadresse="domicile"))
|
2024-09-04 04:09:31 +02:00
|
|
|
try:
|
|
|
|
db.session.flush()
|
|
|
|
except sqlalchemy.exc.IntegrityError as e:
|
|
|
|
db.session.rollback()
|
|
|
|
if "unique_dept_nip_except_null" in str(e):
|
|
|
|
raise ScoValueError(
|
|
|
|
"Code NIP déjà utilisé pour un autre étudiant"
|
|
|
|
) from e
|
|
|
|
if "unique_dept_ine_except_null" in str(e):
|
|
|
|
raise ScoValueError(
|
|
|
|
"Code INE déjà utilisé pour un autre étudiant"
|
|
|
|
) from e
|
|
|
|
raise
|
2023-11-22 23:31:16 +01:00
|
|
|
event = ScolarEvent(etud=etud, event_type="CREATION")
|
|
|
|
db.session.add(event)
|
|
|
|
log(f"Identite.create {etud}")
|
2022-12-07 23:04:11 +01:00
|
|
|
return etud
|
|
|
|
|
2024-02-02 18:23:35 +01:00
|
|
|
def from_dict(self, args, **kwargs) -> bool:
|
|
|
|
"""Check arguments, then modify.
|
|
|
|
Add to session but don't commit.
|
|
|
|
True if modification.
|
|
|
|
"""
|
2024-08-23 04:30:53 +02:00
|
|
|
check_etud_duplicate_code(args, "code_nip", etudid=self.id)
|
|
|
|
check_etud_duplicate_code(args, "code_ine", etudid=self.id)
|
2024-02-02 18:23:35 +01:00
|
|
|
return super().from_dict(args, **kwargs)
|
|
|
|
|
2023-11-23 17:08:18 +01:00
|
|
|
@classmethod
|
|
|
|
def filter_model_attributes(cls, data: dict, excluded: set[str] = None) -> dict:
|
|
|
|
"""Returns a copy of dict with only the keys belonging to the Model and not in excluded."""
|
|
|
|
return super().filter_model_attributes(
|
|
|
|
data,
|
|
|
|
excluded=(excluded or set()) | {"adresses", "admission", "departement"},
|
|
|
|
)
|
|
|
|
|
2021-12-26 19:15:47 +01:00
|
|
|
@property
|
2023-10-17 22:12:28 +02:00
|
|
|
def civilite_str(self) -> str:
|
|
|
|
"""returns civilité usuelle: 'M.' ou 'Mme' ou '' (pour le genre neutre,
|
2021-12-04 21:04:09 +01:00
|
|
|
personnes ne souhaitant pas d'affichage).
|
|
|
|
"""
|
|
|
|
return {"M": "M.", "F": "Mme", "X": ""}[self.civilite]
|
|
|
|
|
2023-03-13 06:39:36 +01:00
|
|
|
@property
|
2023-10-17 22:12:28 +02:00
|
|
|
def civilite_etat_civil_str(self) -> str:
|
|
|
|
"""returns 'M.' ou 'Mme', selon état civil officiel.
|
|
|
|
La France ne reconnait pas le genre neutre dans l'état civil:
|
|
|
|
si cette donnée état civil est précisée, elle est utilisée,
|
|
|
|
sinon on renvoie la civilité usuelle.
|
2023-03-13 06:39:36 +01:00
|
|
|
"""
|
2023-10-17 22:12:28 +02:00
|
|
|
return (
|
|
|
|
{"M": "M.", "F": "Mme"}.get(self.civilite_etat_civil, "")
|
|
|
|
if self.civilite_etat_civil
|
|
|
|
else self.civilite_str
|
|
|
|
)
|
2023-03-13 06:39:36 +01:00
|
|
|
|
2022-02-12 22:57:46 +01:00
|
|
|
def sex_nom(self, no_accents=False) -> str:
|
2023-10-17 22:12:28 +02:00
|
|
|
"'M. DUPONTÉ', ou si no_accents, 'M. DUPONTE'. Civilité usuelle."
|
2022-02-12 22:57:46 +01:00
|
|
|
s = f"{self.civilite_str} {(self.nom_usuel or self.nom).upper()}"
|
|
|
|
if no_accents:
|
|
|
|
return scu.suppress_accents(s)
|
|
|
|
return s
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
@property
|
2023-10-17 22:12:28 +02:00
|
|
|
def e(self) -> str:
|
|
|
|
"terminaison en français: 'ne', '', 'ou '(e)', selon la civilité usuelle"
|
2022-03-06 22:40:20 +01:00
|
|
|
return {"M": "", "F": "e"}.get(self.civilite, "(e)")
|
|
|
|
|
2021-12-26 19:15:47 +01:00
|
|
|
def nom_disp(self) -> str:
|
2023-10-17 22:12:28 +02:00
|
|
|
"""Nom à afficher.
|
|
|
|
Note: le nom est stocké en base en majuscules."""
|
2021-12-04 21:04:09 +01:00
|
|
|
if self.nom_usuel:
|
|
|
|
return (
|
|
|
|
(self.nom_usuel + " (" + self.nom + ")") if self.nom else self.nom_usuel
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
return self.nom
|
|
|
|
|
2024-04-05 11:00:01 +02:00
|
|
|
@property
|
2021-12-26 19:15:47 +01:00
|
|
|
def nomprenom(self, reverse=False) -> str:
|
2024-07-06 23:28:20 +02:00
|
|
|
"""DEPRECATED: préférer nom_prenom()
|
2024-05-29 10:48:34 +02:00
|
|
|
Civilité/prénom/nom pour affichages: "M. Pierre Dupont"
|
2021-12-26 19:15:47 +01:00
|
|
|
Si reverse, "Dupont Pierre", sans civilité.
|
2024-05-29 10:48:34 +02:00
|
|
|
Prend l'identité courante et non celle de l'état civil si elles diffèrent.
|
2021-12-26 19:15:47 +01:00
|
|
|
"""
|
|
|
|
nom = self.nom_usuel or self.nom
|
|
|
|
prenom = self.prenom_str
|
|
|
|
if reverse:
|
2023-11-29 17:13:21 +01:00
|
|
|
return f"{nom} {prenom}".strip()
|
|
|
|
return f"{self.civilite_str} {prenom} {nom}".strip()
|
2021-12-26 19:15:47 +01:00
|
|
|
|
2024-05-29 10:48:34 +02:00
|
|
|
def nom_prenom(self) -> str:
|
|
|
|
"""Civilite NOM Prénom
|
|
|
|
Prend l'identité courante et non celle de l'état civil si elles diffèrent.
|
|
|
|
"""
|
|
|
|
return f"{self.civilite_str} {(self.nom_usuel or self.nom).upper()} {self.prenom_str}"
|
|
|
|
|
2021-12-26 19:15:47 +01:00
|
|
|
@property
|
|
|
|
def prenom_str(self):
|
|
|
|
"""Prénom à afficher. Par exemple: "Jean-Christophe" """
|
|
|
|
if not self.prenom:
|
|
|
|
return ""
|
|
|
|
frags = self.prenom.split()
|
|
|
|
r = []
|
|
|
|
for frag in frags:
|
|
|
|
fields = frag.split("-")
|
|
|
|
r.append("-".join([x.lower().capitalize() for x in fields]))
|
|
|
|
return " ".join(r)
|
|
|
|
|
2023-03-13 06:39:36 +01:00
|
|
|
@property
|
2023-10-17 22:12:28 +02:00
|
|
|
def etat_civil(self) -> str:
|
2023-11-29 17:13:21 +01:00
|
|
|
"M. PRÉNOM NOM, utilisant les données état civil si présentes, usuelles sinon."
|
|
|
|
return f"""{self.civilite_etat_civil_str} {
|
|
|
|
self.prenom_etat_civil or self.prenom or ''} {
|
|
|
|
self.nom or ''}""".strip()
|
2023-03-13 06:39:36 +01:00
|
|
|
|
2022-03-26 23:33:57 +01:00
|
|
|
@property
|
|
|
|
def nom_short(self):
|
|
|
|
"Nom et début du prénom pour table recap: 'DUPONT Pi.'"
|
|
|
|
return f"{(self.nom_usuel or self.nom or '?').upper()} {(self.prenom or '')[:2].capitalize()}."
|
|
|
|
|
2021-12-30 23:58:38 +01:00
|
|
|
@cached_property
|
2024-03-24 14:34:55 +01:00
|
|
|
def sort_key(self) -> str:
|
2021-12-30 23:58:38 +01:00
|
|
|
"clé pour tris par ordre alphabétique"
|
2023-12-09 15:53:45 +01:00
|
|
|
# Note: scodoc7 utilisait sco_etud.etud_sort_key, à mettre à jour
|
|
|
|
# si on modifie cette méthode.
|
2024-03-24 14:34:55 +01:00
|
|
|
return scu.sanitize_string(
|
|
|
|
(self.nom_usuel or self.nom or "") + ";" + (self.prenom or ""),
|
|
|
|
remove_spaces=False,
|
|
|
|
).lower()
|
2021-12-30 23:58:38 +01:00
|
|
|
|
2021-12-11 16:46:15 +01:00
|
|
|
def get_first_email(self, field="email") -> str:
|
2023-03-18 21:56:08 +01:00
|
|
|
"Le mail associé à la première adresse de l'étudiant, ou None"
|
2022-03-06 22:40:20 +01:00
|
|
|
return getattr(self.adresses[0], field) if self.adresses.count() > 0 else None
|
2021-12-11 16:46:15 +01:00
|
|
|
|
2024-06-07 17:58:02 +02:00
|
|
|
def get_formsemestres(self, recent_first=True) -> list:
|
2023-03-18 21:56:08 +01:00
|
|
|
"""Liste des formsemestres dans lesquels l'étudiant est (a été) inscrit,
|
2024-06-07 17:58:02 +02:00
|
|
|
triée par date_debut, le plus récent d'abord (comme "sems" de scodoc7)
|
|
|
|
(si recent_first=False, le plus ancien en tête)
|
2023-03-18 21:56:08 +01:00
|
|
|
"""
|
|
|
|
return sorted(
|
|
|
|
[ins.formsemestre for ins in self.formsemestre_inscriptions],
|
|
|
|
key=attrgetter("date_debut"),
|
2024-06-07 17:58:02 +02:00
|
|
|
reverse=recent_first,
|
2023-03-18 21:56:08 +01:00
|
|
|
)
|
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
def get_modimpls_by_formsemestre(
|
|
|
|
self, annee_scolaire: int
|
|
|
|
) -> dict[int, list["ModuleImpl"]]:
|
|
|
|
"""Pour chaque semestre de l'année indiquée dans lequel l'étudiant
|
|
|
|
est inscrit à des moduleimpls, liste ceux ci.
|
|
|
|
{ formsemestre_id : [ modimpl, ... ] }
|
|
|
|
annee_scolaire est un nombre: eg 2023
|
|
|
|
"""
|
2023-12-29 13:57:44 +01:00
|
|
|
date_debut_annee = scu.date_debut_annee_scolaire(annee_scolaire)
|
|
|
|
date_fin_annee = scu.date_fin_annee_scolaire(annee_scolaire)
|
2023-12-05 21:04:38 +01:00
|
|
|
modimpls = (
|
|
|
|
ModuleImpl.query.join(ModuleImplInscription)
|
|
|
|
.join(FormSemestre)
|
|
|
|
.filter(
|
|
|
|
(FormSemestre.date_debut <= date_fin_annee)
|
|
|
|
& (FormSemestre.date_fin >= date_debut_annee)
|
|
|
|
)
|
|
|
|
.join(Identite)
|
|
|
|
.filter_by(id=self.id)
|
|
|
|
)
|
|
|
|
# Tri, par semestre puis par module, suivant le type de formation:
|
|
|
|
formsemestres = sorted(
|
|
|
|
{m.formsemestre for m in modimpls}, key=lambda s: s.sort_key()
|
|
|
|
)
|
|
|
|
modimpls_by_formsemestre = {}
|
|
|
|
for formsemestre in formsemestres:
|
|
|
|
modimpls_sem = [m for m in modimpls if m.formsemestre_id == formsemestre.id]
|
|
|
|
if formsemestre.formation.is_apc():
|
|
|
|
modimpls_sem.sort(key=lambda m: m.module.sort_key_apc())
|
|
|
|
else:
|
|
|
|
modimpls_sem.sort(
|
|
|
|
key=lambda m: (m.module.ue.numero or 0, m.module.numero or 0)
|
|
|
|
)
|
|
|
|
modimpls_by_formsemestre[formsemestre.id] = modimpls_sem
|
|
|
|
return modimpls_by_formsemestre
|
|
|
|
|
2024-06-05 13:43:44 +02:00
|
|
|
def get_modimpls_from_formsemestre(
|
|
|
|
self, formsemestre: "FormSemestre"
|
|
|
|
) -> list["ModuleImpl"]:
|
|
|
|
"""
|
|
|
|
Liste des ModuleImpl auxquels l'étudiant est inscrit dans le formsemestre.
|
|
|
|
"""
|
|
|
|
modimpls = ModuleImpl.query.join(ModuleImplInscription).filter(
|
|
|
|
ModuleImplInscription.etudid == self.id,
|
|
|
|
ModuleImpl.formsemestre_id == formsemestre.id,
|
|
|
|
)
|
|
|
|
return modimpls.all()
|
|
|
|
|
2023-05-15 19:50:11 +02:00
|
|
|
@classmethod
|
|
|
|
def convert_dict_fields(cls, args: dict) -> dict:
|
2023-10-15 14:42:03 +02:00
|
|
|
"""Convert fields in the given dict. No other side effect.
|
2023-10-16 22:51:31 +02:00
|
|
|
returns: dict to store in model's db.
|
2023-10-15 14:42:03 +02:00
|
|
|
"""
|
2023-10-18 14:28:43 +02:00
|
|
|
# Les champs qui sont toujours stockés en majuscules:
|
|
|
|
fs_uppercase = {"nom", "nom_usuel", "prenom", "prenom_etat_civil"}
|
2023-05-15 19:50:11 +02:00
|
|
|
fs_empty_stored_as_nulls = {
|
|
|
|
"nom",
|
|
|
|
"prenom",
|
|
|
|
"nom_usuel",
|
|
|
|
"date_naissance",
|
|
|
|
"lieu_naissance",
|
|
|
|
"dept_naissance",
|
|
|
|
"nationalite",
|
|
|
|
"statut",
|
|
|
|
"photo_filename",
|
|
|
|
"code_nip",
|
|
|
|
"code_ine",
|
|
|
|
}
|
|
|
|
args_dict = {}
|
|
|
|
for key, value in args.items():
|
2023-05-29 18:23:32 +02:00
|
|
|
if hasattr(cls, key) and not isinstance(getattr(cls, key, None), property):
|
2023-05-15 19:50:11 +02:00
|
|
|
# compat scodoc7 (mauvaise idée de l'époque)
|
|
|
|
if key in fs_empty_stored_as_nulls and value == "":
|
|
|
|
value = None
|
|
|
|
if key in fs_uppercase and value:
|
|
|
|
value = value.upper()
|
2023-10-15 14:42:03 +02:00
|
|
|
if key == "civilite": # requis
|
2023-05-15 19:50:11 +02:00
|
|
|
value = input_civilite(value)
|
2023-10-15 14:42:03 +02:00
|
|
|
elif key == "civilite_etat_civil":
|
2023-10-17 22:12:28 +02:00
|
|
|
value = input_civilite_etat_civil(value)
|
2023-05-15 19:50:11 +02:00
|
|
|
elif key == "boursier":
|
2023-11-24 13:55:53 +01:00
|
|
|
value = scu.to_bool(value)
|
2023-05-15 19:50:11 +02:00
|
|
|
elif key == "date_naissance":
|
|
|
|
value = ndb.DateDMYtoISO(value)
|
|
|
|
args_dict[key] = value
|
|
|
|
return args_dict
|
|
|
|
|
2022-04-28 03:24:37 +02:00
|
|
|
def to_dict_short(self) -> dict:
|
2024-01-20 17:37:24 +01:00
|
|
|
"""Les champs essentiels (aucune donnée perso protégée)"""
|
2022-04-28 03:24:37 +02:00
|
|
|
return {
|
|
|
|
"id": self.id,
|
2022-08-30 19:13:21 +02:00
|
|
|
"civilite": self.civilite,
|
2022-07-29 16:19:40 +02:00
|
|
|
"code_nip": self.code_nip,
|
|
|
|
"code_ine": self.code_ine,
|
|
|
|
"dept_id": self.dept_id,
|
2022-04-28 03:24:37 +02:00
|
|
|
"nom": self.nom,
|
|
|
|
"nom_usuel": self.nom_usuel,
|
|
|
|
"prenom": self.prenom,
|
2022-08-30 19:13:21 +02:00
|
|
|
"sort_key": self.sort_key,
|
2023-03-13 06:39:36 +01:00
|
|
|
"civilite_etat_civil": self.civilite_etat_civil,
|
|
|
|
"prenom_etat_civil": self.prenom_etat_civil,
|
2022-04-28 03:24:37 +02:00
|
|
|
}
|
|
|
|
|
2024-02-04 00:07:14 +01:00
|
|
|
def to_dict_scodoc7(self, restrict=False, with_inscriptions=False) -> dict:
|
2021-12-30 23:58:38 +01:00
|
|
|
"""Représentation dictionnaire,
|
2024-01-20 14:49:36 +01:00
|
|
|
compatible ScoDoc7 mais sans infos admission.
|
|
|
|
Si restrict, cache les infos "personnelles" si pas permission ViewEtudData
|
2024-02-04 00:07:14 +01:00
|
|
|
Si with_inscriptions, inclut les champs "inscription"
|
2021-12-30 23:58:38 +01:00
|
|
|
"""
|
2023-10-15 14:42:03 +02:00
|
|
|
e_dict = self.__dict__.copy() # dict(self.__dict__)
|
|
|
|
e_dict.pop("_sa_instance_state", None)
|
2021-12-30 23:58:38 +01:00
|
|
|
# ScoDoc7 output_formators: (backward compat)
|
2023-10-15 14:42:03 +02:00
|
|
|
e_dict["etudid"] = self.id
|
2023-10-17 22:12:28 +02:00
|
|
|
e_dict["date_naissance"] = ndb.DateISOtoDMY(e_dict.get("date_naissance", ""))
|
2023-10-15 14:42:03 +02:00
|
|
|
e_dict["ne"] = self.e
|
|
|
|
e_dict["nomprenom"] = self.nomprenom
|
2024-11-06 18:27:24 +01:00
|
|
|
adresse: Adresse = self.adresses.first()
|
2023-02-19 23:06:44 +01:00
|
|
|
if adresse:
|
2024-01-20 14:49:36 +01:00
|
|
|
e_dict.update(adresse.to_dict(restrict=restrict))
|
2024-02-04 00:07:14 +01:00
|
|
|
if with_inscriptions:
|
|
|
|
e_dict.update(self.inscription_descr())
|
2023-10-15 14:42:03 +02:00
|
|
|
return {k: v or "" for k, v in e_dict.items()} # convert_null_outputs_to_empty
|
2021-12-30 23:58:38 +01:00
|
|
|
|
2021-12-21 15:33:21 +01:00
|
|
|
def to_dict_bul(self, include_urls=True):
|
2022-03-16 15:20:23 +01:00
|
|
|
"""Infos exportées dans les bulletins
|
|
|
|
L'étudiant, et sa première adresse.
|
|
|
|
"""
|
2021-12-20 22:53:09 +01:00
|
|
|
from app.scodoc import sco_photos
|
|
|
|
|
|
|
|
d = {
|
2023-08-29 11:27:24 +02:00
|
|
|
"boursier": self.boursier or "",
|
|
|
|
"civilite_etat_civil": self.civilite_etat_civil,
|
2021-12-05 20:21:51 +01:00
|
|
|
"civilite": self.civilite,
|
2022-03-16 15:20:23 +01:00
|
|
|
"code_ine": self.code_ine or "",
|
|
|
|
"code_nip": self.code_nip or "",
|
2024-02-11 12:05:43 +01:00
|
|
|
"date_naissance": (
|
2024-04-02 23:37:23 +02:00
|
|
|
self.date_naissance.strftime(scu.DATE_FMT)
|
|
|
|
if self.date_naissance
|
|
|
|
else ""
|
2024-02-11 12:05:43 +01:00
|
|
|
),
|
2022-05-11 04:14:42 +02:00
|
|
|
"dept_acronym": self.departement.acronym,
|
2023-08-29 11:27:24 +02:00
|
|
|
"dept_id": self.dept_id,
|
|
|
|
"dept_naissance": self.dept_naissance or "",
|
2022-03-16 15:20:23 +01:00
|
|
|
"email": self.get_first_email() or "",
|
2021-12-11 16:46:15 +01:00
|
|
|
"emailperso": self.get_first_email("emailperso"),
|
2023-08-29 11:27:24 +02:00
|
|
|
"etat_civil": self.etat_civil,
|
2021-12-05 20:21:51 +01:00
|
|
|
"etudid": self.id,
|
2022-03-16 15:20:23 +01:00
|
|
|
"lieu_naissance": self.lieu_naissance or "",
|
|
|
|
"nationalite": self.nationalite or "",
|
2023-08-29 11:27:24 +02:00
|
|
|
"nom": self.nom_disp(),
|
|
|
|
"nomprenom": self.nomprenom or "",
|
2023-03-13 06:39:36 +01:00
|
|
|
"prenom_etat_civil": self.prenom_etat_civil,
|
2023-08-29 11:27:24 +02:00
|
|
|
"prenom": self.prenom or "",
|
2021-12-05 20:21:51 +01:00
|
|
|
}
|
2022-08-07 19:56:25 +02:00
|
|
|
if include_urls and has_request_context():
|
|
|
|
# test request context so we can use this func in tests under the flask shell
|
2021-12-21 15:33:21 +01:00
|
|
|
d["fiche_url"] = url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=self.id
|
2021-12-21 15:33:21 +01:00
|
|
|
)
|
2022-03-16 15:20:23 +01:00
|
|
|
d["photo_url"] = sco_photos.get_etud_photo_url(self.id)
|
|
|
|
adresse = self.adresses.first()
|
|
|
|
if adresse:
|
|
|
|
d.update(adresse.to_dict(convert_nulls_to_str=True))
|
2022-07-31 20:42:38 +02:00
|
|
|
d["id"] = self.id # a été écrasé par l'id de adresse
|
2021-12-20 22:53:09 +01:00
|
|
|
return d
|
2021-12-05 20:21:51 +01:00
|
|
|
|
2024-02-10 19:32:43 +01:00
|
|
|
def to_dict_api(self, restrict=False, with_annotations=False) -> dict:
|
2024-01-20 17:37:24 +01:00
|
|
|
"""Représentation dictionnaire pour export API, avec adresses et admission.
|
|
|
|
Si restrict, supprime les infos "personnelles" (boursier)
|
|
|
|
"""
|
2022-07-31 21:44:39 +02:00
|
|
|
e = dict(self.__dict__)
|
|
|
|
e.pop("_sa_instance_state", None)
|
2023-10-15 14:42:03 +02:00
|
|
|
admission = self.admission
|
2022-07-31 21:44:39 +02:00
|
|
|
e["admission"] = admission.to_dict() if admission is not None else None
|
2024-01-20 17:37:24 +01:00
|
|
|
e["adresses"] = [adr.to_dict(restrict=restrict) for adr in self.adresses]
|
2022-07-31 21:44:39 +02:00
|
|
|
e["dept_acronym"] = self.departement.acronym
|
|
|
|
e.pop("departement", None)
|
2022-08-30 19:13:21 +02:00
|
|
|
e["sort_key"] = self.sort_key
|
2024-02-10 19:32:43 +01:00
|
|
|
if with_annotations:
|
2024-02-11 12:05:43 +01:00
|
|
|
e["annotations"] = (
|
|
|
|
[
|
|
|
|
annot.to_dict()
|
|
|
|
for annot in EtudAnnotation.query.filter_by(
|
|
|
|
etudid=self.id
|
|
|
|
).order_by(desc(EtudAnnotation.date))
|
|
|
|
]
|
|
|
|
if not restrict
|
|
|
|
else []
|
|
|
|
)
|
2024-01-20 17:37:24 +01:00
|
|
|
if restrict:
|
|
|
|
# Met à None les attributs protégés:
|
|
|
|
for attr in self.protected_attrs:
|
|
|
|
e[attr] = None
|
2022-07-31 21:44:39 +02:00
|
|
|
return e
|
|
|
|
|
2022-07-02 11:17:04 +02:00
|
|
|
def inscriptions(self) -> list["FormSemestreInscription"]:
|
|
|
|
"Liste des inscriptions à des formsemestres, triée, la plus récente en tête"
|
|
|
|
return (
|
|
|
|
FormSemestreInscription.query.join(FormSemestreInscription.formsemestre)
|
|
|
|
.filter(
|
|
|
|
FormSemestreInscription.etudid == self.id,
|
|
|
|
)
|
|
|
|
.order_by(desc(FormSemestre.date_debut))
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
|
2024-05-20 15:51:33 +02:00
|
|
|
def inscription_courante(self) -> "FormSemestreInscription | None":
|
2021-12-04 21:04:09 +01:00
|
|
|
"""La première inscription à un formsemestre _actuellement_ en cours.
|
|
|
|
None s'il n'y en a pas (ou plus, ou pas encore).
|
|
|
|
"""
|
|
|
|
r = [
|
|
|
|
ins
|
|
|
|
for ins in self.formsemestre_inscriptions
|
|
|
|
if ins.formsemestre.est_courant()
|
|
|
|
]
|
|
|
|
return r[0] if r else None
|
|
|
|
|
2022-07-02 11:17:04 +02:00
|
|
|
def inscriptions_courantes(self) -> list["FormSemestreInscription"]:
|
2022-03-06 22:40:20 +01:00
|
|
|
"""Liste des inscriptions à des semestres _courants_
|
|
|
|
(il est rare qu'il y en ai plus d'une, mais c'est possible).
|
|
|
|
Triées par date de début de semestre décroissante (le plus récent en premier).
|
|
|
|
"""
|
|
|
|
return (
|
|
|
|
FormSemestreInscription.query.join(FormSemestreInscription.formsemestre)
|
|
|
|
.filter(
|
|
|
|
FormSemestreInscription.etudid == self.id,
|
|
|
|
text("date_debut < now() and date_fin > now()"),
|
|
|
|
)
|
|
|
|
.order_by(desc(FormSemestre.date_debut))
|
|
|
|
.all()
|
|
|
|
)
|
|
|
|
|
2021-12-23 19:28:25 +01:00
|
|
|
def inscription_courante_date(self, date_debut, date_fin):
|
2021-12-29 14:41:33 +01:00
|
|
|
"""La première inscription à un formsemestre incluant la
|
|
|
|
période [date_debut, date_fin]
|
|
|
|
"""
|
2021-12-23 19:28:25 +01:00
|
|
|
r = [
|
|
|
|
ins
|
|
|
|
for ins in self.formsemestre_inscriptions
|
2021-12-29 14:41:33 +01:00
|
|
|
if ins.formsemestre.contient_periode(date_debut, date_fin)
|
2021-12-23 19:28:25 +01:00
|
|
|
]
|
|
|
|
return r[0] if r else None
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
def inscription_descr(self) -> dict:
|
2024-02-04 00:07:14 +01:00
|
|
|
"""Description de l'état d'inscription
|
|
|
|
avec champs compatibles templates ScoDoc7
|
|
|
|
"""
|
2022-03-06 22:40:20 +01:00
|
|
|
inscription_courante = self.inscription_courante()
|
|
|
|
if inscription_courante:
|
|
|
|
titre_sem = inscription_courante.formsemestre.titre_mois()
|
2022-09-30 20:55:09 +02:00
|
|
|
if inscription_courante.etat == scu.DEMISSION:
|
|
|
|
inscr_txt = "Démission de"
|
|
|
|
elif inscription_courante.etat == scu.DEF:
|
|
|
|
inscr_txt = "Défaillant dans"
|
|
|
|
else:
|
|
|
|
inscr_txt = "Inscrit en"
|
|
|
|
|
2024-02-04 00:07:14 +01:00
|
|
|
result = {
|
2022-03-06 22:40:20 +01:00
|
|
|
"etat_in_cursem": inscription_courante.etat,
|
|
|
|
"inscription_courante": inscription_courante,
|
|
|
|
"inscription": titre_sem,
|
2022-09-30 20:55:09 +02:00
|
|
|
"inscription_str": inscr_txt + " " + titre_sem,
|
2022-03-06 22:40:20 +01:00
|
|
|
"situation": self.descr_situation_etud(),
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
if self.formsemestre_inscriptions:
|
|
|
|
# cherche l'inscription la plus récente:
|
|
|
|
fin_dernier_sem = max(
|
|
|
|
[
|
|
|
|
inscr.formsemestre.date_debut
|
|
|
|
for inscr in self.formsemestre_inscriptions
|
|
|
|
]
|
|
|
|
)
|
|
|
|
if fin_dernier_sem > datetime.date.today():
|
|
|
|
inscription = "futur"
|
|
|
|
situation = "futur élève"
|
|
|
|
else:
|
|
|
|
inscription = "ancien"
|
|
|
|
situation = "ancien élève"
|
|
|
|
else:
|
2024-02-04 00:07:14 +01:00
|
|
|
inscription = "non inscrit"
|
2022-03-06 22:40:20 +01:00
|
|
|
situation = inscription
|
2024-02-04 00:07:14 +01:00
|
|
|
result = {
|
2022-03-06 22:40:20 +01:00
|
|
|
"etat_in_cursem": "?",
|
|
|
|
"inscription_courante": None,
|
|
|
|
"inscription": inscription,
|
|
|
|
"inscription_str": inscription,
|
|
|
|
"situation": situation,
|
|
|
|
}
|
2024-02-04 00:07:14 +01:00
|
|
|
# aliases pour compat templates ScoDoc7
|
|
|
|
result["etatincursem"] = result["etat_in_cursem"]
|
|
|
|
result["inscriptionstr"] = result["inscription_str"]
|
|
|
|
|
|
|
|
return result
|
2022-03-06 22:40:20 +01:00
|
|
|
|
2022-09-30 16:20:51 +02:00
|
|
|
def inscription_etat(self, formsemestre_id: int) -> str:
|
2022-07-02 11:17:04 +02:00
|
|
|
"""État de l'inscription de cet étudiant au semestre:
|
|
|
|
False si pas inscrit, ou scu.INSCRIT, DEMISSION, DEF
|
|
|
|
"""
|
|
|
|
# voir si ce n'est pas trop lent:
|
|
|
|
ins = models.FormSemestreInscription.query.filter_by(
|
|
|
|
etudid=self.id, formsemestre_id=formsemestre_id
|
|
|
|
).first()
|
|
|
|
if ins:
|
|
|
|
return ins.etat
|
|
|
|
return False
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
def descr_situation_etud(self) -> str:
|
|
|
|
"""Chaîne décrivant la situation _actuelle_ de l'étudiant.
|
|
|
|
Exemple:
|
|
|
|
"inscrit en BUT R&T semestre 2 FI (Jan 2022 - Jul 2022) le 16/01/2022"
|
|
|
|
ou
|
|
|
|
"non inscrit"
|
|
|
|
"""
|
|
|
|
inscriptions_courantes = self.inscriptions_courantes()
|
|
|
|
if inscriptions_courantes:
|
|
|
|
inscr = inscriptions_courantes[0]
|
|
|
|
if inscr.etat == scu.INSCRIT:
|
|
|
|
situation = f"inscrit{self.e} en {inscr.formsemestre.titre_mois()}"
|
|
|
|
# Cherche la date d'inscription dans scolar_events:
|
|
|
|
events = models.ScolarEvent.query.filter_by(
|
|
|
|
etudid=self.id,
|
|
|
|
formsemestre_id=inscr.formsemestre.id,
|
|
|
|
event_type="INSCRIPTION",
|
|
|
|
).all()
|
|
|
|
if not events:
|
|
|
|
log(
|
|
|
|
f"*** situation inconsistante pour {self} (inscrit mais pas d'event)"
|
|
|
|
)
|
2022-03-21 14:33:38 +01:00
|
|
|
situation += " (inscription non enregistrée)" # ???
|
2022-03-06 22:40:20 +01:00
|
|
|
else:
|
|
|
|
date_ins = events[0].event_date
|
2022-03-21 14:33:38 +01:00
|
|
|
situation += date_ins.strftime(" le %d/%m/%Y")
|
2022-04-21 16:35:27 +02:00
|
|
|
elif inscr.etat == scu.DEF:
|
|
|
|
situation = f"défaillant en {inscr.formsemestre.titre_mois()}"
|
|
|
|
event = (
|
|
|
|
models.ScolarEvent.query.filter_by(
|
|
|
|
etudid=self.id,
|
|
|
|
formsemestre_id=inscr.formsemestre.id,
|
|
|
|
event_type="DEFAILLANCE",
|
|
|
|
)
|
|
|
|
.order_by(models.ScolarEvent.event_date)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
if not event:
|
|
|
|
log(
|
|
|
|
f"*** situation inconsistante pour {self} (def mais pas d'event)"
|
|
|
|
)
|
|
|
|
situation += "???" # ???
|
|
|
|
else:
|
|
|
|
date_def = event.event_date
|
|
|
|
situation += date_def.strftime(" le %d/%m/%Y")
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
else:
|
|
|
|
situation = f"démission de {inscr.formsemestre.titre_mois()}"
|
|
|
|
# Cherche la date de demission dans scolar_events:
|
2022-04-21 16:35:27 +02:00
|
|
|
event = (
|
|
|
|
models.ScolarEvent.query.filter_by(
|
|
|
|
etudid=self.id,
|
|
|
|
formsemestre_id=inscr.formsemestre.id,
|
|
|
|
event_type="DEMISSION",
|
|
|
|
)
|
|
|
|
.order_by(models.ScolarEvent.event_date)
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
if not event:
|
2022-03-06 22:40:20 +01:00
|
|
|
log(
|
|
|
|
f"*** situation inconsistante pour {self} (demission mais pas d'event)"
|
|
|
|
)
|
2022-04-21 16:35:27 +02:00
|
|
|
situation += "???" # ???
|
2022-03-06 22:40:20 +01:00
|
|
|
else:
|
2022-04-21 16:35:27 +02:00
|
|
|
date_dem = event.event_date
|
|
|
|
situation += date_dem.strftime(" le %d/%m/%Y")
|
2022-03-06 22:40:20 +01:00
|
|
|
else:
|
|
|
|
situation = "non inscrit" + self.e
|
|
|
|
|
|
|
|
return situation
|
|
|
|
|
2023-02-21 02:30:48 +01:00
|
|
|
def etat_civil_pv(self, with_paragraph=True, line_sep="\n") -> str:
|
2022-06-30 23:49:39 +02:00
|
|
|
"""Présentation, pour PV jury
|
2023-02-21 02:30:48 +01:00
|
|
|
Si with_paragraph (défaut):
|
|
|
|
M. Pierre Dupont
|
|
|
|
n° 12345678
|
|
|
|
né(e) le 7/06/1974
|
|
|
|
à Paris
|
|
|
|
Sinon:
|
|
|
|
M. Pierre Dupont
|
2022-06-30 23:49:39 +02:00
|
|
|
"""
|
2023-02-21 02:30:48 +01:00
|
|
|
if with_paragraph:
|
2023-03-13 06:39:36 +01:00
|
|
|
return f"""{self.etat_civil}{line_sep}n°{self.code_nip or ""}{line_sep}né{self.e} le {
|
2024-04-02 23:37:23 +02:00
|
|
|
self.date_naissance.strftime(scu.DATE_FMT) if self.date_naissance else ""}{
|
2023-02-21 02:30:48 +01:00
|
|
|
line_sep}à {self.lieu_naissance or ""}"""
|
2023-03-13 06:39:36 +01:00
|
|
|
return self.etat_civil
|
2022-06-30 23:49:39 +02:00
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
def photo_html(self, title=None, size="small") -> str:
|
|
|
|
"""HTML img tag for the photo, either in small size (h90)
|
|
|
|
or original size (size=="orig")
|
|
|
|
"""
|
|
|
|
from app.scodoc import sco_photos
|
|
|
|
|
|
|
|
# sco_photo traite des dicts:
|
|
|
|
return sco_photos.etud_photo_html(
|
|
|
|
etud=dict(
|
|
|
|
etudid=self.id,
|
|
|
|
code_nip=self.code_nip,
|
|
|
|
nomprenom=self.nomprenom,
|
|
|
|
nom_disp=self.nom_disp(),
|
|
|
|
photo_filename=self.photo_filename,
|
|
|
|
),
|
|
|
|
title=title,
|
|
|
|
size=size,
|
|
|
|
)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-09-04 04:09:31 +02:00
|
|
|
def check_etud_duplicate_code(
|
|
|
|
args, code_name, edit=True, etudid: int | None = None, dest_url: str | None = ""
|
|
|
|
):
|
2024-02-02 18:23:35 +01:00
|
|
|
"""Vérifie que le code n'est pas dupliqué.
|
|
|
|
Raises ScoGenError si problème.
|
2024-09-04 04:09:31 +02:00
|
|
|
Si dest_url === None, pas de lien continuer/annuler.
|
2024-02-02 18:23:35 +01:00
|
|
|
"""
|
2024-08-23 04:30:53 +02:00
|
|
|
etudid = etudid or args.get("etudid", None)
|
2024-02-02 18:23:35 +01:00
|
|
|
if not args.get(code_name, None):
|
|
|
|
return
|
|
|
|
etuds = Identite.query.filter_by(
|
|
|
|
**{code_name: str(args[code_name]), "dept_id": g.scodoc_dept_id}
|
|
|
|
).all()
|
|
|
|
duplicate = False
|
|
|
|
if edit:
|
2024-02-03 23:25:05 +01:00
|
|
|
duplicate = (len(etuds) > 1) or ((len(etuds) == 1) and etuds[0].id != etudid)
|
2024-02-02 18:23:35 +01:00
|
|
|
else:
|
|
|
|
duplicate = len(etuds) > 0
|
|
|
|
if duplicate:
|
|
|
|
listh = [] # liste des doubles
|
|
|
|
for etud in etuds:
|
|
|
|
listh.append(f"Autre étudiant: {etud.html_link_fiche()}")
|
|
|
|
if etudid:
|
|
|
|
submit_label = "retour à la fiche étudiant"
|
|
|
|
dest_endpoint = "scolar.fiche_etud"
|
|
|
|
parameters = {"etudid": etudid}
|
|
|
|
else:
|
|
|
|
if "tf_submitted" in args:
|
|
|
|
del args["tf_submitted"]
|
|
|
|
submit_label = "Continuer"
|
|
|
|
dest_endpoint = "scolar.etudident_create_form"
|
|
|
|
parameters = args
|
|
|
|
else:
|
|
|
|
submit_label = "Annuler"
|
|
|
|
dest_endpoint = "notes.index_html"
|
|
|
|
parameters = {}
|
|
|
|
|
2024-07-19 16:32:56 +02:00
|
|
|
err_page = f"""<h3>Code étudiant ({code_name}) dupliqué !</h3>
|
2024-02-02 18:23:35 +01:00
|
|
|
<p class="help">Le {code_name} {args[code_name]} est déjà utilisé: un seul étudiant peut avoir
|
|
|
|
ce code. Vérifier votre valeur ou supprimer l'autre étudiant avec cette valeur.
|
|
|
|
</p>
|
|
|
|
<ul><li>
|
|
|
|
{ '</li><li>'.join(listh) }
|
|
|
|
</li></ul>
|
2024-09-04 04:09:31 +02:00
|
|
|
"""
|
|
|
|
err_page += (
|
|
|
|
f"""
|
2024-02-02 18:23:35 +01:00
|
|
|
<p>
|
2024-09-04 04:09:31 +02:00
|
|
|
<a href="{ dest_url or url_for(dest_endpoint, scodoc_dept=g.scodoc_dept, **parameters) }
|
2024-02-02 18:23:35 +01:00
|
|
|
">{submit_label}</a>
|
|
|
|
</p>
|
|
|
|
"""
|
2024-09-04 04:09:31 +02:00
|
|
|
if dest_url is not None
|
|
|
|
else ""
|
|
|
|
)
|
2024-02-02 18:23:35 +01:00
|
|
|
|
|
|
|
log(f"*** error: code {code_name} duplique: {args[code_name]}")
|
|
|
|
|
2024-07-19 16:32:56 +02:00
|
|
|
raise ScoGenError(err_page, safe=True)
|
2024-02-02 18:23:35 +01:00
|
|
|
|
|
|
|
|
2021-12-26 19:15:47 +01:00
|
|
|
def make_etud_args(
|
|
|
|
etudid=None, code_nip=None, use_request=True, raise_exc=False, abort_404=True
|
|
|
|
) -> dict:
|
|
|
|
"""forme args dict pour requete recherche etudiant
|
|
|
|
On peut specifier etudid
|
|
|
|
ou bien (si use_request) cherche dans la requete http: etudid, code_nip, code_ine
|
|
|
|
(dans cet ordre).
|
|
|
|
|
|
|
|
Résultat: dict avec soit "etudid", soit "code_nip", soit "code_ine"
|
|
|
|
"""
|
|
|
|
args = None
|
|
|
|
if etudid:
|
2022-04-05 22:23:55 +02:00
|
|
|
try:
|
|
|
|
args = {"etudid": int(etudid)}
|
|
|
|
except ValueError as exc:
|
2022-04-12 17:12:51 +02:00
|
|
|
raise ScoInvalidParamError() from exc
|
2021-12-26 19:15:47 +01:00
|
|
|
elif code_nip:
|
|
|
|
args = {"code_nip": code_nip}
|
|
|
|
elif use_request: # use form from current request (Flask global)
|
|
|
|
if request.method == "POST":
|
|
|
|
vals = request.form
|
|
|
|
elif request.method == "GET":
|
|
|
|
vals = request.args
|
|
|
|
else:
|
|
|
|
vals = {}
|
2022-03-27 10:49:45 +02:00
|
|
|
try:
|
|
|
|
if "etudid" in vals:
|
|
|
|
args = {"etudid": int(vals["etudid"])}
|
|
|
|
elif "code_nip" in vals:
|
|
|
|
args = {"code_nip": str(vals["code_nip"])}
|
|
|
|
elif "code_ine" in vals:
|
|
|
|
args = {"code_ine": str(vals["code_ine"])}
|
|
|
|
except ValueError:
|
|
|
|
args = {}
|
2021-12-26 19:15:47 +01:00
|
|
|
if not args:
|
|
|
|
if abort_404:
|
|
|
|
abort(404, "pas d'étudiant sélectionné")
|
|
|
|
elif raise_exc:
|
|
|
|
raise ValueError("make_etud_args: pas d'étudiant sélectionné !")
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
2023-10-15 14:42:03 +02:00
|
|
|
def input_civilite(s: str) -> str:
|
2023-05-15 19:50:11 +02:00
|
|
|
"""Converts external representation of civilite to internal:
|
|
|
|
'M', 'F', or 'X' (and nothing else).
|
|
|
|
Raises ScoValueError if conversion fails.
|
|
|
|
"""
|
2023-10-15 14:42:03 +02:00
|
|
|
if not isinstance(s, str):
|
|
|
|
raise ScoValueError("valeur invalide pour la civilité (chaine attendue)")
|
2023-05-15 19:50:11 +02:00
|
|
|
s = s.upper().strip()
|
|
|
|
if s in ("M", "M.", "MR", "H"):
|
|
|
|
return "M"
|
|
|
|
elif s in ("F", "MLLE", "MLLE.", "MELLE", "MME"):
|
|
|
|
return "F"
|
|
|
|
elif s == "X" or not s:
|
|
|
|
return "X"
|
2023-05-15 22:20:28 +02:00
|
|
|
raise ScoValueError(f"valeur invalide pour la civilité: {s}")
|
|
|
|
|
|
|
|
|
2023-10-17 22:12:28 +02:00
|
|
|
def input_civilite_etat_civil(s: str) -> str | None:
|
|
|
|
"""Same as input_civilite, but empty gives None (null)"""
|
|
|
|
return input_civilite(s) if s and s.strip() else None
|
|
|
|
|
|
|
|
|
2023-05-15 22:20:28 +02:00
|
|
|
PIVOT_YEAR = 70
|
|
|
|
|
|
|
|
|
|
|
|
def pivot_year(y) -> int:
|
|
|
|
"converti et calcule l'année si saisie à deux chiffres"
|
|
|
|
if y == "" or y is None:
|
|
|
|
return None
|
|
|
|
y = int(round(float(y)))
|
|
|
|
if y >= 0 and y < 100:
|
|
|
|
if y < PIVOT_YEAR:
|
|
|
|
y = y + 2000
|
|
|
|
else:
|
|
|
|
y = y + 1900
|
|
|
|
return y
|
2023-05-15 19:50:11 +02:00
|
|
|
|
|
|
|
|
2023-12-22 15:21:07 +01:00
|
|
|
class Adresse(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Adresse d'un étudiant
|
|
|
|
(le modèle permet plusieurs adresses, mais l'UI n'en gère qu'une seule)
|
|
|
|
"""
|
|
|
|
|
|
|
|
__tablename__ = "adresse"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
adresse_id = db.synonym("id")
|
2023-10-15 14:42:03 +02:00
|
|
|
etudid = db.Column(db.Integer, db.ForeignKey("identite.id"), nullable=False)
|
|
|
|
# Relationship to Identite
|
|
|
|
etud = db.relationship("Identite", back_populates="adresses")
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
email = db.Column(db.Text()) # mail institutionnel
|
|
|
|
emailperso = db.Column(db.Text) # email personnel (exterieur)
|
|
|
|
domicile = db.Column(db.Text)
|
|
|
|
codepostaldomicile = db.Column(db.Text)
|
|
|
|
villedomicile = db.Column(db.Text)
|
|
|
|
paysdomicile = db.Column(db.Text)
|
|
|
|
telephone = db.Column(db.Text)
|
|
|
|
telephonemobile = db.Column(db.Text)
|
|
|
|
fax = db.Column(db.Text)
|
2021-08-10 00:23:30 +02:00
|
|
|
typeadresse = db.Column(
|
|
|
|
db.Text, default="domicile", server_default="domicile", nullable=False
|
|
|
|
)
|
2021-08-07 15:20:30 +02:00
|
|
|
description = db.Column(db.Text)
|
|
|
|
|
2024-01-20 14:49:36 +01:00
|
|
|
# Champs "protégés" par ViewEtudData (RGPD)
|
|
|
|
protected_attrs = {
|
|
|
|
"emailperso",
|
|
|
|
"domicile",
|
|
|
|
"codepostaldomicile",
|
|
|
|
"villedomicile",
|
|
|
|
"telephone",
|
|
|
|
"telephonemobile",
|
|
|
|
"fax",
|
|
|
|
}
|
|
|
|
|
|
|
|
def to_dict(self, convert_nulls_to_str=False, restrict=False):
|
|
|
|
"""Représentation dictionnaire. Si restrict, filtre les champs protégés (RGPD)."""
|
2022-03-16 15:20:23 +01:00
|
|
|
e = dict(self.__dict__)
|
|
|
|
e.pop("_sa_instance_state", None)
|
|
|
|
if convert_nulls_to_str:
|
2024-01-20 14:49:36 +01:00
|
|
|
e = {k: v or "" for k, v in e.items()}
|
|
|
|
if restrict:
|
|
|
|
e = {k: v for (k, v) in e.items() if k not in self.protected_attrs}
|
2022-03-16 15:20:23 +01:00
|
|
|
return e
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2023-12-22 15:21:07 +01:00
|
|
|
class Admission(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Informations liées à l'admission d'un étudiant"""
|
|
|
|
|
|
|
|
__tablename__ = "admissions"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
adm_id = db.synonym("id")
|
2023-10-15 14:42:03 +02:00
|
|
|
# obsoleted by migration 497ba81343f7_identite_admission.py:
|
|
|
|
# etudid = db.Column(
|
|
|
|
# db.Integer,
|
|
|
|
# db.ForeignKey("identite.id", ondelete="CASCADE"),
|
|
|
|
# )
|
|
|
|
etud = db.relationship("Identite", back_populates="admission", uselist=False)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
# Anciens champs de ScoDoc7, à revoir pour être plus générique et souple
|
|
|
|
# notamment dans le cadre du bac 2021
|
|
|
|
# de plus, certaines informations liées à APB ne sont plus disponibles
|
|
|
|
# avec Parcoursup
|
|
|
|
annee = db.Column(db.Integer)
|
|
|
|
bac = db.Column(db.Text)
|
|
|
|
specialite = db.Column(db.Text)
|
|
|
|
annee_bac = db.Column(db.Integer)
|
|
|
|
math = db.Column(db.Text)
|
2023-10-17 22:12:28 +02:00
|
|
|
physique = db.Column(db.Text)
|
|
|
|
anglais = db.Column(db.Text)
|
|
|
|
francais = db.Column(db.Text)
|
2021-08-07 15:20:30 +02:00
|
|
|
# Rang dans les voeux du candidat (inconnu avec APB et PS)
|
|
|
|
rang = db.Column(db.Integer)
|
|
|
|
# Qualité et décision du jury d'admission (ou de l'examinateur)
|
|
|
|
qualite = db.Column(db.Float)
|
|
|
|
rapporteur = db.Column(db.Text)
|
|
|
|
decision = db.Column(db.Text)
|
|
|
|
score = db.Column(db.Float)
|
|
|
|
commentaire = db.Column(db.Text)
|
|
|
|
# Lycée d'origine:
|
|
|
|
nomlycee = db.Column(db.Text)
|
|
|
|
villelycee = db.Column(db.Text)
|
|
|
|
codepostallycee = db.Column(db.Text)
|
|
|
|
codelycee = db.Column(db.Text)
|
|
|
|
# 'APB', 'APC-PC', 'CEF', 'Direct', '?' (autre)
|
|
|
|
type_admission = db.Column(db.Text)
|
|
|
|
# était boursier dans le cycle precedent (lycee) ?
|
|
|
|
boursier_prec = db.Column(db.Boolean())
|
|
|
|
# classement par le jury d'admission (1 à N),
|
|
|
|
# global (pas celui d'APB si il y a des groupes)
|
|
|
|
classement = db.Column(db.Integer)
|
|
|
|
# code du groupe APB
|
|
|
|
apb_groupe = db.Column(db.Text)
|
|
|
|
# classement (1..Ngr) par le jury dans le groupe APB
|
|
|
|
apb_classement_gr = db.Column(db.Integer)
|
|
|
|
|
2024-01-20 14:49:36 +01:00
|
|
|
# Tous les champs sont "protégés" par ViewEtudData (RGPD)
|
|
|
|
# sauf:
|
|
|
|
not_protected_attrs = {"bac", "specialite", "anne_bac"}
|
|
|
|
|
2022-01-09 21:02:07 +01:00
|
|
|
def get_bac(self) -> Baccalaureat:
|
|
|
|
"Le bac. utiliser bac.abbrev() pour avoir une chaine de caractères."
|
|
|
|
return Baccalaureat(self.bac, specialite=self.specialite)
|
|
|
|
|
2024-01-20 14:49:36 +01:00
|
|
|
def to_dict(self, no_nulls=False, restrict=False):
|
|
|
|
"""Représentation dictionnaire. Si restrict, filtre les champs protégés (RGPD)."""
|
2022-05-22 03:26:39 +02:00
|
|
|
d = dict(self.__dict__)
|
|
|
|
d.pop("_sa_instance_state", None)
|
2022-02-11 18:27:10 +01:00
|
|
|
if no_nulls:
|
2023-05-15 22:20:28 +02:00
|
|
|
for key, value in d.items():
|
|
|
|
if value is None:
|
2022-02-11 18:27:10 +01:00
|
|
|
col_type = getattr(
|
2023-05-15 22:20:28 +02:00
|
|
|
sqlalchemy.inspect(models.Admission).columns, key
|
2022-02-11 18:27:10 +01:00
|
|
|
).expression.type
|
|
|
|
if isinstance(col_type, sqlalchemy.Text):
|
2023-05-15 22:20:28 +02:00
|
|
|
d[key] = ""
|
2022-02-11 18:27:10 +01:00
|
|
|
elif isinstance(col_type, sqlalchemy.Integer):
|
2023-05-15 22:20:28 +02:00
|
|
|
d[key] = 0
|
2022-02-11 18:27:10 +01:00
|
|
|
elif isinstance(col_type, sqlalchemy.Boolean):
|
2023-05-15 22:20:28 +02:00
|
|
|
d[key] = False
|
2024-01-20 14:49:36 +01:00
|
|
|
if restrict:
|
|
|
|
d = {k: v for (k, v) in d.items() if k in self.not_protected_attrs}
|
2022-05-22 03:26:39 +02:00
|
|
|
return d
|
2022-02-11 18:27:10 +01:00
|
|
|
|
2023-05-15 22:20:28 +02:00
|
|
|
@classmethod
|
|
|
|
def convert_dict_fields(cls, args: dict) -> dict:
|
2023-10-16 22:51:31 +02:00
|
|
|
"""Convert fields in the given dict. No other side effect.
|
|
|
|
args: dict with args in application.
|
|
|
|
returns: dict to store in model's db.
|
|
|
|
"""
|
2023-05-15 22:20:28 +02:00
|
|
|
fs_uppercase = {"bac", "specialite"}
|
|
|
|
args_dict = {}
|
|
|
|
for key, value in args.items():
|
|
|
|
if hasattr(cls, key):
|
|
|
|
if (
|
|
|
|
value == ""
|
|
|
|
): # les chaines vides donne des NULLS (scodoc7 convention)
|
|
|
|
value = None
|
|
|
|
if key in fs_uppercase and value:
|
|
|
|
value = value.upper()
|
|
|
|
elif key == "annee" or key == "annee_bac":
|
|
|
|
value = pivot_year(value)
|
|
|
|
elif key == "classement" or key == "apb_classement_gr":
|
|
|
|
value = ndb.int_null_is_null(value)
|
|
|
|
args_dict[key] = value
|
|
|
|
return args_dict
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-07-19 09:42:44 +02:00
|
|
|
class ItemSuivi(models.ScoDocModel):
|
|
|
|
"""Suivi scolarité / débouchés"""
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
__tablename__ = "itemsuivi"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
itemsuivi_id = db.synonym("id")
|
|
|
|
etudid = db.Column(
|
|
|
|
db.Integer,
|
2022-05-26 03:55:03 +02:00
|
|
|
db.ForeignKey("identite.id", ondelete="CASCADE"),
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|
|
|
|
item_date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
|
|
|
situation = db.Column(db.Text)
|
|
|
|
|
2024-07-19 09:42:44 +02:00
|
|
|
_sco_dept_relations = ("Identite",) # accès au dept_id
|
|
|
|
|
2024-09-09 16:21:51 +02:00
|
|
|
tags = db.relationship(
|
|
|
|
"ItemSuiviTag",
|
|
|
|
secondary="itemsuivi_tags_assoc",
|
|
|
|
lazy=True,
|
|
|
|
backref=db.backref("items", lazy=True),
|
|
|
|
)
|
|
|
|
|
|
|
|
def to_dict(self, merge_tags=False):
|
|
|
|
"""Représentation dictionnaire.
|
|
|
|
Si merge_tags, regroupe les tags sur une seule chaine, valeurs séparées par des virgules
|
|
|
|
"""
|
|
|
|
d = super().to_dict()
|
|
|
|
# Convertit les tags en liste de strings:
|
|
|
|
if merge_tags:
|
|
|
|
d["tags"] = ", ".join([tag.title for tag in self.tags])
|
|
|
|
else:
|
|
|
|
d["tags"] = [tag.title for tag in self.tags]
|
|
|
|
# Ajoute date locale
|
2024-09-11 15:31:22 +02:00
|
|
|
d["item_date_dmy"] = (
|
|
|
|
self.item_date.strftime(scu.DATE_FMT) if self.item_date else ""
|
|
|
|
)
|
2024-09-09 16:21:51 +02:00
|
|
|
return d
|
|
|
|
|
|
|
|
def set_tags(self, tags: list[str]):
|
|
|
|
"""Définit les tags de l'itemsuivi"""
|
|
|
|
self.tags = []
|
|
|
|
for tag in tags:
|
|
|
|
tag_obj = ItemSuiviTag.query.filter_by(title=tag).first()
|
|
|
|
if tag_obj is None:
|
|
|
|
tag_obj = ItemSuiviTag(title=tag)
|
|
|
|
self.tags.append(tag_obj)
|
|
|
|
|
2021-08-07 15:20:30 +02:00
|
|
|
|
2024-09-09 16:21:51 +02:00
|
|
|
class ItemSuiviTag(models.ScoDocModel):
|
|
|
|
"Tag sur un itemsuivi"
|
2021-08-07 15:20:30 +02:00
|
|
|
__tablename__ = "itemsuivi_tags"
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
2021-08-29 21:21:41 +02:00
|
|
|
dept_id = db.Column(db.Integer, db.ForeignKey("departement.id"), index=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
tag_id = db.synonym("id")
|
2021-08-15 22:13:41 +02:00
|
|
|
title = db.Column(db.Text(), nullable=False, unique=True)
|
2021-08-07 15:20:30 +02:00
|
|
|
|
|
|
|
|
2024-09-09 16:21:51 +02:00
|
|
|
# Association tag <-> itemsuivi
|
2021-08-07 15:20:30 +02:00
|
|
|
itemsuivi_tags_assoc = db.Table(
|
|
|
|
"itemsuivi_tags_assoc",
|
2021-11-27 19:04:30 +01:00
|
|
|
db.Column(
|
|
|
|
"tag_id", db.Integer, db.ForeignKey("itemsuivi_tags.id", ondelete="CASCADE")
|
|
|
|
),
|
|
|
|
db.Column(
|
|
|
|
"itemsuivi_id", db.Integer, db.ForeignKey("itemsuivi.id", ondelete="CASCADE")
|
|
|
|
),
|
2021-08-07 15:20:30 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-07-19 09:42:44 +02:00
|
|
|
class EtudAnnotation(models.ScoDocModel):
|
2021-08-07 15:20:30 +02:00
|
|
|
"""Annotation sur un étudiant"""
|
|
|
|
|
|
|
|
__tablename__ = "etud_annotations"
|
|
|
|
|
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
date = db.Column(db.DateTime(timezone=True), server_default=db.func.now())
|
2024-02-11 12:05:43 +01:00
|
|
|
etudid = db.Column(db.Integer, db.ForeignKey(Identite.id))
|
2021-08-14 18:54:32 +02:00
|
|
|
author = db.Column(db.Text) # le pseudo (user_name), was zope_authenticated_user
|
2021-08-07 15:20:30 +02:00
|
|
|
comment = db.Column(db.Text)
|
2023-12-05 21:04:38 +01:00
|
|
|
|
2024-07-19 09:42:44 +02:00
|
|
|
_sco_dept_relations = ("Identite",) # accès au dept_id
|
|
|
|
|
2024-02-11 12:05:43 +01:00
|
|
|
def to_dict(self):
|
|
|
|
"""Représentation dictionnaire."""
|
2024-02-10 14:11:34 +01:00
|
|
|
e = dict(self.__dict__)
|
|
|
|
e.pop("_sa_instance_state", None)
|
|
|
|
return e
|
|
|
|
|
2023-12-05 21:04:38 +01:00
|
|
|
|
2024-03-22 17:39:48 +01:00
|
|
|
from app.models.formsemestre import FormSemestre, FormSemestreInscription
|
2023-12-05 21:04:38 +01:00
|
|
|
from app.models.moduleimpls import ModuleImpl, ModuleImplInscription
|