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
#
##############################################################################
""" Synchronisation des listes d ' étudiants avec liste portail (Apogée)
"""
2020-12-26 00:11:55 +01:00
import time
2021-07-09 23:19:30 +02:00
from operator import itemgetter
2020-09-26 16:19:37 +02:00
2024-08-23 23:16:49 +02:00
from flask import g , render_template , url_for
2021-09-02 18:05:22 +02:00
from flask_login import current_user
2021-08-16 08:33:12 +02:00
2023-10-15 14:42:03 +02:00
from app import db , log
2024-02-19 19:10:12 +01:00
from app . models import Admission , Adresse , FormSemestre , Identite , ScolarNews
2022-04-12 17:12:51 +02:00
2021-06-19 23:21:37 +02:00
import app . scodoc . sco_utils as scu
import app . scodoc . notesdb as ndb
2021-07-19 19:53:01 +02:00
from app . scodoc import sco_cache
2021-06-19 23:21:37 +02:00
from app . scodoc import sco_formsemestre
from app . scodoc import sco_formsemestre_inscriptions
from app . scodoc import sco_groups
from app . scodoc import sco_inscr_passage
from app . scodoc import sco_portal_apogee
from app . scodoc import sco_etud
from app . scodoc . sco_exceptions import ScoValueError
from app . scodoc . sco_permissions import Permission
2020-09-26 16:19:37 +02:00
# Clés utilisées pour la synchro
EKEY_APO = " nip "
EKEY_SCO = " code_nip "
EKEY_NAME = " code NIP "
2023-07-21 09:25:39 +02:00
2021-09-02 18:05:22 +02:00
# view:
2020-09-26 16:19:37 +02:00
def formsemestre_synchro_etuds (
formsemestre_id ,
2023-10-06 15:33:33 +02:00
etuds : list = None ,
inscrits_without_key : list = None ,
annee_apogee = None ,
2020-09-26 16:19:37 +02:00
submitted = False ,
dialog_confirmed = False ,
export_cat_xls = None ,
2023-10-06 15:33:33 +02:00
read_only = False ,
2020-09-26 16:19:37 +02:00
) :
""" Synchronise les étudiants de ce semestre avec ceux d ' Apogée.
2023-10-06 15:33:33 +02:00
etuds : liste des codes NIP des etudiants a inscrire ( ou deja inscrits )
inscrits_without_key : etudids des etudiants sans code NIP a laisser inscrits
read_only : Affiche sans permettre modifications
2020-09-26 16:19:37 +02:00
On a plusieurs cas de figure : L ' étudiant peut être
1 - présent dans Apogée et inscrit dans le semestre ScoDoc ( etuds_ok )
2 - dans Apogée , dans ScoDoc , mais pas inscrit dans le semestre ( etuds_noninscrits )
3 - dans Apogée et pas dans ScoDoc ( a_importer )
4 - inscrit dans le semestre ScoDoc , mais pas trouvé dans Apogée ( sur la base du code NIP )
2020-10-12 23:16:41 +02:00
2020-09-26 16:19:37 +02:00
Que faire ?
Cas 1 : rien à faire
Cas 2 : inscrire dans le semestre
Cas 3 : importer l ' étudiant (le créer)
puis l ' inscrire à ce semestre.
Cas 4 : lister les etudiants absents d ' Apogée (indiquer leur code NIP...)
- présenter les différents cas
- l ' utilisateur valide (cocher les étudiants à importer/inscrire)
- go
2021-09-02 18:05:22 +02:00
etuds : apres sélection par l ' utilisateur, la liste des étudiants selectionnés
2020-09-26 16:19:37 +02:00
que l ' on va importer/inscrire
"""
2023-10-06 15:33:33 +02:00
etuds = etuds or [ ]
2024-02-19 19:10:12 +01:00
formsemestre = FormSemestre . get_formsemestre ( formsemestre_id )
2023-10-06 15:33:33 +02:00
inscrits_without_key = inscrits_without_key or [ ]
2022-08-26 08:22:07 +02:00
log ( f " formsemestre_synchro_etuds: formsemestre_id= { formsemestre_id } " )
2021-08-19 10:28:35 +02:00
sem = sco_formsemestre . get_formsemestre ( formsemestre_id )
2020-09-26 16:19:37 +02:00
sem [ " etape_apo_str " ] = sco_formsemestre . formsemestre_etape_apo_str ( sem )
# Write access ?
2023-09-29 21:17:31 +02:00
if not current_user . has_permission ( Permission . EtudInscrit ) :
2020-09-26 16:19:37 +02:00
read_only = True
if read_only :
submitted = False
dialog_confirmed = False
# -- check lock
2021-08-10 12:57:38 +02:00
if not sem [ " etat " ] :
2020-09-26 16:19:37 +02:00
raise ScoValueError ( " opération impossible: semestre verrouille " )
if not sem [ " etapes " ] :
raise ScoValueError (
2024-02-20 21:30:08 +01:00
f """ opération impossible: ce semestre n ' a pas de code étape
( voir < a class = " stdlink " href = " {
url_for ( ' notes.formsemestre_editwithmodules ' ,
scodoc_dept = g . scodoc_dept , formsemestre_id = formsemestre . id )
} " >Modifier ce semestre</a>)
2024-05-20 10:46:36 +02:00
""" ,
safe = True ,
2020-09-26 16:19:37 +02:00
)
2021-09-02 18:05:22 +02:00
base_url = url_for (
" notes.formsemestre_synchro_etuds " ,
scodoc_dept = g . scodoc_dept ,
2021-09-25 10:43:06 +02:00
formsemestre_id = formsemestre_id ,
2023-10-06 15:33:33 +02:00
annee_apogee = annee_apogee or None , # si None, le param n'est pas dans l'URL
2021-09-02 18:05:22 +02:00
)
2020-09-26 16:19:37 +02:00
2023-10-06 15:33:33 +02:00
if annee_apogee is None : # année d'inscription par défaut
annee_apogee = scu . annee_scolaire_debut (
2021-08-21 15:17:14 +02:00
sem [ " annee_debut " ] , sem [ " mois_debut_ord " ]
2020-09-26 16:19:37 +02:00
)
2023-10-06 15:33:33 +02:00
annee_apogee = str ( annee_apogee )
2020-09-26 16:19:37 +02:00
2021-08-22 16:43:48 +02:00
if isinstance ( etuds , str ) :
2020-09-26 16:19:37 +02:00
etuds = etuds . split ( " , " ) # vient du form de confirmation
2021-08-22 16:43:48 +02:00
elif isinstance ( etuds , int ) :
2024-01-15 18:57:52 +01:00
etuds = [ str ( etuds ) ]
2021-09-25 15:12:38 +02:00
if isinstance ( inscrits_without_key , int ) :
inscrits_without_key = [ inscrits_without_key ]
elif isinstance ( inscrits_without_key , str ) :
2020-09-26 16:19:37 +02:00
inscrits_without_key = inscrits_without_key . split ( " , " )
2021-09-25 15:12:38 +02:00
elif not isinstance ( inscrits_without_key , list ) :
raise ValueError ( " invalid type for inscrits_without_key " )
2021-09-27 13:43:11 +02:00
inscrits_without_key = [ int ( x ) for x in inscrits_without_key if x ]
2020-09-26 16:19:37 +02:00
(
etuds_by_cat ,
a_importer ,
a_inscrire ,
inscrits_set ,
inscrits_without_key_all ,
etudsapo_ident ,
2023-10-06 15:33:33 +02:00
) = list_synch ( sem , annee_apogee = annee_apogee )
2020-09-26 16:19:37 +02:00
if export_cat_xls :
filename = export_cat_xls
2023-10-22 17:27:35 +02:00
xls = _build_page (
2020-09-26 16:19:37 +02:00
sem ,
etuds_by_cat ,
2023-10-06 15:33:33 +02:00
annee_apogee ,
2020-09-26 16:19:37 +02:00
export_cat_xls = export_cat_xls ,
base_url = base_url ,
read_only = read_only ,
)
2021-09-25 10:43:06 +02:00
return scu . send_file (
2021-09-02 18:05:22 +02:00
xls ,
2021-09-25 10:43:06 +02:00
mime = scu . XLS_MIMETYPE ,
filename = filename ,
suffix = scu . XLSX_SUFFIX ,
2021-09-02 18:05:22 +02:00
)
2020-09-26 16:19:37 +02:00
2024-08-23 23:16:49 +02:00
H = [ ]
2020-09-26 16:19:37 +02:00
if not submitted :
2023-10-22 17:27:35 +02:00
H + = _build_page (
2020-09-26 16:19:37 +02:00
sem ,
etuds_by_cat ,
2023-10-06 15:33:33 +02:00
annee_apogee ,
2020-09-26 16:19:37 +02:00
base_url = base_url ,
read_only = read_only ,
)
else :
etuds_set = set ( etuds )
a_importer = a_importer . intersection ( etuds_set )
a_desinscrire = inscrits_set - etuds_set
log ( " inscrits_without_key_all= %s " % set ( inscrits_without_key_all ) )
log ( " inscrits_without_key= %s " % inscrits_without_key )
a_desinscrire_without_key = set ( inscrits_without_key_all ) - set (
inscrits_without_key
)
log ( " a_desinscrire_without_key= %s " % a_desinscrire_without_key )
2024-02-19 19:10:12 +01:00
inscrits_ailleurs = set ( sco_inscr_passage . list_inscrits_date ( formsemestre ) )
2020-09-26 16:19:37 +02:00
a_inscrire = a_inscrire . intersection ( etuds_set )
if not dialog_confirmed :
# Confirmation
if a_importer :
2022-08-26 08:22:07 +02:00
H . append ( " <h3>Étudiants à importer et inscrire :</h3><ol> " )
2020-09-26 16:19:37 +02:00
for key in a_importer :
2022-08-26 08:22:07 +02:00
nom = f """ { etudsapo_ident [ key ] [ ' nom ' ] } { etudsapo_ident [ key ] . get ( " prenom " , " " ) } """
H . append ( f " <li> { nom } </li> " )
2020-09-26 16:19:37 +02:00
H . append ( " </ol> " )
if a_inscrire :
2022-08-26 08:22:07 +02:00
H . append ( " <h3>Étudiants à inscrire :</h3><ol> " )
2020-09-26 16:19:37 +02:00
for key in a_inscrire :
2022-08-26 08:22:07 +02:00
nom = f """ { etudsapo_ident [ key ] [ ' nom ' ] } { etudsapo_ident [ key ] . get ( " prenom " , " " ) } """
H . append ( f " <li> { nom } </li> " )
2020-09-26 16:19:37 +02:00
H . append ( " </ol> " )
a_inscrire_en_double = inscrits_ailleurs . intersection ( a_inscrire )
if a_inscrire_en_double :
2024-02-19 19:10:12 +01:00
H . append (
" <h3>dont étudiants déjà inscrits dans un autre semestre:</h3><ol> "
)
2020-09-26 16:19:37 +02:00
for key in a_inscrire_en_double :
2022-08-26 08:22:07 +02:00
nom = f """ { etudsapo_ident [ key ] [ ' nom ' ] } { etudsapo_ident [ key ] . get ( " prenom " , " " ) } """
2024-02-19 19:10:12 +01:00
H . append ( f ' <li class= " inscrit-ailleurs " > { nom } </li> ' )
2020-09-26 16:19:37 +02:00
H . append ( " </ol> " )
2021-09-25 15:12:38 +02:00
if a_desinscrire :
2022-08-26 08:22:07 +02:00
H . append ( " <h3>Étudiants à désinscrire :</h3><ol> " )
2020-09-26 16:19:37 +02:00
for key in a_desinscrire :
2021-08-22 13:24:36 +02:00
etud = sco_etud . get_etud_info ( filled = True , code_nip = key ) [ 0 ]
2020-09-26 16:19:37 +02:00
H . append ( ' <li class= " desinscription " > %(nomprenom)s </li> ' % etud )
2021-09-25 15:12:38 +02:00
H . append ( " </ol> " )
if a_desinscrire_without_key :
2022-08-26 08:22:07 +02:00
H . append ( " <h3>Étudiants à désinscrire (sans code):</h3><ol> " )
2020-09-26 16:19:37 +02:00
for etudid in a_desinscrire_without_key :
etud = inscrits_without_key_all [ etudid ]
2021-06-19 23:21:37 +02:00
sco_etud . format_etud_ident ( etud )
2020-09-26 16:19:37 +02:00
H . append ( ' <li class= " desinscription " > %(nomprenom)s </li> ' % etud )
H . append ( " </ol> " )
2021-09-25 15:12:38 +02:00
todo = (
a_importer or a_inscrire or a_desinscrire or a_desinscrire_without_key
)
if not todo :
2020-09-26 16:19:37 +02:00
H . append ( """ <h3>Il n ' y a rien à modifier !</h3> """ )
H . append (
2021-06-02 22:40:34 +02:00
scu . confirm_dialog (
2020-09-26 16:19:37 +02:00
dest_url = " formsemestre_synchro_etuds " ,
add_headers = False ,
cancel_url = " formsemestre_synchro_etuds?formsemestre_id= "
2021-08-10 17:12:10 +02:00
+ str ( formsemestre_id ) ,
2021-09-25 15:12:38 +02:00
OK = " Effectuer l ' opération " if todo else " OK " ,
2020-09-26 16:19:37 +02:00
parameters = {
" formsemestre_id " : formsemestre_id ,
" etuds " : " , " . join ( etuds ) ,
2021-09-25 15:12:38 +02:00
" inscrits_without_key " : " , " . join (
[ str ( x ) for x in inscrits_without_key ]
) ,
2020-09-26 16:19:37 +02:00
" submitted " : 1 ,
2023-10-06 15:33:33 +02:00
" annee_apogee " : annee_apogee ,
2020-09-26 16:19:37 +02:00
} ,
)
)
else :
# OK, do it
# Conversions des listes de codes NIP en listes de codes etudid
def nip2etudid ( code_nip ) :
2021-06-19 23:21:37 +02:00
etud = sco_etud . get_etud_info ( code_nip = code_nip ) [ 0 ]
2020-09-26 16:19:37 +02:00
return etud [ " etudid " ]
etudids_a_inscrire = [ nip2etudid ( x ) for x in a_inscrire ]
etudids_a_desinscrire = [ nip2etudid ( x ) for x in a_desinscrire ]
etudids_a_desinscrire + = a_desinscrire_without_key
#
2024-02-19 19:10:12 +01:00
# check decisions jury ici pour éviter de recontruire le cache
# après chaque desinscription
sco_formsemestre_inscriptions . check_if_has_decision_jury (
formsemestre , a_desinscrire
)
2022-05-04 20:26:45 +02:00
with sco_cache . DeferredSemCacheManager ( ) :
2024-02-19 19:10:12 +01:00
do_import_etuds_from_portal ( formsemestre , a_importer , etudsapo_ident )
sco_inscr_passage . do_inscrit ( formsemestre , etudids_a_inscrire )
sco_inscr_passage . do_desinscrit (
formsemestre , etudids_a_desinscrire , check_has_dec_jury = False
)
2020-09-26 16:19:37 +02:00
H . append (
2024-02-19 19:10:12 +01:00
f """ <h3>Opération effectuée</h3>
2020-09-26 16:19:37 +02:00
< ul >
2024-02-19 19:10:12 +01:00
< li > < a class = " stdlink " href = " {
url_for ( ' notes.formsemestre_synchro_etuds ' ,
scodoc_dept = g . scodoc_dept , formsemestre_id = formsemestre_id
) } " >Continuer la synchronisation</a>
< / li > """
2020-09-26 16:19:37 +02:00
)
#
partitions = sco_groups . get_partitions_list (
2021-08-19 10:28:35 +02:00
formsemestre_id , with_default = False
2020-09-26 16:19:37 +02:00
)
if partitions : # il y a au moins une vraie partition
H . append (
2021-08-16 08:33:12 +02:00
f """ <li><a class= " stdlink " href= " {
2023-07-21 09:25:39 +02:00
url_for ( " scolar.partition_editor " ,
2024-02-19 19:10:12 +01:00
scodoc_dept = g . scodoc_dept , formsemestre_id = formsemestre_id
) } " >Répartir les groupes de {partitions[0]["partition_name"]} </a>
< / li >
2023-07-21 09:25:39 +02:00
"""
2020-09-26 16:19:37 +02:00
)
2024-08-23 23:16:49 +02:00
return render_template (
" sco_page.j2 " , title = " Synchronisation des étudiants " , content = " \n " . join ( H )
)
2020-09-26 16:19:37 +02:00
2023-10-22 17:27:35 +02:00
def _build_page (
2020-09-26 16:19:37 +02:00
sem ,
etuds_by_cat ,
2023-10-06 15:33:33 +02:00
annee_apogee ,
2020-09-26 16:19:37 +02:00
export_cat_xls = None ,
base_url = " " ,
read_only = False ,
) :
if export_cat_xls :
return sco_inscr_passage . etuds_select_boxes (
2021-08-21 00:24:51 +02:00
etuds_by_cat , export_cat_xls = export_cat_xls , base_url = base_url
2020-09-26 16:19:37 +02:00
)
year = time . localtime ( ) [ 0 ]
2023-10-06 15:33:33 +02:00
if annee_apogee and abs ( year - int ( annee_apogee ) ) < 50 :
2021-07-09 17:47:06 +02:00
years = list (
2023-10-06 15:33:33 +02:00
range (
min ( year - 1 , int ( annee_apogee ) - 1 ) , max ( year , int ( annee_apogee ) ) + 1
)
2020-09-26 16:19:37 +02:00
)
else :
2021-07-09 17:47:06 +02:00
years = list ( range ( year - 1 , year + 1 ) )
2023-10-06 15:33:33 +02:00
annee_apogee = " "
2020-09-26 16:19:37 +02:00
options = [ ]
for y in years :
2023-10-06 15:33:33 +02:00
if str ( y ) == annee_apogee :
2020-09-26 16:19:37 +02:00
sel = " selected "
else :
sel = " "
options . append ( ' <option value= " %s " %s > %s </option> ' % ( str ( y ) , sel , str ( y ) ) )
2023-10-06 15:33:33 +02:00
if annee_apogee :
2020-09-26 16:19:37 +02:00
sel = " "
else :
sel = " selected "
options . append ( ' <option value= " " %s >toutes</option> ' % sel )
# sem['etape_apo_str'] = sem['etape_apo'] or '-'
H = [
""" <h2 class= " formsemestre " >Synchronisation des étudiants du semestre avec Apogée</h2> """ ,
""" <p>Actuellement <b> %d </b> inscrits dans ce semestre.</p> """
% (
len ( etuds_by_cat [ " etuds_ok " ] [ " etuds " ] )
+ len ( etuds_by_cat [ " etuds_nonapogee " ] [ " etuds " ] )
+ len ( etuds_by_cat [ " inscrits_without_key " ] [ " etuds " ] )
) ,
2023-10-22 17:27:35 +02:00
f """ <p>Code étape Apogée: { sem [ ' etape_apo_str ' ] } </p>
2020-09-26 16:19:37 +02:00
< form method = " post " action = " formsemestre_synchro_etuds " >
2023-10-22 17:27:35 +02:00
Année Apogée : < select id = " annee_apogee " name = " annee_apogee "
onchange = " document.location= ' formsemestre_synchro_etuds?formsemestre_id= {
sem [ ' formsemestre_id ' ]
} & annee_apogee = ' +document.getElementById( ' annee_apogee ' ).value " >
""" ,
2020-09-26 16:19:37 +02:00
" \n " . join ( options ) ,
2023-10-22 17:27:35 +02:00
""" </select>
2020-09-26 16:19:37 +02:00
""" ,
2024-02-12 10:12:46 +01:00
(
" "
if read_only
else f """
2023-10-22 17:27:35 +02:00
< input type = " hidden " name = " formsemestre_id " value = " {sem['formsemestre_id']} " / >
2020-09-26 16:19:37 +02:00
< input type = " submit " name = " submitted " value = " Appliquer les modifications " / >
& nbsp ; < a href = " #help " > aide < / a >
2024-02-12 10:12:46 +01:00
"""
) ,
2020-09-26 16:19:37 +02:00
sco_inscr_passage . etuds_select_boxes (
etuds_by_cat ,
sel_inscrits = False ,
show_empty_boxes = True ,
base_url = base_url ,
read_only = read_only ,
) ,
2024-02-12 10:12:46 +01:00
(
" "
if read_only
else """ <p/><input type= " submit " name= " submitted " value= " Appliquer les modifications " /> """
) ,
2021-08-21 00:24:51 +02:00
formsemestre_synchro_etuds_help ( sem ) ,
2020-09-26 16:19:37 +02:00
""" </form> """ ,
]
return H
2023-10-06 15:33:33 +02:00
def list_synch ( sem , annee_apogee = None ) :
2020-10-12 23:16:41 +02:00
""" """
2021-08-21 00:24:51 +02:00
inscrits = sco_inscr_passage . list_inscrits ( sem [ " formsemestre_id " ] , with_dems = True )
2020-09-26 16:19:37 +02:00
# Tous les ensembles d'etudiants sont ici des ensembles de codes NIP (voir EKEY_SCO)
# (sauf inscrits_without_key)
inscrits_set = set ( )
inscrits_without_key = { } # etudid : etud sans code NIP
for e in inscrits . values ( ) :
if not e [ EKEY_SCO ] :
inscrits_without_key [ e [ " etudid " ] ] = e
e [ " inscrit " ] = True # checkbox state
else :
inscrits_set . add ( e [ EKEY_SCO ] )
2023-10-06 15:33:33 +02:00
date_finalisation_inscr_by_nip = { } # nip : datefinalisationinscription_str
2020-09-26 16:19:37 +02:00
etapes = sem [ " etapes " ]
etudsapo_set = set ( )
etudsapo_ident = { }
2023-10-06 15:33:33 +02:00
etuds_payes = set ( ) # étudiants ayant payé (avec balise <paiementinscription> true)
2020-09-26 16:19:37 +02:00
for etape in etapes :
if etape :
etudsapo = sco_portal_apogee . get_inscrits_etape (
2023-10-06 15:33:33 +02:00
etape , annee_apogee = annee_apogee
2020-09-26 16:19:37 +02:00
)
2023-10-06 15:33:33 +02:00
etudsapo_set | = { x [ EKEY_APO ] for x in etudsapo }
2020-09-26 16:19:37 +02:00
for e in etudsapo :
if e [ EKEY_APO ] not in etudsapo_ident :
etudsapo_ident [ e [ EKEY_APO ] ] = e
2023-10-06 15:33:33 +02:00
date_finalisation_inscr_by_nip [ e [ EKEY_APO ] ] = e [
2020-09-26 16:19:37 +02:00
" datefinalisationinscription "
]
2023-10-06 15:33:33 +02:00
# note: si le portail ne renseigne pas cette balise, suppose que paiement ok
etuds_payes | = {
x [ EKEY_APO ] for x in etudsapo if x . get ( " paiementinscription " , True )
}
2020-09-26 16:19:37 +02:00
# categories:
etuds_ok = etudsapo_set . intersection ( inscrits_set )
2021-08-21 00:24:51 +02:00
etuds_aposco , a_importer , key2etudid = list_all ( etudsapo_set )
2020-09-26 16:19:37 +02:00
etuds_noninscrits = etuds_aposco - inscrits_set
etuds_nonapogee = inscrits_set - etudsapo_set
#
2021-06-15 13:59:56 +02:00
cnx = ndb . GetDBConnexion ( )
2023-07-21 09:25:39 +02:00
2020-09-26 16:19:37 +02:00
# Tri listes
def set_to_sorted_list ( etudset , etud_apo = False , is_inscrit = False ) :
def key2etud ( key , etud_apo = False ) :
if not etud_apo :
etudid = key2etudid [ key ]
2021-09-13 22:10:01 +02:00
etuds = sco_etud . identite_list ( cnx , { " etudid " : etudid } )
2021-09-13 23:36:56 +02:00
if not etuds : # ? cela ne devrait pas arriver XXX
2023-02-22 22:45:39 +01:00
log ( f " XXX key2etud etudid= { etudid } , type { type ( etudid ) } " )
2021-09-13 22:10:01 +02:00
etud = etuds [ 0 ]
2020-09-26 16:19:37 +02:00
etud [ " inscrit " ] = is_inscrit # checkbox state
2024-02-12 10:12:46 +01:00
etud [ " datefinalisationinscription " ] = (
date_finalisation_inscr_by_nip . get ( key , None )
)
2020-09-26 16:19:37 +02:00
if key in etudsapo_ident :
etud [ " etape " ] = etudsapo_ident [ key ] . get ( " etape " , " " )
else :
# etudiant Apogee
etud = etudsapo_ident [ key ]
etud [ " etudid " ] = " "
2021-02-13 17:28:55 +01:00
etud [ " civilite " ] = etud . get (
2020-09-26 16:19:37 +02:00
" sexe " , etud . get ( " gender " , " " )
) # la cle 'sexe' est prioritaire sur 'gender'
etud [ " inscrit " ] = is_inscrit # checkbox state
if key in etuds_payes :
etud [ " paiementinscription " ] = True
else :
etud [ " paiementinscription " ] = False
return etud
etuds = [ key2etud ( x , etud_apo ) for x in etudset ]
2021-07-10 13:58:25 +02:00
etuds . sort ( key = itemgetter ( " nom " ) )
2020-09-26 16:19:37 +02:00
return etuds
#
2021-09-25 10:43:06 +02:00
boites = {
" etuds_a_importer " : {
" etuds " : set_to_sorted_list ( a_importer , is_inscrit = True , etud_apo = True ) ,
2020-09-26 16:19:37 +02:00
" infos " : {
2021-09-25 10:43:06 +02:00
" id " : " etuds_a_importer " ,
2022-09-03 11:41:56 +02:00
" title " : " Étudiants dans Apogée à importer " ,
2023-10-22 17:27:35 +02:00
" help " : """ Ces étudiants sont inscrits dans cette étape Apogée mais ne sont pas connus par ScoDoc:
2021-09-25 10:43:06 +02:00
cocher les noms à importer et inscrire puis appuyer sur le bouton " Appliquer " . """ ,
2020-09-26 16:19:37 +02:00
" title_target " : " " ,
" with_checkbox " : True ,
2021-09-25 10:43:06 +02:00
" etud_key " : EKEY_APO , # clé à stocker dans le formulaire html
" filename " : " etuds_a_importer " ,
2020-09-26 16:19:37 +02:00
} ,
2021-09-25 10:43:06 +02:00
" nomprenoms " : etudsapo_ident ,
2020-09-26 16:19:37 +02:00
} ,
" etuds_noninscrits " : {
" etuds " : set_to_sorted_list ( etuds_noninscrits , is_inscrit = True ) ,
" infos " : {
" id " : " etuds_noninscrits " ,
2022-09-03 11:41:56 +02:00
" title " : " Étudiants non inscrits dans ce semestre " ,
2020-09-26 16:19:37 +02:00
" help " : """ Ces étudiants sont déjà connus par ScoDoc, sont inscrits dans cette étape Apogée mais ne sont pas inscrits à ce semestre ScoDoc. Cochez les étudiants à inscrire. """ ,
2022-10-02 23:43:29 +02:00
" comment " : """ dans ScoDoc et Apogée, <br>mais pas inscrits
2020-09-26 16:19:37 +02:00
dans ce semestre """ ,
" title_target " : " " ,
" with_checkbox " : True ,
" etud_key " : EKEY_SCO ,
2021-09-25 10:43:06 +02:00
" filename " : " etuds_non_inscrits " ,
2020-09-26 16:19:37 +02:00
} ,
} ,
" etuds_nonapogee " : {
" etuds " : set_to_sorted_list ( etuds_nonapogee , is_inscrit = True ) ,
" infos " : {
" id " : " etuds_nonapogee " ,
2022-09-03 11:41:56 +02:00
" title " : " Étudiants ScoDoc inconnus dans cette étape Apogée " ,
2020-09-26 16:19:37 +02:00
" help " : """ Ces étudiants sont inscrits dans ce semestre ScoDoc, ont un code NIP, mais ne sont pas inscrits dans cette étape Apogée. Soit ils sont en retard pour leur inscription, soit il s ' agit d ' une erreur: vérifiez avec le service Scolarité de votre établissement. Autre possibilité: votre code étape semestre ( %s ) est incorrect ou vous n ' avez pas choisi la bonne année d ' inscription. """
% sem [ " etape_apo_str " ] ,
" comment " : " à vérifier avec la Scolarité " ,
" title_target " : " " ,
" with_checkbox " : True ,
" etud_key " : EKEY_SCO ,
2021-09-25 10:43:06 +02:00
" filename " : " etuds_non_apogee " ,
2020-09-26 16:19:37 +02:00
} ,
} ,
" inscrits_without_key " : {
2021-07-09 17:47:06 +02:00
" etuds " : list ( inscrits_without_key . values ( ) ) ,
2020-09-26 16:19:37 +02:00
" infos " : {
" id " : " inscrits_without_key " ,
2022-09-03 11:41:56 +02:00
" title " : " Étudiants ScoDoc sans clé Apogée (NIP) " ,
2020-09-26 16:19:37 +02:00
" help " : """ Ces étudiants sont inscrits dans ce semestre ScoDoc, mais n ' ont pas de code NIP: on ne peut pas les mettre en correspondance avec Apogée. Utiliser le lien ' Changer les données identité ' dans le menu ' Etudiant ' sur leur fiche pour ajouter cette information. """ ,
" title_target " : " " ,
" with_checkbox " : True ,
" checkbox_name " : " inscrits_without_key " ,
2021-09-25 10:43:06 +02:00
" filename " : " inscrits_without_key " ,
} ,
} ,
" etuds_ok " : {
" etuds " : set_to_sorted_list ( etuds_ok , is_inscrit = True ) ,
" infos " : {
" id " : " etuds_ok " ,
2022-09-03 11:41:56 +02:00
" title " : " Étudiants dans Apogée et déjà inscrits " ,
2023-10-22 17:27:35 +02:00
" help " : """ Ces etudiants sont inscrits dans le semestre ScoDoc et sont présents dans Apogée:
2021-09-25 10:43:06 +02:00
tout est donc correct . Décocher les étudiants que vous souhaitez désinscrire . """ ,
" title_target " : " " ,
" with_checkbox " : True ,
" etud_key " : EKEY_SCO ,
" filename " : " etuds_inscrits_ok_apo " ,
2020-09-26 16:19:37 +02:00
} ,
} ,
}
return (
2021-09-25 10:43:06 +02:00
boites ,
2020-09-26 16:19:37 +02:00
a_importer ,
etuds_noninscrits ,
inscrits_set ,
inscrits_without_key ,
etudsapo_ident ,
)
2021-08-21 00:24:51 +02:00
def list_all ( etudsapo_set ) :
2020-09-26 16:19:37 +02:00
""" Cherche le sous-ensemble des etudiants Apogee de ce semestre
qui existent dans ScoDoc .
"""
# on charge TOUS les etudiants (au pire qq 100000 ?)
# si tres grosse base, il serait mieux de faire une requete
# d'interrogation par etudiant.
2021-06-15 13:59:56 +02:00
cnx = ndb . GetDBConnexion ( )
2021-06-19 23:21:37 +02:00
cursor = cnx . cursor ( cursor_factory = ndb . ScoDocCursor )
2021-09-13 22:10:01 +02:00
cursor . execute (
" SELECT "
+ EKEY_SCO
+ """ , id AS etudid
2021-09-13 23:16:02 +02:00
FROM identite WHERE dept_id = % ( dept_id ) s
2021-09-13 22:10:01 +02:00
""" ,
2021-09-13 23:36:56 +02:00
{ " dept_id " : g . scodoc_dept_id } ,
2021-09-13 22:10:01 +02:00
)
2020-09-26 16:19:37 +02:00
key2etudid = dict ( [ ( x [ 0 ] , x [ 1 ] ) for x in cursor . fetchall ( ) ] )
all_set = set ( key2etudid . keys ( ) )
# ne retient que ceux dans Apo
etuds_aposco = etudsapo_set . intersection (
all_set
) # a la fois dans Apogee et dans ScoDoc
a_importer = etudsapo_set - all_set # dans Apogee, mais inconnus dans ScoDoc
return etuds_aposco , a_importer , key2etudid
2021-08-21 00:24:51 +02:00
def formsemestre_synchro_etuds_help ( sem ) :
2023-10-22 17:27:35 +02:00
formsemestre_id = sem [ " formsemestre_id " ]
default_group_id = sco_groups . get_default_group ( sem [ " formsemestre_id " ] )
return f """ <div class= " pas_help pas_help_left " ><h3><a name= " help " >Explications</a></h3>
2020-09-26 16:19:37 +02:00
< p > Cette page permet d ' importer dans le semestre destination
< a class = " stdlink "
2023-10-22 17:27:35 +02:00
href = " { url_for( ' notes.formsemestre_status ' , scodoc_dept=g.scodoc_dept,
formsemestre_id = formsemestre_id )
} " > {sem['titreannee']} </a>
les étudiants inscrits dans l ' étape Apogée correspondante
( < b > < tt > { sem [ ' etape_apo_str ' ] } < / tt > < / b > )
2020-09-26 16:19:37 +02:00
< / p >
2021-09-02 18:05:22 +02:00
< p > Au départ , tous les étudiants d ' Apogée sont sélectionnés; vous pouvez
en déselectionner certains . Tous les étudiants cochés seront inscrits au semestre ScoDoc ,
les autres seront si besoin désinscrits . Aucune modification n ' est effectuée avant
2020-09-26 16:19:37 +02:00
d ' appuyer sur le bouton " Appliquer les modifications " .</p>
< h4 > Autres fonctions utiles < / h4 >
< ul >
2023-10-22 17:27:35 +02:00
< li > < a class = " stdlink " href = " {
url_for ( " scolar.check_group_apogee " , scodoc_dept = g . scodoc_dept ,
group_id = default_group_id )
} " >vérification des codes Apogée</a> (des étudiants déjà inscrits)
< / li >
< li > le < a class = " stdlink " href = " { url_for( ' notes.formsemestre_inscr_passage ' ,
scodoc_dept = g . scodoc_dept ,
formsemestre_id = formsemestre_id ) } " >
2020-09-26 16:19:37 +02:00
formulaire de passage < / a > qui permet aussi de désinscrire des étudiants
en cas d ' erreur, etc.</li>
< / ul >
2023-10-22 17:27:35 +02:00
< / div >
"""
2020-09-26 16:19:37 +02:00
2021-02-13 17:28:55 +01:00
def gender2civilite ( gender ) :
""" Le portail code en ' M ' , ' F ' , et ScoDoc en ' M ' , ' F ' , ' X ' """
if gender == " M " or gender == " F " or gender == " X " :
return gender
elif not gender :
return " X "
log ( ' gender2civilite: invalid value " %s " , defaulting to " X " ' % gender )
return " X " # "X" en général n'est pas affiché, donc bon choix si invalide
2020-09-26 16:19:37 +02:00
2023-10-15 14:42:03 +02:00
def get_opt_str ( etud : dict , k ) - > str | None :
" etud[k].strip() ou None "
2020-09-26 16:19:37 +02:00
v = etud . get ( k , None )
if not v :
return v
return v . strip ( )
2021-09-02 18:05:22 +02:00
def get_annee_naissance ( ddmmyyyyy : str ) - > int :
""" Extrait l ' année de la date stockée en dd/mm/yyyy dans le XML portail """
2020-09-26 16:19:37 +02:00
if not ddmmyyyyy :
return None
try :
return int ( ddmmyyyyy . split ( " / " ) [ 2 ] )
2021-09-02 18:05:22 +02:00
except ( ValueError , IndexError ) :
2020-09-26 16:19:37 +02:00
return None
2024-02-19 19:10:12 +01:00
def do_import_etuds_from_portal ( formsemestre : FormSemestre , a_importer , etudsapo_ident ) :
2020-10-12 23:16:41 +02:00
""" Inscrit les etudiants Apogee dans ce semestre. """
2023-10-15 14:42:03 +02:00
log ( f " do_import_etuds_from_portal: a_importer= { a_importer } " )
2020-09-26 16:19:37 +02:00
if not a_importer :
return
2021-06-15 13:59:56 +02:00
cnx = ndb . GetDBConnexion ( )
2020-09-26 16:19:37 +02:00
created_etudids = [ ]
try : # --- begin DB transaction
for key in a_importer :
2023-10-15 14:42:03 +02:00
etud_portal : dict = etudsapo_ident [ key ]
# -> toutes les infos renvoyées par le portail
2020-09-26 16:19:37 +02:00
# Traduit les infos portail en infos pour ScoDoc:
2023-10-15 14:42:03 +02:00
address = etud_portal . get ( " address " , " " ) . strip ( )
2020-09-26 16:19:37 +02:00
if address [ - 2 : ] == " \\ n " : # certains champs se terminent par \n
address = address [ : - 2 ]
2020-10-21 00:15:40 +02:00
2020-09-26 16:19:37 +02:00
args = {
2023-10-15 14:42:03 +02:00
" code_nip " : etud_portal [ " nip " ] ,
" nom " : etud_portal [ " nom " ] . strip ( ) ,
" prenom " : etud_portal [ " prenom " ] . strip ( ) ,
2020-10-21 00:15:40 +02:00
# Les champs suivants sont facultatifs (pas toujours renvoyés par le portail)
2023-10-15 14:42:03 +02:00
" code_ine " : etud_portal . get ( " ine " , " " ) . strip ( ) ,
" civilite " : gender2civilite ( etud_portal [ " gender " ] . strip ( ) ) ,
" etape " : etud_portal . get ( " etape " , None ) ,
" email " : etud_portal . get ( " mail " , " " ) . strip ( ) ,
" emailperso " : etud_portal . get ( " mailperso " , " " ) . strip ( ) ,
" date_naissance " : etud_portal . get ( " naissance " , " " ) . strip ( ) ,
" lieu_naissance " : etud_portal . get ( " ville_naissance " , " " ) . strip ( ) ,
" dept_naissance " : etud_portal . get ( " code_dep_naissance " , " " ) . strip ( ) ,
2020-09-26 16:19:37 +02:00
" domicile " : address ,
2023-10-15 14:42:03 +02:00
" codepostaldomicile " : etud_portal . get ( " postalcode " , " " ) . strip ( ) ,
" villedomicile " : etud_portal . get ( " city " , " " ) . strip ( ) ,
" paysdomicile " : etud_portal . get ( " country " , " " ) . strip ( ) ,
" telephone " : etud_portal . get ( " phone " , " " ) . strip ( ) ,
2020-09-26 16:19:37 +02:00
" typeadresse " : " domicile " ,
2023-10-15 14:42:03 +02:00
" boursier " : etud_portal . get ( " bourse " , None ) ,
2020-09-26 16:19:37 +02:00
" description " : " infos portail " ,
}
2020-10-21 00:15:40 +02:00
2020-09-26 16:19:37 +02:00
# Identite
2023-10-15 14:42:03 +02:00
etud : Identite = Identite . create_from_dict ( args )
db . session . flush ( )
created_etudids . append ( etud . id )
2020-09-26 16:19:37 +02:00
# Adresse
2023-10-15 14:42:03 +02:00
adresse = etud . adresses . first ( )
adresse . from_dict ( args )
# Admissions
do_import_etud_admission ( etud , etud_portal )
2020-09-26 16:19:37 +02:00
# Inscription au semestre
sco_formsemestre_inscriptions . do_formsemestre_inscription_with_modules (
2024-02-19 19:10:12 +01:00
formsemestre . id ,
2023-10-15 14:42:03 +02:00
etud . id ,
2022-09-30 22:43:39 +02:00
etat = scu . INSCRIT ,
2020-12-01 16:46:45 +01:00
etape = args [ " etape " ] ,
2020-09-26 16:19:37 +02:00
method = " synchro_apogee " ,
)
except :
cnx . rollback ( )
log ( " do_import_etuds_from_portal: aborting transaction ! " )
# Nota: db transaction is sometimes partly commited...
# here we try to remove all created students
2021-06-19 23:21:37 +02:00
cursor = cnx . cursor ( cursor_factory = ndb . ScoDocCursor )
2020-09-26 16:19:37 +02:00
for etudid in created_etudids :
2022-08-26 08:22:07 +02:00
log ( f " do_import_etuds_from_portal: deleting etudid= { etudid } " )
2020-09-26 16:19:37 +02:00
cursor . execute (
" delete from notes_moduleimpl_inscription where etudid= %(etudid)s " ,
{ " etudid " : etudid } ,
)
cursor . execute (
" delete from notes_formsemestre_inscription where etudid= %(etudid)s " ,
{ " etudid " : etudid } ,
)
cursor . execute (
" delete from scolar_events where etudid= %(etudid)s " , { " etudid " : etudid }
)
cursor . execute (
" delete from adresse where etudid= %(etudid)s " , { " etudid " : etudid }
)
cursor . execute (
" delete from group_membership where etudid= %(etudid)s " ,
{ " etudid " : etudid } ,
)
cursor . execute (
2021-08-21 15:17:14 +02:00
" delete from identite where id= %(etudid)s " , { " etudid " : etudid }
2020-09-26 16:19:37 +02:00
)
cnx . commit ( )
log ( " do_import_etuds_from_portal: re-raising exception " )
2021-06-13 23:37:14 +02:00
# > import: modif identite, adresses, inscriptions
2021-07-19 19:53:01 +02:00
sco_cache . invalidate_formsemestre ( )
2020-09-26 16:19:37 +02:00
raise
2022-04-12 17:12:51 +02:00
ScolarNews . add (
typ = ScolarNews . NEWS_INSCR ,
2022-08-26 08:22:07 +02:00
text = f " Import Apogée de { len ( created_etudids ) } étudiants en " ,
2024-02-19 19:10:12 +01:00
obj = formsemestre . id ,
2020-09-26 16:19:37 +02:00
)
2023-10-15 14:42:03 +02:00
def do_import_etud_admission ( etud : Identite , etud_data : dict , import_identite = False ) :
2020-09-26 16:19:37 +02:00
""" Importe les donnees admission pour cet etud.
2023-10-15 14:42:03 +02:00
etud_data est un dictionnaire traduit du XML portail
2020-09-26 16:19:37 +02:00
"""
annee_courante = time . localtime ( ) [ 0 ]
2023-10-15 14:42:03 +02:00
serie_bac , spe_bac = _get_bac ( etud_data )
2022-08-26 08:22:07 +02:00
# Les champs n'ont pas les mêmes noms dans Apogee et dans ScoDoc:
2020-09-26 16:19:37 +02:00
args = {
2023-10-15 14:42:03 +02:00
" annee " : get_opt_str ( etud_data , " inscription " ) or annee_courante ,
2020-09-26 16:19:37 +02:00
" bac " : serie_bac ,
" specialite " : spe_bac ,
2023-10-15 14:42:03 +02:00
" annee_bac " : get_opt_str ( etud_data , " anneebac " ) ,
" codelycee " : get_opt_str ( etud_data , " lycee " ) ,
" nomlycee " : get_opt_str ( etud_data , " nom_lycee " ) ,
" villelycee " : get_opt_str ( etud_data , " ville_lycee " ) ,
" codepostallycee " : get_opt_str ( etud_data , " codepostal_lycee " ) ,
" boursier " : get_opt_str ( etud_data , " bourse " ) ,
2020-09-26 16:19:37 +02:00
}
2023-10-15 14:42:03 +02:00
if etud . admission is None :
etud . admission = Admission ( )
args = { k : v for k , v in args . items ( ) if v not in ( " " , None ) }
etud . admission . from_dict ( args )
2020-09-26 16:19:37 +02:00
# Reimport des identités
if import_identite :
2023-10-15 14:42:03 +02:00
args = { }
2020-09-26 16:19:37 +02:00
# Les champs n'ont pas les mêmes noms dans Apogee et dans ScoDoc:
fields_apo_sco = [
( " naissance " , " date_naissance " ) ,
( " ville_naissance " , " lieu_naissance " ) ,
( " code_dep_naissance " , " dept_naissance " ) ,
( " nom " , " nom " ) ,
( " prenom " , " prenom " ) ,
( " ine " , " code_ine " ) ,
( " bourse " , " boursier " ) ,
]
for apo_field , sco_field in fields_apo_sco :
2023-10-15 14:42:03 +02:00
x = etud_data . get ( apo_field , " " ) . strip ( )
2020-09-26 16:19:37 +02:00
if x :
2020-10-21 00:15:40 +02:00
args [ sco_field ] = x
2020-09-26 16:19:37 +02:00
# Champs spécifiques:
2023-10-15 14:42:03 +02:00
civilite = gender2civilite ( etud_data [ " gender " ] . strip ( ) )
2021-02-13 17:28:55 +01:00
if civilite :
args [ " civilite " ] = civilite
2020-09-26 16:19:37 +02:00
2023-10-15 14:42:03 +02:00
etud . from_dict ( args )
db . session . add ( etud )
db . session . commit ( )
db . session . refresh ( etud )
2020-09-26 16:19:37 +02:00
2023-10-15 14:42:03 +02:00
def _get_bac ( etud ) - > tuple [ str | None , str | None ] :
2020-09-26 16:19:37 +02:00
bac = get_opt_str ( etud , " bac " )
if not bac :
return None , None
serie_bac = bac . split ( " - " ) [ 0 ]
if len ( serie_bac ) < 8 :
spe_bac = bac [ len ( serie_bac ) + 1 : ]
else :
serie_bac = bac
spe_bac = None
return serie_bac , spe_bac
2021-08-21 00:24:51 +02:00
def update_etape_formsemestre_inscription ( ins , etud ) :
2020-12-01 16:46:45 +01:00
""" Met à jour l ' étape de l ' inscription.
Args :
ins ( dict ) : formsemestre_inscription
etud ( dict ) : etudiant portail Apo
"""
if etud [ " etape " ] != ins [ " etape " ] :
ins [ " etape " ] = etud [ " etape " ]
2021-08-21 00:24:51 +02:00
sco_formsemestre_inscriptions . do_formsemestre_inscription_edit ( args = ins )
2020-12-01 16:46:45 +01:00
2020-09-26 16:19:37 +02:00
def formsemestre_import_etud_admission (
2023-11-26 18:28:56 +01:00
formsemestre_id : int , import_identite = True , import_email = False
) - > tuple [ list [ Identite ] , list [ Identite ] , list [ tuple [ Identite , str ] ] ] :
2020-10-12 23:16:41 +02:00
""" Tente d ' importer les données admission depuis le portail
2020-09-26 16:19:37 +02:00
pour tous les étudiants du semestre .
Si import_identite == True , recopie l ' identité (nom/prenom/sexe/date_naissance)
de chaque étudiant depuis le portail .
2020-10-12 23:16:41 +02:00
N ' affecte pas les etudiants inconnus sur le portail.
2023-11-26 18:28:56 +01:00
Renvoie :
- etuds_no_nip : liste d ' étudiants sans code NIP
- etuds_unknown : etudiants avec NIP mais inconnus du portail
- changed_mails : ( etudiant , old_mail ) pour ceux dont le mail a changé
2020-09-26 16:19:37 +02:00
"""
2021-08-19 10:28:35 +02:00
sem = sco_formsemestre . get_formsemestre ( formsemestre_id )
2021-06-19 23:21:37 +02:00
ins = sco_formsemestre_inscriptions . do_formsemestre_inscription_list (
2021-08-19 10:28:35 +02:00
{ " formsemestre_id " : formsemestre_id }
2021-06-19 23:21:37 +02:00
)
2023-10-15 14:42:03 +02:00
log ( f " formsemestre_import_etud_admission: { formsemestre_id } ( { len ( ins ) } etuds) " )
2023-11-26 18:28:56 +01:00
etuds_no_nip : list [ Identite ] = [ ]
etuds_unknown : list [ Identite ] = [ ]
2023-10-15 14:42:03 +02:00
changed_mails : list [ tuple [ Identite , str ] ] = [ ] # modification d'adresse mails
2020-10-12 23:16:41 +02:00
2020-10-14 12:36:18 +02:00
# Essaie de recuperer les etudiants des étapes, car
# la requete get_inscrits_etape est en général beaucoup plus
# rapide que les requetes individuelles get_etud_apogee
2023-10-06 15:33:33 +02:00
annee_apogee = str (
2021-02-03 22:00:41 +01:00
scu . annee_scolaire_debut ( sem [ " annee_debut " ] , sem [ " mois_debut_ord " ] )
)
2020-10-14 12:36:18 +02:00
apo_etuds = { } # nip : etud apo
for etape in sem [ " etapes " ] :
2023-10-06 15:33:33 +02:00
etudsapo = sco_portal_apogee . get_inscrits_etape (
etape , annee_apogee = annee_apogee
)
2020-10-14 12:36:18 +02:00
apo_etuds . update ( { e [ " nip " ] : e for e in etudsapo } )
2020-09-26 16:19:37 +02:00
for i in ins :
etudid = i [ " etudid " ]
2024-10-29 19:18:36 +01:00
etud : Identite = Identite . get_or_404 ( etudid )
2023-10-15 14:42:03 +02:00
code_nip = etud . code_nip
2020-09-26 16:19:37 +02:00
if not code_nip :
2023-11-26 18:28:56 +01:00
etuds_no_nip . append ( etud )
2020-09-26 16:19:37 +02:00
else :
2023-10-15 14:42:03 +02:00
data_apo = apo_etuds . get ( code_nip )
if not data_apo :
2020-10-14 12:36:18 +02:00
# pas vu dans les etudiants de l'étape, tente en individuel
2023-10-15 14:42:03 +02:00
data_apo = sco_portal_apogee . get_etud_apogee ( code_nip )
if data_apo :
update_etape_formsemestre_inscription ( i , data_apo )
2020-09-26 16:19:37 +02:00
do_import_etud_admission (
etud ,
2023-10-15 14:42:03 +02:00
data_apo ,
2020-09-26 16:19:37 +02:00
import_identite = import_identite ,
)
2023-10-15 14:42:03 +02:00
adresse = etud . adresses . first ( )
if adresse is None :
adresse = Adresse ( )
etud . adresses . append ( adresse )
apo_emailperso = data_apo . get ( " mailperso " , " " )
if adresse . emailperso and not apo_emailperso :
apo_emailperso = adresse . emailperso
2022-02-23 20:15:28 +01:00
if import_email :
2023-10-15 14:42:03 +02:00
if not " mail " in data_apo :
2022-02-23 20:15:28 +01:00
raise ScoValueError (
2024-02-12 10:12:46 +01:00
" la réponse portail n ' a pas le champ requis ' mail ' "
2022-02-23 20:15:28 +01:00
)
if (
2023-10-15 14:42:03 +02:00
adresse . email != data_apo [ " mail " ]
or adresse . emailperso != apo_emailperso
2022-02-23 20:15:28 +01:00
) :
2023-10-15 14:42:03 +02:00
old_mail = adresse . email
adresse . email = data_apo [ " mail " ]
adresse . emailperso = apo_emailperso
db . session . add ( adresse )
2022-02-23 20:15:28 +01:00
# notifie seulement les changements d'adresse mail institutionnelle
2023-10-15 14:42:03 +02:00
if adresse . email != data_apo [ " mail " ] :
changed_mails . append ( ( etud , old_mail ) )
2020-09-26 16:19:37 +02:00
else :
2023-11-26 18:28:56 +01:00
etuds_unknown . append ( etud )
2023-10-15 14:42:03 +02:00
db . session . commit ( )
2021-07-19 19:53:01 +02:00
sco_cache . invalidate_formsemestre ( formsemestre_id = sem [ " formsemestre_id " ] )
2023-11-26 18:28:56 +01:00
return etuds_no_nip , etuds_unknown , changed_mails