2020-09-26 16:19:37 +02:00
|
|
|
# -*- mode: python -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# Gestion scolarite IUT
|
|
|
|
#
|
2023-12-31 23:04:06 +01:00
|
|
|
# Copyright (c) 1999 - 2024 Emmanuel Viennet. All rights reserved.
|
2020-09-26 16:19:37 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
# Emmanuel Viennet emmanuel.viennet@viennet.net
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2020-12-26 00:11:55 +01:00
|
|
|
""" Accès donnees etudiants
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-01-17 22:31:28 +01:00
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
# Ancien module "scolars"
|
2021-07-25 09:51:09 +02:00
|
|
|
import os
|
2021-06-19 23:21:37 +02:00
|
|
|
import time
|
2021-09-14 12:21:22 +02:00
|
|
|
from operator import itemgetter
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
from flask import url_for, g
|
2021-07-11 17:37:12 +02:00
|
|
|
|
2023-05-15 19:50:11 +02:00
|
|
|
from app import db, email
|
2021-09-14 12:21:22 +02:00
|
|
|
from app import log
|
2023-05-15 19:50:11 +02:00
|
|
|
from app.models import Admission, Identite
|
2023-10-17 22:12:28 +02:00
|
|
|
from app.models.etudiants import (
|
2024-02-02 18:23:35 +01:00
|
|
|
check_etud_duplicate_code,
|
2023-10-17 22:12:28 +02:00
|
|
|
input_civilite,
|
|
|
|
input_civilite_etat_civil,
|
|
|
|
make_etud_args,
|
|
|
|
pivot_year,
|
|
|
|
)
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.sco_utils as scu
|
2023-11-22 23:31:16 +01:00
|
|
|
from app.scodoc.sco_utils import (
|
|
|
|
format_civilite,
|
|
|
|
format_nom,
|
|
|
|
format_nomprenom,
|
|
|
|
format_prenom,
|
|
|
|
)
|
2021-06-19 23:21:37 +02:00
|
|
|
import app.scodoc.notesdb as ndb
|
|
|
|
from app.scodoc.sco_exceptions import ScoGenError, ScoValueError
|
|
|
|
from app.scodoc import safehtml
|
|
|
|
from app.scodoc import sco_preferences
|
|
|
|
from app.scodoc.scolog import logdb
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2023-10-17 22:12:28 +02:00
|
|
|
def format_etud_ident(etud: dict):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Format identite de l'étudiant (modifié en place)
|
2023-10-17 22:12:28 +02:00
|
|
|
nom, prénom et formes associees.
|
|
|
|
|
|
|
|
Note: par rapport à Identite.to_dict_bul(),
|
|
|
|
ajoute les champs:
|
2024-01-20 14:49:36 +01:00
|
|
|
'nom_disp', 'nom_usuel', 'civilite_etat_civil_str', 'ne', 'civilite_str'
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
etud["nom"] = format_nom(etud["nom"])
|
|
|
|
if "nom_usuel" in etud:
|
|
|
|
etud["nom_usuel"] = format_nom(etud["nom_usuel"])
|
|
|
|
else:
|
|
|
|
etud["nom_usuel"] = ""
|
|
|
|
etud["prenom"] = format_prenom(etud["prenom"])
|
2023-03-13 06:39:36 +01:00
|
|
|
if "prenom_etat_civil" in etud:
|
|
|
|
etud["prenom_etat_civil"] = format_prenom(etud["prenom_etat_civil"])
|
|
|
|
else:
|
|
|
|
etud["prenom_etat_civil"] = ""
|
2021-02-13 17:28:55 +01:00
|
|
|
etud["civilite_str"] = format_civilite(etud["civilite"])
|
2023-10-16 22:51:31 +02:00
|
|
|
etud["civilite_etat_civil_str"] = (
|
|
|
|
format_civilite(etud["civilite_etat_civil"])
|
|
|
|
if etud["civilite_etat_civil"]
|
2023-10-17 22:12:28 +02:00
|
|
|
else etud["civilite_str"]
|
2023-05-25 18:48:21 +02:00
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
# Nom à afficher:
|
|
|
|
if etud["nom_usuel"]:
|
|
|
|
etud["nom_disp"] = etud["nom_usuel"]
|
|
|
|
if etud["nom"]:
|
|
|
|
etud["nom_disp"] += " (" + etud["nom"] + ")"
|
|
|
|
else:
|
|
|
|
etud["nom_disp"] = etud["nom"]
|
|
|
|
|
|
|
|
etud["nomprenom"] = format_nomprenom(etud) # M. Pierre DUPONT
|
2023-10-17 22:12:28 +02:00
|
|
|
etud["etat_civil"] = _format_etat_civil(etud)
|
2021-02-13 17:28:55 +01:00
|
|
|
if etud["civilite"] == "M":
|
2020-09-26 16:19:37 +02:00
|
|
|
etud["ne"] = ""
|
2021-02-13 17:28:55 +01:00
|
|
|
elif etud["civilite"] == "F":
|
2020-09-26 16:19:37 +02:00
|
|
|
etud["ne"] = "e"
|
2021-02-13 17:28:55 +01:00
|
|
|
else: # 'X'
|
|
|
|
etud["ne"] = "(e)"
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def force_uppercase(s):
|
2021-08-21 00:24:51 +02:00
|
|
|
return s.upper() if s else s
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-10-17 22:12:28 +02:00
|
|
|
def _format_etat_civil(etud: dict) -> str:
|
|
|
|
"Mme Béatrice DUPONT, en utilisant les données d'état civil si indiquées."
|
|
|
|
if etud["prenom_etat_civil"] or etud["civilite_etat_civil"]:
|
|
|
|
return f"""{etud["civilite_etat_civil_str"]} {
|
|
|
|
etud["prenom_etat_civil"] or etud["prenom"]
|
|
|
|
} {etud["nom"]}"""
|
|
|
|
return etud["nomprenom"]
|
2023-05-15 18:00:22 +02:00
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
def format_pays(s):
|
|
|
|
"laisse le pays seulement si != FRANCE"
|
2021-08-21 00:24:51 +02:00
|
|
|
if s.upper() != "FRANCE":
|
2020-09-26 16:19:37 +02:00
|
|
|
return s
|
|
|
|
else:
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
2024-03-24 14:34:55 +01:00
|
|
|
def etud_sort_key(etud: dict) -> str:
|
2022-09-02 22:00:34 +02:00
|
|
|
"""Clé de tri pour les étudiants représentés par des dict (anciens codes).
|
|
|
|
Equivalent moderne: identite.sort_key
|
|
|
|
"""
|
2024-03-24 14:34:55 +01:00
|
|
|
return scu.sanitize_string(
|
|
|
|
(etud.get("nom_usuel") or etud["nom"] or "") + ";" + (etud["prenom"] or ""),
|
|
|
|
remove_spaces=False,
|
|
|
|
).lower()
|
2022-09-02 22:00:34 +02:00
|
|
|
|
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
_identiteEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"identite",
|
|
|
|
"etudid",
|
|
|
|
(
|
2023-10-23 23:50:13 +02:00
|
|
|
"admission_id",
|
|
|
|
"boursier",
|
2023-03-13 06:39:36 +01:00
|
|
|
"cas_allow_login",
|
|
|
|
"cas_allow_scodoc_login",
|
2023-10-23 23:50:13 +02:00
|
|
|
"cas_id",
|
2023-03-13 06:39:36 +01:00
|
|
|
"civilite_etat_civil",
|
2023-10-23 23:50:13 +02:00
|
|
|
"civilite", # 'M", "F", or "X"
|
|
|
|
"code_ine",
|
|
|
|
"code_nip",
|
2020-09-26 16:19:37 +02:00
|
|
|
"date_naissance",
|
|
|
|
"dept_naissance",
|
2023-10-23 23:50:13 +02:00
|
|
|
"etudid",
|
2020-09-26 16:19:37 +02:00
|
|
|
"foto",
|
2023-10-23 23:50:13 +02:00
|
|
|
"lieu_naissance",
|
|
|
|
"nationalite",
|
|
|
|
"nom_usuel",
|
|
|
|
"nom",
|
2020-09-26 16:19:37 +02:00
|
|
|
"photo_filename",
|
2023-10-23 23:50:13 +02:00
|
|
|
"prenom_etat_civil",
|
|
|
|
"prenom",
|
|
|
|
"statut",
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
2021-08-13 00:34:58 +02:00
|
|
|
filter_dept=True,
|
2020-09-26 16:19:37 +02:00
|
|
|
sortkey="nom",
|
|
|
|
input_formators={
|
|
|
|
"nom": force_uppercase,
|
2023-10-18 14:28:43 +02:00
|
|
|
"nom_usuel": force_uppercase,
|
2020-09-26 16:19:37 +02:00
|
|
|
"prenom": force_uppercase,
|
2023-03-13 06:39:36 +01:00
|
|
|
"prenom_etat_civil": force_uppercase,
|
2021-02-13 17:28:55 +01:00
|
|
|
"civilite": input_civilite,
|
2023-10-17 22:12:28 +02:00
|
|
|
"civilite_etat_civil": input_civilite_etat_civil,
|
2021-06-19 23:21:37 +02:00
|
|
|
"date_naissance": ndb.DateDMYtoISO,
|
2021-08-11 00:36:07 +02:00
|
|
|
"boursier": bool,
|
2020-09-26 16:19:37 +02:00
|
|
|
},
|
2021-06-19 23:21:37 +02:00
|
|
|
output_formators={"date_naissance": ndb.DateISOtoDMY},
|
2020-09-26 16:19:37 +02:00
|
|
|
convert_null_outputs_to_empty=True,
|
2021-08-08 16:01:10 +02:00
|
|
|
# allow_set_id=True, # car on specifie le code Apogee a la creation #sco8
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
identite_delete = _identiteEditor.delete
|
|
|
|
|
|
|
|
|
|
|
|
def identite_list(cnx, *a, **kw):
|
2021-02-13 17:28:55 +01:00
|
|
|
"""List, adding on the fly 'annee_naissance' and 'civilite_str' (M., Mme, "")."""
|
2020-09-26 16:19:37 +02:00
|
|
|
objs = _identiteEditor.list(cnx, *a, **kw)
|
|
|
|
for o in objs:
|
|
|
|
if o["date_naissance"]:
|
|
|
|
o["annee_naissance"] = int(o["date_naissance"].split("/")[2])
|
|
|
|
else:
|
|
|
|
o["annee_naissance"] = o["date_naissance"]
|
2021-02-13 17:28:55 +01:00
|
|
|
o["civilite_str"] = format_civilite(o["civilite"])
|
2023-10-16 22:51:31 +02:00
|
|
|
o["civilite_etat_civil_str"] = (
|
|
|
|
format_civilite(o["civilite_etat_civil"])
|
|
|
|
if o["civilite_etat_civil"]
|
|
|
|
else ""
|
|
|
|
)
|
2020-09-26 16:19:37 +02:00
|
|
|
return objs
|
|
|
|
|
|
|
|
|
|
|
|
def identite_edit_nocheck(cnx, args):
|
2020-10-12 23:16:41 +02:00
|
|
|
"""Modifie les champs mentionnes dans args, sans verification ni notification."""
|
2023-07-11 06:57:38 +02:00
|
|
|
etud = db.session.get(Identite, args["etudid"])
|
2023-05-15 19:50:11 +02:00
|
|
|
etud.from_dict(args)
|
|
|
|
db.session.commit()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2023-10-08 10:01:23 +02:00
|
|
|
def check_nom_prenom_homonyms(
|
|
|
|
nom: str = "", prenom: str = "", etudid=None
|
|
|
|
) -> tuple[bool, list[Identite]]:
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Check if nom and prenom are valid.
|
2020-10-12 23:16:41 +02:00
|
|
|
Also check for duplicates (homonyms), excluding etudid :
|
2020-09-26 16:19:37 +02:00
|
|
|
in general, homonyms are allowed, but it may be useful to generate a warning.
|
|
|
|
Returns:
|
2023-10-08 10:01:23 +02:00
|
|
|
True | False, homonyms
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2021-01-17 22:31:28 +01:00
|
|
|
if not nom or (not prenom and not scu.CONFIG.ALLOW_NULL_PRENOM):
|
2023-10-08 10:01:23 +02:00
|
|
|
return False, []
|
2021-07-12 15:13:10 +02:00
|
|
|
nom = nom.lower().strip()
|
2020-09-26 16:19:37 +02:00
|
|
|
if prenom:
|
2021-07-12 15:13:10 +02:00
|
|
|
prenom = prenom.lower().strip()
|
2020-09-26 16:19:37 +02:00
|
|
|
# Don't allow some special cars (eg used in sql regexps)
|
2021-01-17 22:31:28 +01:00
|
|
|
if scu.FORBIDDEN_CHARS_EXP.search(nom) or scu.FORBIDDEN_CHARS_EXP.search(prenom):
|
2023-10-23 23:50:13 +02:00
|
|
|
return False, []
|
2023-10-08 10:01:23 +02:00
|
|
|
# Liste homonymes (dans tous les départements):
|
|
|
|
query = Identite.query.filter(
|
|
|
|
Identite.nom.ilike(nom + "%"), Identite.prenom.ilike(prenom + "%")
|
|
|
|
)
|
|
|
|
if etudid is not None:
|
|
|
|
query = query.filter(Identite.id != etudid)
|
|
|
|
return True, query.all()
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def identite_edit(cnx, args, disable_notify=False):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Modifie l'identite d'un étudiant.
|
2021-08-21 00:24:51 +02:00
|
|
|
Si pref notification et difference, envoie message notification, sauf si disable_notify
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
2024-02-02 18:23:35 +01:00
|
|
|
check_etud_duplicate_code(args, "code_nip", edit=True)
|
|
|
|
check_etud_duplicate_code(args, "code_ine", edit=True)
|
2020-09-26 16:19:37 +02:00
|
|
|
notify_to = None
|
2021-08-21 00:24:51 +02:00
|
|
|
if not disable_notify:
|
2020-09-26 16:19:37 +02:00
|
|
|
try:
|
2021-07-28 17:03:54 +02:00
|
|
|
notify_to = sco_preferences.get_preference("notify_etud_changes_to")
|
2020-09-26 16:19:37 +02:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if notify_to:
|
|
|
|
# etat AVANT edition pour envoyer diffs
|
|
|
|
before = identite_list(cnx, {"etudid": args["etudid"]})[0]
|
|
|
|
|
|
|
|
identite_edit_nocheck(cnx, args)
|
|
|
|
|
|
|
|
# Notification du changement par e-mail:
|
|
|
|
if notify_to:
|
2021-06-19 23:21:37 +02:00
|
|
|
etud = get_etud_info(etudid=args["etudid"], filled=True)[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
after = identite_list(cnx, {"etudid": args["etudid"]})[0]
|
|
|
|
notify_etud_change(
|
|
|
|
notify_to,
|
|
|
|
etud,
|
|
|
|
before,
|
|
|
|
after,
|
|
|
|
"Modification identite %(nomprenom)s" % etud,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def identite_create(cnx, args):
|
2020-09-26 16:19:37 +02:00
|
|
|
"check unique etudid, then create"
|
2024-02-02 18:23:35 +01:00
|
|
|
check_etud_duplicate_code(args, "code_nip", edit=False)
|
|
|
|
check_etud_duplicate_code(args, "code_ine", edit=False)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
2021-07-09 17:47:06 +02:00
|
|
|
if "etudid" in args:
|
2020-09-26 16:19:37 +02:00
|
|
|
etudid = args["etudid"]
|
|
|
|
r = identite_list(cnx, {"etudid": etudid})
|
|
|
|
if r:
|
2024-02-02 18:23:35 +01:00
|
|
|
raise ScoValueError(f"Code identifiant (etudid) déjà utilisé ! ({etudid})")
|
2020-09-26 16:19:37 +02:00
|
|
|
return _identiteEditor.create(cnx, args)
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def notify_etud_change(email_addr, etud, before, after, subject):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Send email notifying changes to etud
|
|
|
|
before and after are two dicts, with values before and after the change.
|
|
|
|
"""
|
|
|
|
txt = [
|
|
|
|
"Code NIP:" + etud["code_nip"],
|
2021-02-13 17:28:55 +01:00
|
|
|
"Civilité: " + etud["civilite_str"],
|
2020-09-26 16:19:37 +02:00
|
|
|
"Nom: " + etud["nom"],
|
|
|
|
"Prénom: " + etud["prenom"],
|
2021-09-13 17:10:38 +02:00
|
|
|
"Etudid: " + str(etud["etudid"]),
|
2020-09-26 16:19:37 +02:00
|
|
|
"\n",
|
|
|
|
"Changements effectués:",
|
|
|
|
]
|
|
|
|
n = 0
|
|
|
|
for key in after.keys():
|
|
|
|
if before[key] != after[key]:
|
|
|
|
txt.append('%s: %s (auparavant: "%s")' % (key, after[key], before[key]))
|
|
|
|
n += 1
|
|
|
|
if not n:
|
|
|
|
return # pas de changements
|
|
|
|
txt = "\n".join(txt)
|
|
|
|
# build mail
|
2023-10-09 15:29:01 +02:00
|
|
|
log(f"notify_etud_change: sending notification to {email_addr}")
|
|
|
|
log(f"notify_etud_change: subject: {subject}")
|
2020-10-12 23:16:41 +02:00
|
|
|
log(txt)
|
2023-10-09 15:29:01 +02:00
|
|
|
email.send_email("[ScoDoc] " + subject, email.get_from_addr(), [email_addr], txt)
|
2020-10-12 23:16:41 +02:00
|
|
|
return txt
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
# --------
|
|
|
|
# Note: la table adresse n'est pas dans dans la table "identite"
|
|
|
|
# car on prevoit plusieurs adresses par etudiant (ie domicile, entreprise)
|
|
|
|
|
2021-06-19 23:21:37 +02:00
|
|
|
_adresseEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"adresse",
|
|
|
|
"adresse_id",
|
|
|
|
(
|
|
|
|
"adresse_id",
|
|
|
|
"etudid",
|
|
|
|
"email",
|
|
|
|
"emailperso",
|
|
|
|
"domicile",
|
|
|
|
"codepostaldomicile",
|
|
|
|
"villedomicile",
|
|
|
|
"paysdomicile",
|
|
|
|
"telephone",
|
|
|
|
"telephonemobile",
|
|
|
|
"fax",
|
|
|
|
"typeadresse",
|
|
|
|
"description",
|
|
|
|
),
|
|
|
|
convert_null_outputs_to_empty=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
adresse_create = _adresseEditor.create
|
|
|
|
adresse_delete = _adresseEditor.delete
|
|
|
|
adresse_list = _adresseEditor.list
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def adresse_edit(cnx, args, disable_notify=False):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Modifie l'adresse d'un étudiant.
|
2021-08-21 00:24:51 +02:00
|
|
|
Si pref notification et difference, envoie message notification, sauf si disable_notify
|
2020-09-26 16:19:37 +02:00
|
|
|
"""
|
|
|
|
notify_to = None
|
2021-08-21 00:24:51 +02:00
|
|
|
if not disable_notify:
|
2020-09-26 16:19:37 +02:00
|
|
|
try:
|
2021-07-28 17:03:54 +02:00
|
|
|
notify_to = sco_preferences.get_preference("notify_etud_changes_to")
|
2020-09-26 16:19:37 +02:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
if notify_to:
|
|
|
|
# etat AVANT edition pour envoyer diffs
|
|
|
|
before = adresse_list(cnx, {"etudid": args["etudid"]})[0]
|
|
|
|
|
|
|
|
_adresseEditor.edit(cnx, args)
|
|
|
|
|
|
|
|
# Notification du changement par e-mail:
|
|
|
|
if notify_to:
|
2021-06-19 23:21:37 +02:00
|
|
|
etud = get_etud_info(etudid=args["etudid"], filled=True)[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
after = adresse_list(cnx, {"etudid": args["etudid"]})[0]
|
|
|
|
notify_etud_change(
|
|
|
|
notify_to,
|
|
|
|
etud,
|
|
|
|
before,
|
|
|
|
after,
|
|
|
|
"Modification adresse %(nomprenom)s" % etud,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def getEmail(cnx, etudid):
|
|
|
|
"get email institutionnel etudiant (si plusieurs adresses, prend le premier non null"
|
|
|
|
adrs = adresse_list(cnx, {"etudid": etudid})
|
|
|
|
for adr in adrs:
|
|
|
|
if adr["email"]:
|
|
|
|
return adr["email"]
|
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
# ---------
|
2021-06-19 23:21:37 +02:00
|
|
|
_admissionEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"admissions",
|
|
|
|
"adm_id",
|
|
|
|
(
|
|
|
|
"adm_id",
|
|
|
|
"annee",
|
|
|
|
"bac",
|
|
|
|
"specialite",
|
|
|
|
"annee_bac",
|
|
|
|
"math",
|
|
|
|
"physique",
|
|
|
|
"anglais",
|
|
|
|
"francais",
|
|
|
|
"rang",
|
|
|
|
"qualite",
|
|
|
|
"rapporteur",
|
|
|
|
"decision",
|
|
|
|
"score",
|
|
|
|
"classement",
|
|
|
|
"apb_groupe",
|
|
|
|
"apb_classement_gr",
|
|
|
|
"commentaire",
|
|
|
|
"nomlycee",
|
|
|
|
"villelycee",
|
|
|
|
"codepostallycee",
|
|
|
|
"codelycee",
|
|
|
|
"type_admission",
|
|
|
|
"boursier_prec",
|
|
|
|
),
|
|
|
|
input_formators={
|
|
|
|
"annee": pivot_year,
|
|
|
|
"bac": force_uppercase,
|
|
|
|
"specialite": force_uppercase,
|
|
|
|
"annee_bac": pivot_year,
|
2021-06-19 23:21:37 +02:00
|
|
|
"classement": ndb.int_null_is_null,
|
|
|
|
"apb_classement_gr": ndb.int_null_is_null,
|
2021-08-10 17:12:10 +02:00
|
|
|
"boursier_prec": bool,
|
2020-09-26 16:19:37 +02:00
|
|
|
},
|
2021-01-17 22:31:28 +01:00
|
|
|
output_formators={"type_admission": lambda x: x or scu.TYPE_ADMISSION_DEFAULT},
|
2020-09-26 16:19:37 +02:00
|
|
|
convert_null_outputs_to_empty=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
admission_create = _admissionEditor.create
|
|
|
|
admission_delete = _admissionEditor.delete
|
|
|
|
admission_list = _admissionEditor.list
|
|
|
|
admission_edit = _admissionEditor.edit
|
|
|
|
|
2023-05-15 19:50:11 +02:00
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# Edition simultanee de identite et admission
|
2023-10-23 23:50:13 +02:00
|
|
|
class EtudIdentEditor:
|
2021-09-27 10:20:10 +02:00
|
|
|
def create(self, cnx, args):
|
2023-10-15 14:42:03 +02:00
|
|
|
admission_id = admission_create(cnx, args)
|
|
|
|
args["admission_id"] = admission_id
|
2021-09-27 10:20:10 +02:00
|
|
|
etudid = identite_create(cnx, args)
|
2020-09-26 16:19:37 +02:00
|
|
|
return etudid
|
|
|
|
|
2023-10-15 14:42:03 +02:00
|
|
|
def list(self, *args, **kw) -> list[dict]:
|
|
|
|
etuds_dict = identite_list(*args, **kw)
|
2020-09-26 16:19:37 +02:00
|
|
|
res = []
|
2023-10-15 14:42:03 +02:00
|
|
|
for etud_dict in etuds_dict:
|
|
|
|
res.append(etud_dict)
|
|
|
|
adms_dict = (
|
|
|
|
admission_list(args[0], args={"id": etud_dict["admission_id"]})
|
|
|
|
if etud_dict["admission_id"]
|
|
|
|
else []
|
|
|
|
)
|
|
|
|
if adms_dict:
|
2020-09-26 16:19:37 +02:00
|
|
|
# merge
|
2023-10-15 14:42:03 +02:00
|
|
|
adms_dict[0].pop("id", None)
|
|
|
|
adms_dict[0].pop("etudid", None)
|
|
|
|
res[-1] |= adms_dict[0]
|
2020-09-26 16:19:37 +02:00
|
|
|
else: # pas d'etudiant trouve
|
|
|
|
void_adm = {
|
|
|
|
k: None
|
2021-01-17 22:31:28 +01:00
|
|
|
for k in _admissionEditor.dbfields
|
2023-10-15 14:42:03 +02:00
|
|
|
if k not in ("id", "etudid", "adm_id")
|
2020-09-26 16:19:37 +02:00
|
|
|
}
|
2023-10-15 14:42:03 +02:00
|
|
|
res[-1] |= void_adm
|
2020-09-26 16:19:37 +02:00
|
|
|
# tri par nom
|
2021-07-09 23:19:30 +02:00
|
|
|
res.sort(key=itemgetter("nom", "prenom"))
|
2020-09-26 16:19:37 +02:00
|
|
|
return res
|
|
|
|
|
2021-09-27 10:20:10 +02:00
|
|
|
def edit(self, cnx, args, disable_notify=False):
|
|
|
|
identite_edit(cnx, args, disable_notify=disable_notify)
|
2020-09-26 16:19:37 +02:00
|
|
|
if "adm_id" in args: # safety net
|
|
|
|
admission_edit(cnx, args)
|
|
|
|
|
|
|
|
|
|
|
|
_etudidentEditor = EtudIdentEditor()
|
|
|
|
etudident_list = _etudidentEditor.list
|
|
|
|
etudident_edit = _etudidentEditor.edit
|
|
|
|
|
|
|
|
|
2021-09-18 13:42:19 +02:00
|
|
|
def log_unknown_etud():
|
|
|
|
"""Log request: cas ou getEtudInfo n'a pas ramene de resultat"""
|
|
|
|
etud_args = make_etud_args(raise_exc=False)
|
|
|
|
log(f"unknown student: args={etud_args}")
|
|
|
|
|
|
|
|
|
2022-09-26 20:57:52 +02:00
|
|
|
def get_etud_info(etudid=False, code_nip=False, filled=False) -> list[dict]:
|
2023-10-18 14:28:43 +02:00
|
|
|
"""infos sur un etudiant. If not found, returns empty list.
|
2021-11-20 17:21:51 +01:00
|
|
|
On peut spécifier etudid ou code_nip
|
|
|
|
ou bien cherche dans les arguments de la requête courante:
|
2021-09-27 10:20:10 +02:00
|
|
|
etudid, code_nip, code_ine (dans cet ordre).
|
2021-06-14 00:23:22 +02:00
|
|
|
"""
|
|
|
|
if etudid is None:
|
|
|
|
return []
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-08-22 13:24:36 +02:00
|
|
|
args = make_etud_args(etudid=etudid, code_nip=code_nip)
|
2021-06-19 23:21:37 +02:00
|
|
|
etud = etudident_list(cnx, args=args)
|
2021-06-14 00:23:22 +02:00
|
|
|
|
|
|
|
if filled:
|
2021-06-19 23:21:37 +02:00
|
|
|
fill_etuds_info(etud)
|
2021-06-14 00:23:22 +02:00
|
|
|
return etud
|
|
|
|
|
|
|
|
|
2023-05-15 19:50:11 +02:00
|
|
|
def create_etud(cnx, args: dict = None):
|
|
|
|
"""Création d'un étudiant. Génère aussi évenement et "news".
|
2020-12-26 00:11:55 +01:00
|
|
|
|
|
|
|
Args:
|
|
|
|
args: dict avec les attributs de l'étudiant
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
etud, l'étudiant créé.
|
|
|
|
"""
|
2022-04-12 17:12:51 +02:00
|
|
|
from app.models import ScolarNews
|
2021-06-19 23:21:37 +02:00
|
|
|
|
2020-12-26 00:11:55 +01:00
|
|
|
# creation d'un etudiant
|
2023-05-15 19:50:11 +02:00
|
|
|
args_dict = Identite.convert_dict_fields(args)
|
|
|
|
args_dict["dept_id"] = g.scodoc_dept_id
|
|
|
|
etud = Identite.create_etud(**args_dict)
|
|
|
|
db.session.add(etud)
|
|
|
|
db.session.commit()
|
2023-10-15 14:42:03 +02:00
|
|
|
admission = etud.admission
|
2023-05-15 22:20:28 +02:00
|
|
|
admission.from_dict(args)
|
|
|
|
db.session.add(admission)
|
|
|
|
db.session.commit()
|
2023-05-15 19:50:11 +02:00
|
|
|
etudid = etud.id
|
2020-12-26 00:11:55 +01:00
|
|
|
|
|
|
|
# log
|
|
|
|
logdb(
|
|
|
|
cnx,
|
|
|
|
method="etudident_edit_form",
|
|
|
|
etudid=etudid,
|
|
|
|
msg="creation initiale",
|
|
|
|
)
|
2023-11-22 23:31:16 +01:00
|
|
|
etud_dict = etudident_list(cnx, {"etudid": etudid})[0]
|
|
|
|
fill_etuds_info([etud_dict])
|
|
|
|
etud_dict["url"] = url_for(
|
2024-01-20 14:49:36 +01:00
|
|
|
"scolar.fiche_etud", scodoc_dept=g.scodoc_dept, etudid=etudid
|
2023-11-22 23:31:16 +01:00
|
|
|
)
|
2022-04-12 17:12:51 +02:00
|
|
|
ScolarNews.add(
|
|
|
|
typ=ScolarNews.NEWS_INSCR,
|
2023-11-22 23:31:16 +01:00
|
|
|
text=f"Nouvel étudiant {etud.html_link_fiche()}",
|
2023-11-23 17:08:18 +01:00
|
|
|
url=etud_dict["url"],
|
2023-06-23 10:37:32 +02:00
|
|
|
max_frequency=0,
|
2020-12-26 00:11:55 +01:00
|
|
|
)
|
2023-11-22 23:31:16 +01:00
|
|
|
return etud_dict
|
2020-12-26 00:11:55 +01:00
|
|
|
|
|
|
|
|
2020-09-26 16:19:37 +02:00
|
|
|
# ---------- "EVENTS"
|
2021-06-19 23:21:37 +02:00
|
|
|
_scolar_eventsEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"scolar_events",
|
|
|
|
"event_id",
|
|
|
|
(
|
|
|
|
"event_id",
|
|
|
|
"etudid",
|
|
|
|
"event_date",
|
|
|
|
"formsemestre_id",
|
|
|
|
"ue_id",
|
|
|
|
"event_type",
|
|
|
|
"comp_formsemestre_id",
|
|
|
|
),
|
|
|
|
sortkey="event_date",
|
|
|
|
convert_null_outputs_to_empty=True,
|
2021-06-19 23:21:37 +02:00
|
|
|
output_formators={"event_date": ndb.DateISOtoDMY},
|
|
|
|
input_formators={"event_date": ndb.DateDMYtoISO},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
# scolar_events_create = _scolar_eventsEditor.create
|
|
|
|
scolar_events_delete = _scolar_eventsEditor.delete
|
|
|
|
scolar_events_list = _scolar_eventsEditor.list
|
|
|
|
scolar_events_edit = _scolar_eventsEditor.edit
|
|
|
|
|
|
|
|
|
|
|
|
def scolar_events_create(cnx, args):
|
|
|
|
# several "events" may share the same values
|
2021-08-01 16:33:09 +02:00
|
|
|
_scolar_eventsEditor.create(cnx, args)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
# --------
|
2021-06-19 23:21:37 +02:00
|
|
|
_etud_annotationsEditor = ndb.EditableTable(
|
2020-09-26 16:19:37 +02:00
|
|
|
"etud_annotations",
|
|
|
|
"id",
|
|
|
|
(
|
|
|
|
"id",
|
|
|
|
"date",
|
|
|
|
"etudid",
|
|
|
|
"author",
|
|
|
|
"comment",
|
2021-08-10 17:12:10 +02:00
|
|
|
"author",
|
2020-09-26 16:19:37 +02:00
|
|
|
),
|
|
|
|
sortkey="date desc",
|
|
|
|
convert_null_outputs_to_empty=True,
|
2021-07-11 22:00:41 +02:00
|
|
|
output_formators={"comment": safehtml.html_to_safe_html, "date": ndb.DateISOtoDMY},
|
2020-09-26 16:19:37 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
etud_annotations_create = _etud_annotationsEditor.create
|
|
|
|
etud_annotations_delete = _etud_annotationsEditor.delete
|
|
|
|
etud_annotations_list = _etud_annotationsEditor.list
|
|
|
|
etud_annotations_edit = _etud_annotationsEditor.edit
|
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def add_annotations_to_etud_list(etuds):
|
2020-09-26 16:19:37 +02:00
|
|
|
"""Add key 'annotations' describing annotations of etuds
|
|
|
|
(used to list all annotations of a group)
|
|
|
|
"""
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2020-09-26 16:19:37 +02:00
|
|
|
for etud in etuds:
|
|
|
|
l = []
|
|
|
|
for a in etud_annotations_list(cnx, args={"etudid": etud["etudid"]}):
|
|
|
|
l.append("%(comment)s (%(date)s)" % a)
|
|
|
|
etud["annotations_str"] = ", ".join(l)
|
|
|
|
|
|
|
|
|
|
|
|
# -------- Noms des Lycées à partir du code
|
|
|
|
def read_etablissements():
|
2021-07-25 09:51:09 +02:00
|
|
|
filename = os.path.join(scu.SCO_TOOLS_DIR, scu.CONFIG.ETABL_FILENAME)
|
2020-09-26 16:19:37 +02:00
|
|
|
log("reading %s" % filename)
|
2021-10-11 22:22:42 +02:00
|
|
|
with open(filename) as f:
|
|
|
|
L = [x[:-1].split(";") for x in f]
|
2020-09-26 16:19:37 +02:00
|
|
|
E = {}
|
|
|
|
for l in L[1:]:
|
|
|
|
E[l[0]] = {
|
|
|
|
"name": l[1],
|
|
|
|
"address": l[2],
|
|
|
|
"codepostal": l[3],
|
|
|
|
"commune": l[4],
|
|
|
|
"position": l[5] + "," + l[6],
|
|
|
|
}
|
|
|
|
return E
|
|
|
|
|
|
|
|
|
|
|
|
ETABLISSEMENTS = None
|
|
|
|
|
|
|
|
|
|
|
|
def get_etablissements():
|
|
|
|
global ETABLISSEMENTS
|
|
|
|
if ETABLISSEMENTS is None:
|
|
|
|
ETABLISSEMENTS = read_etablissements()
|
|
|
|
return ETABLISSEMENTS
|
|
|
|
|
|
|
|
|
|
|
|
def get_lycee_infos(codelycee):
|
2024-01-20 14:49:36 +01:00
|
|
|
etablissements = get_etablissements()
|
|
|
|
return etablissements.get(codelycee, None)
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
2024-01-20 14:49:36 +01:00
|
|
|
def format_lycee_from_code(codelycee: str) -> str:
|
2020-09-26 16:19:37 +02:00
|
|
|
"Description lycee à partir du code"
|
2024-01-20 14:49:36 +01:00
|
|
|
etablissements = get_etablissements()
|
|
|
|
if codelycee in etablissements:
|
|
|
|
e = etablissements[codelycee]
|
2020-09-26 16:19:37 +02:00
|
|
|
nomlycee = e["name"]
|
2024-01-20 14:49:36 +01:00
|
|
|
return f"{nomlycee} ({e['commune']})"
|
|
|
|
return f"{codelycee} (établissement inconnu)"
|
|
|
|
|
|
|
|
|
|
|
|
def format_lycee(nomlycee: str) -> str:
|
|
|
|
"mise en forme nom de lycée"
|
|
|
|
nomlycee = nomlycee.strip()
|
|
|
|
s = nomlycee.lower()
|
|
|
|
if s[:5] == "lycee" or s[:5] == "lycée":
|
|
|
|
return nomlycee[5:]
|
2020-09-26 16:19:37 +02:00
|
|
|
else:
|
2024-01-20 14:49:36 +01:00
|
|
|
return nomlycee
|
2020-09-26 16:19:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
def etud_add_lycee_infos(etud):
|
|
|
|
"""Si codelycee est renseigné, ajout les champs au dict"""
|
|
|
|
if etud["codelycee"]:
|
|
|
|
il = get_lycee_infos(etud["codelycee"])
|
|
|
|
if il:
|
|
|
|
if not etud["codepostallycee"]:
|
|
|
|
etud["codepostallycee"] = il["codepostal"]
|
|
|
|
if not etud["nomlycee"]:
|
|
|
|
etud["nomlycee"] = il["name"]
|
|
|
|
if not etud["villelycee"]:
|
|
|
|
etud["villelycee"] = il["commune"]
|
|
|
|
if not etud.get("positionlycee", None):
|
|
|
|
if il["position"] != "0.0,0.0":
|
|
|
|
etud["positionlycee"] = il["position"]
|
|
|
|
return etud
|
|
|
|
|
|
|
|
|
|
|
|
""" Conversion fichier original:
|
|
|
|
f = open('etablissements.csv')
|
|
|
|
o = open('etablissements2.csv', 'w')
|
|
|
|
o.write( f.readline() )
|
|
|
|
for l in f:
|
|
|
|
fs = l.split(';')
|
2021-08-21 00:24:51 +02:00
|
|
|
nom = ' '.join( [ x.capitalize() for x in fs[1].split() ] )
|
|
|
|
adr = ' '.join( [ x.capitalize() for x in fs[2].split() ] )
|
|
|
|
ville=' '.join( [ x.capitalize() for x in fs[4].split() ] )
|
2020-09-26 16:19:37 +02:00
|
|
|
o.write( '%s;%s;%s;%s;%s\n' % (fs[0], nom, adr, fs[3], ville))
|
|
|
|
|
|
|
|
o.close()
|
|
|
|
"""
|
2021-06-02 22:40:34 +02:00
|
|
|
|
|
|
|
|
2021-08-21 00:24:51 +02:00
|
|
|
def list_scolog(etudid):
|
2021-06-02 22:40:34 +02:00
|
|
|
"liste des operations effectuees sur cet etudiant"
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-02 22:40:34 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
|
|
|
cursor.execute(
|
2021-09-13 22:10:01 +02:00
|
|
|
"SELECT * FROM scolog WHERE etudid=%(etudid)s ORDER BY DATE DESC",
|
2021-06-02 22:40:34 +02:00
|
|
|
{"etudid": etudid},
|
|
|
|
)
|
|
|
|
return cursor.dictfetchall()
|
|
|
|
|
|
|
|
|
2022-03-06 22:40:20 +01:00
|
|
|
def fill_etuds_info(etuds: list[dict], add_admission=True):
|
2021-06-02 22:40:34 +02:00
|
|
|
"""etuds est une liste d'etudiants (mappings)
|
|
|
|
Pour chaque etudiant, ajoute ou formatte les champs
|
|
|
|
-> informations pour fiche etudiant ou listes diverses
|
2022-02-11 18:27:10 +01:00
|
|
|
|
|
|
|
Si add_admission: ajoute au dict le schamps "admission" s'il n'y sont pas déjà.
|
2021-06-02 22:40:34 +02:00
|
|
|
"""
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-02 22:40:34 +02:00
|
|
|
for etud in etuds:
|
|
|
|
etudid = etud["etudid"]
|
2021-08-21 15:17:14 +02:00
|
|
|
etud["dept"] = g.scodoc_dept
|
2022-02-11 18:27:10 +01:00
|
|
|
# Admission
|
|
|
|
if add_admission and "nomlycee" not in etud:
|
|
|
|
admission = (
|
2023-10-18 14:28:43 +02:00
|
|
|
Admission.query.filter_by(id=etud["admission_id"])
|
|
|
|
.first()
|
|
|
|
.to_dict(no_nulls=True)
|
2022-02-11 18:27:10 +01:00
|
|
|
)
|
2022-09-02 20:56:55 +02:00
|
|
|
del admission["id"] # pour garder id == etudid dans etud
|
2022-02-11 18:27:10 +01:00
|
|
|
etud.update(admission)
|
|
|
|
#
|
2021-06-02 22:40:34 +02:00
|
|
|
adrs = adresse_list(cnx, {"etudid": etudid})
|
|
|
|
if not adrs:
|
|
|
|
# certains "vieux" etudiants n'ont pas d'adresse
|
|
|
|
adr = {}.fromkeys(_adresseEditor.dbfields, "")
|
|
|
|
adr["etudid"] = etudid
|
|
|
|
else:
|
|
|
|
adr = adrs[0]
|
|
|
|
if len(adrs) > 1:
|
2021-06-19 23:21:37 +02:00
|
|
|
log("fill_etuds_info: etudid=%s a %d adresses" % (etudid, len(adrs)))
|
2022-09-02 20:56:55 +02:00
|
|
|
adr.pop("id", None)
|
2021-06-02 22:40:34 +02:00
|
|
|
etud.update(adr)
|
|
|
|
format_etud_ident(etud)
|
|
|
|
|
2022-02-13 13:58:09 +01:00
|
|
|
etud.update(etud_inscriptions_infos(etudid, etud["ne"]))
|
2021-06-02 22:40:34 +02:00
|
|
|
|
2022-02-11 18:27:10 +01:00
|
|
|
# nettoyage champs souvent vides
|
2023-10-10 22:42:02 +02:00
|
|
|
etud["codepostallycee"] = etud.get("codepostallycee", "") or ""
|
|
|
|
etud["nomlycee"] = etud.get("nomlycee", "") or ""
|
2021-06-02 22:40:34 +02:00
|
|
|
|
|
|
|
|
2024-02-04 00:07:14 +01:00
|
|
|
# voir Identite.inscription_descr et Identite.to_dict_scodoc7(with_inscriptions=True)
|
2022-02-13 13:58:09 +01:00
|
|
|
def etud_inscriptions_infos(etudid: int, ne="") -> dict:
|
2022-11-13 14:55:18 +01:00
|
|
|
"""Dict avec les informations sur les semestres passés et courant.
|
|
|
|
{
|
2023-03-18 21:56:08 +01:00
|
|
|
"sems" : , # trie les semestres par date de debut, le plus recent d'abord
|
2022-11-13 14:55:18 +01:00
|
|
|
"ins" : ,
|
|
|
|
"cursem" : ,
|
2024-02-04 00:07:14 +01:00
|
|
|
"inscription" : , # cursem["titremois"]
|
|
|
|
"inscriptionstr" : , # "Inscrit en " + cursem["titremois"]
|
|
|
|
"inscription_formsemestre_id" : , # cursem["formsemestre_id"]
|
|
|
|
"etatincursem" : , # curi["etat"]
|
|
|
|
"situation" : , # descr_situation_etud(etudid, ne)
|
2022-11-13 14:55:18 +01:00
|
|
|
}
|
|
|
|
"""
|
2022-02-13 13:58:09 +01:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
from app.scodoc import sco_formsemestre_inscriptions
|
|
|
|
|
2023-10-17 22:12:28 +02:00
|
|
|
infos = {}
|
2022-02-13 13:58:09 +01:00
|
|
|
# Semestres dans lesquel il est inscrit
|
|
|
|
ins = sco_formsemestre_inscriptions.do_formsemestre_inscription_list(
|
|
|
|
{"etudid": etudid}
|
|
|
|
)
|
2023-10-17 22:12:28 +02:00
|
|
|
infos["ins"] = ins
|
2022-02-13 13:58:09 +01:00
|
|
|
sems = []
|
|
|
|
cursem = None # semestre "courant" ou il est inscrit
|
|
|
|
for i in ins:
|
|
|
|
sem = sco_formsemestre.get_formsemestre(i["formsemestre_id"])
|
|
|
|
if sco_formsemestre.sem_est_courant(sem):
|
|
|
|
cursem = sem
|
|
|
|
curi = i
|
|
|
|
sem["ins"] = i
|
|
|
|
sems.append(sem)
|
|
|
|
# trie les semestres par date de debut, le plus recent d'abord
|
|
|
|
# (important, ne pas changer (suivi cohortes))
|
|
|
|
sems.sort(key=itemgetter("dateord"), reverse=True)
|
2023-10-17 22:12:28 +02:00
|
|
|
infos["sems"] = sems
|
|
|
|
infos["cursem"] = cursem
|
2022-02-13 13:58:09 +01:00
|
|
|
if cursem:
|
2023-10-17 22:12:28 +02:00
|
|
|
infos["inscription"] = cursem["titremois"]
|
|
|
|
infos["inscriptionstr"] = "Inscrit en " + cursem["titremois"]
|
|
|
|
infos["inscription_formsemestre_id"] = cursem["formsemestre_id"]
|
|
|
|
infos["etatincursem"] = curi["etat"]
|
|
|
|
infos["situation"] = descr_situation_etud(etudid, ne)
|
2022-02-13 13:58:09 +01:00
|
|
|
else:
|
2023-10-17 22:12:28 +02:00
|
|
|
if infos["sems"]:
|
|
|
|
if infos["sems"][0]["dateord"] > time.strftime(
|
|
|
|
"%Y-%m-%d", time.localtime()
|
|
|
|
):
|
|
|
|
infos["inscription"] = "futur"
|
|
|
|
infos["situation"] = "futur élève"
|
2022-02-13 13:58:09 +01:00
|
|
|
else:
|
2023-10-17 22:12:28 +02:00
|
|
|
infos["inscription"] = "ancien"
|
|
|
|
infos["situation"] = "ancien élève"
|
2022-02-13 13:58:09 +01:00
|
|
|
else:
|
2023-10-17 22:12:28 +02:00
|
|
|
infos["inscription"] = "non inscrit"
|
|
|
|
infos["situation"] = infos["inscription"]
|
|
|
|
infos["inscriptionstr"] = infos["inscription"]
|
|
|
|
infos["inscription_formsemestre_id"] = None
|
|
|
|
infos["etatincursem"] = "?"
|
|
|
|
return infos
|
2022-02-13 13:58:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
def descr_situation_etud(etudid: int, ne="") -> str:
|
2022-03-06 22:40:20 +01:00
|
|
|
"""Chaîne décrivant la situation actuelle de l'étudiant
|
|
|
|
XXX Obsolete, utiliser Identite.descr_situation_etud() dans
|
|
|
|
les nouveaux codes
|
|
|
|
"""
|
2021-06-21 10:17:16 +02:00
|
|
|
from app.scodoc import sco_formsemestre
|
|
|
|
|
2021-06-15 13:59:56 +02:00
|
|
|
cnx = ndb.GetDBConnexion()
|
2021-06-02 22:40:34 +02:00
|
|
|
cursor = cnx.cursor(cursor_factory=ndb.ScoDocCursor)
|
|
|
|
cursor.execute(
|
2023-10-23 23:50:13 +02:00
|
|
|
"""SELECT I.formsemestre_id, I.etat
|
|
|
|
FROM notes_formsemestre_inscription I, notes_formsemestre S
|
|
|
|
WHERE etudid=%(etudid)s
|
|
|
|
and S.id = I.formsemestre_id
|
|
|
|
and date_debut < now()
|
|
|
|
and date_fin > now()
|
2021-08-11 13:01:37 +02:00
|
|
|
ORDER BY S.date_debut DESC;""",
|
2021-06-02 22:40:34 +02:00
|
|
|
{"etudid": etudid},
|
|
|
|
)
|
|
|
|
r = cursor.dictfetchone()
|
|
|
|
if not r:
|
2022-02-13 13:58:09 +01:00
|
|
|
situation = "non inscrit" + ne
|
2021-06-02 22:40:34 +02:00
|
|
|
else:
|
2021-08-19 10:28:35 +02:00
|
|
|
sem = sco_formsemestre.get_formsemestre(r["formsemestre_id"])
|
2022-09-30 22:43:39 +02:00
|
|
|
if r["etat"] == scu.INSCRIT:
|
2021-06-02 22:40:34 +02:00
|
|
|
situation = "inscrit%s en %s" % (ne, sem["titremois"])
|
|
|
|
# Cherche la date d'inscription dans scolar_events:
|
2021-06-19 23:21:37 +02:00
|
|
|
events = scolar_events_list(
|
2021-06-02 22:40:34 +02:00
|
|
|
cnx,
|
|
|
|
args={
|
|
|
|
"etudid": etudid,
|
|
|
|
"formsemestre_id": sem["formsemestre_id"],
|
|
|
|
"event_type": "INSCRIPTION",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if not events:
|
|
|
|
log(
|
|
|
|
"*** situation inconsistante pour %s (inscrit mais pas d'event)"
|
|
|
|
% etudid
|
|
|
|
)
|
|
|
|
date_ins = "???" # ???
|
|
|
|
else:
|
|
|
|
date_ins = events[0]["event_date"]
|
|
|
|
situation += " le " + str(date_ins)
|
|
|
|
else:
|
|
|
|
situation = "démission de %s" % sem["titremois"]
|
|
|
|
# Cherche la date de demission dans scolar_events:
|
2021-06-19 23:21:37 +02:00
|
|
|
events = scolar_events_list(
|
2021-06-02 22:40:34 +02:00
|
|
|
cnx,
|
|
|
|
args={
|
|
|
|
"etudid": etudid,
|
|
|
|
"formsemestre_id": sem["formsemestre_id"],
|
|
|
|
"event_type": "DEMISSION",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if not events:
|
|
|
|
log(
|
|
|
|
"*** situation inconsistante pour %s (demission mais pas d'event)"
|
|
|
|
% etudid
|
|
|
|
)
|
|
|
|
date_dem = "???" # ???
|
|
|
|
else:
|
|
|
|
date_dem = events[0]["event_date"]
|
|
|
|
situation += " le " + str(date_dem)
|
2021-08-14 10:12:40 +02:00
|
|
|
return situation
|