4277 lines
193 KiB
Python
4277 lines
193 KiB
Python
"""
|
|
Ce fichier permet de gerer les admissions à une formation (promotion)
|
|
dans le cadre d'une formation initiale.
|
|
|
|
Le sessions d'admission sont géré dans une collection appelée admission_session
|
|
"""
|
|
import ast
|
|
from zipfile import ZipFile
|
|
|
|
import bson
|
|
import pymongo
|
|
import xlsxwriter
|
|
from dateutil.relativedelta import relativedelta
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime, date
|
|
|
|
import apprenant_mgt
|
|
import partner_client
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
import GlobalVariable as MYSY_GV
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
import jinja2
|
|
from flask import send_file
|
|
from xhtml2pdf import pisa
|
|
from email.message import EmailMessage
|
|
from email.mime.text import MIMEText
|
|
from email import encoders
|
|
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from email.mime.base import MIMEBase
|
|
from email import encoders
|
|
import attached_file_mgt
|
|
|
|
"""
|
|
Creation d'une session d'admission
|
|
"""
|
|
def Add_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'date_debut', 'date_fin', 'nb_participant', 'adresse',
|
|
'code_postal', 'ville', 'code_session',
|
|
'tab_class_id', 'session_status', 'date_debut_inscription',
|
|
'date_fin_inscription', "prix_session",'session_ondemande', 'source', 'session_etape', 'pays', 'formateur_id',
|
|
'titre', 'location_type', 'site_formation_id', 'mode_animation', 'archive',
|
|
'entre_scolaire',
|
|
'memo', 'comment', 'class_session_id', 'process_inscription_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'code_session', ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
|
|
"""
|
|
Verifier la validité des formation
|
|
"""
|
|
tab_class_ids = []
|
|
tab_class_ids_ObjectId = []
|
|
if ("tab_class_id" in diction.keys()):
|
|
tab_class_ids = str(diction['tab_class_id']).split(",")
|
|
|
|
for tmp in tab_class_ids:
|
|
if (tmp):
|
|
is_valide_class = MYSY_GV.dbname['myclass'].count_documents({'_id':ObjectId(tmp), 'valide':'1', 'partner_owner_recid':str(my_partner['recid'])})
|
|
if( is_valide_class != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La formation '" + tmp + "' est invalide ")
|
|
return False, " La formation '" + tmp + "' est invalide "
|
|
tab_class_ids_ObjectId.append(ObjectId(tmp))
|
|
|
|
"""
|
|
Si cette admission à lié à une promotion
|
|
"""
|
|
if ("class_session_id" in diction.keys() and diction['class_session_id']):
|
|
is_valide_promotion = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['class_session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_promotion != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la promotion est invalide ")
|
|
return False, " L'identifiant de la promotion est invalide "
|
|
|
|
"""
|
|
Pour le mode d'animation d'une session de formation, on a :
|
|
0 => Présentiel
|
|
1 => Distanciel
|
|
2 => Hybride
|
|
"""
|
|
if ("mode_animation" in diction.keys() and diction['mode_animation'] not in ['0', '1', '2', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le mode d'animation est invalide ")
|
|
return False, " Le mode d'animation est invalide "
|
|
|
|
"""
|
|
Si cette admission à lié à une promotion
|
|
"""
|
|
if ("class_session_id" in diction.keys() and diction['class_session_id']):
|
|
is_valide_promotion = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['class_session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_promotion != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la promotion est invalide ")
|
|
return False, " L'identifiant de la promotion est invalide "
|
|
|
|
|
|
"""
|
|
Si cette admission à lié à un process d'admission
|
|
"""
|
|
if ("process_inscription_id" in diction.keys() and diction['process_inscription_id']):
|
|
is_valide_process_admiss = MYSY_GV.dbname['admission_setup'].count_documents(
|
|
{'_id': ObjectId(str(diction['process_inscription_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_process_admiss != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du processus d'admission est invalide ")
|
|
return False, " L'identifiant du processus d'admission est invalide "
|
|
|
|
|
|
if ("price_by" in diction.keys()):
|
|
if( str(diction['price_by']) not in MYSY_GV.TRAINING_PRICE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le prix par "+str(diction['price_by'])+" n'est valide. Les valeurs autorisées sont "+str(MYSY_GV.TRAINING_PRICE) )
|
|
return False, " Le prix par "+str(diction['price_by'])+" n'est valide. Les valeurs autorisées sont "+str(MYSY_GV.TRAINING_PRICE)+" "
|
|
|
|
|
|
if ("location_type" in diction.keys()):
|
|
if (str(diction['location_type']).lower() not in MYSY_GV.TRAINING_LOCATION_TYPE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le champ 'location_type' est incorrecte.")
|
|
return False, "Le champ 'location_type' est incorrect."
|
|
|
|
|
|
if ("entre_scolaire" in diction.keys()):
|
|
if (str(diction['entre_scolaire']).lower() not in MYSY_GV.TRAINING_ENTREE_SCOLAIRE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le champ 'Entrée scolaire' est incorrecte.")
|
|
return False, "Le champ 'Entrée scolaire' est incorrect."
|
|
|
|
formateur_id = ""
|
|
if ("formateur_id" in diction.keys() and diction['formateur_id']):
|
|
formateur_id = diction['formateur_id']
|
|
# Verification de la validité du formateur (collection employé)
|
|
is_formateur_id_ok = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(formateur_id)),
|
|
'partner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'
|
|
})
|
|
|
|
if (is_formateur_id_ok <= 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'identifiant du responsable est invalide")
|
|
return False, " L'identifiant du responsable est invalide "
|
|
|
|
|
|
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(
|
|
diction['date_debut'])[0:10] +
|
|
" est postérieure à la date de fin " + str(diction['date_fin'])[0:10] )
|
|
|
|
return False, " La date debut de formation " + str(diction['date_debut'])[0:10] + \
|
|
" est postérieure à la date de fin de formation " + str(diction['date_fin'])[0:10] + " "
|
|
|
|
# Verification de la cohérence des dates d'inscription si on a bien une date debut et une date de fin
|
|
if ("date_debut_inscription" in diction.keys() and "date_fin_inscription" in diction.keys()):
|
|
if (str(diction['date_debut_inscription']).strip() != "" and str(
|
|
diction['date_fin_inscription']).strip() != ""):
|
|
local_status = mycommon.CheckisDate(str(diction['date_debut_inscription'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date_debut_inscription n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de début d'inscription n'est pas au format jj/mm/aaaa "
|
|
|
|
local_status = mycommon.CheckisDate(str(diction['date_fin_inscription'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin d'inscription n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de fin d'inscription n'est pas au format jj/mm/aaaa "
|
|
|
|
if (datetime.strptime(str(diction['date_debut_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin_inscription'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de début d'inscription " + str(
|
|
diction['date_debut_inscription'])[0:10] + \
|
|
" est postérieure à la date de fin d'inscription " + str(diction['date_fin_inscription'])[
|
|
0:10] + " ")
|
|
|
|
return False, " La date de début d'inscription " + str(
|
|
diction['date_debut_inscription'])[0:10] + \
|
|
" est postérieure à la date de fin d'inscription " + str(
|
|
diction['date_fin_inscription'])[0:10] + " "
|
|
|
|
# Verification : Date de debut inscription n'est pas > date de fin de formation
|
|
if (datetime.strptime(str(diction['date_debut_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut d'inscription " + str(diction['date_debut_inscription']) + " est postérieure à la date de fin de formation " + str(
|
|
diction['date_fin']))
|
|
|
|
return False, " La date de debut d'inscription " + str(
|
|
diction['date_debut_inscription'])[0:10] + " est postérieure à la date de fin de formation " + str(
|
|
diction['date_fin'])[0:10] + " "
|
|
|
|
# Verification : Date de fin inscription n'est pas > date de fin de formation
|
|
if (datetime.strptime(str(diction['date_fin_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date de fin d'inscription " + str(diction['date_fin_inscription'])[0:10] + " est postérieure à la date de fin de la formation " + str(diction['date_fin'])[0:10])
|
|
|
|
return False, " La date de fin d'inscription " + str(diction['date_fin_inscription'])[0:10] + " est postérieure à la date de fin de la formation " + str(
|
|
diction['date_fin'])[0:10] + " "
|
|
|
|
|
|
|
|
new_data = diction
|
|
del diction['token']
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
new_data[str(val)] = ""
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
new_data['creation_date'] = str(datetime.now())
|
|
new_data['creation_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
inserted_id = MYSY_GV.dbname['admission_session'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer la session d'admission (2) ")
|
|
return False, " Impossible de créer la session d'admission (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session"
|
|
history_event_dict['related_collection_recid'] = str(inserted_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Création "
|
|
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " La session d'admission a été correctement ajoutée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de créer la session d'admission (2) "
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'une session d'admission
|
|
"""
|
|
|
|
def Update_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'date_debut', 'date_fin', 'nb_participant', 'adresse',
|
|
'code_postal', 'ville', 'code_session',
|
|
'tab_class_id', 'session_status', 'date_debut_inscription', 'date_fin_inscription',
|
|
'attestation_certif', "distantiel", "presentiel", "prix_session", 'contenu_ftion',
|
|
'session_ondemande', 'source', 'session_etape', 'pays', 'formateur_id',
|
|
'titre', 'location_type', 'site_formation_id', 'mode_animation', 'archive',
|
|
'entre_scolaire',
|
|
'memo', 'comment', 'class_session_id', 'process_inscription_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id',]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
new_data = diction
|
|
|
|
# Verifier que la configuration de l'admission
|
|
is_existe_admis_session = MYSY_GV.dbname['admission_session'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_admis_session < 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session d'admission est invalide ")
|
|
return False, " L'identifiant de la session d'admission est invalide "
|
|
|
|
"""
|
|
Verifier la validité des formation
|
|
"""
|
|
tab_class_ids = []
|
|
tab_class_ids_ObjectId = []
|
|
if ("tab_class_id" in diction.keys()):
|
|
tab_class_ids = str(diction['tab_class_id']).split(",")
|
|
|
|
for tmp in tab_class_ids:
|
|
if (tmp):
|
|
is_valide_class = MYSY_GV.dbname['myclass'].count_documents(
|
|
{'_id': ObjectId(tmp), 'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_class != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La formation '" + tmp + "' est invalide ")
|
|
return False, " La formation '" + tmp + "' est invalide "
|
|
tab_class_ids_ObjectId.append(ObjectId(tmp))
|
|
|
|
"""
|
|
Pour le mode d'animation d'une session de formation, on a :
|
|
0 => Présentiel
|
|
1 => Distanciel
|
|
2 => Hybride
|
|
"""
|
|
if ("mode_animation" in diction.keys() and diction['mode_animation'] not in ['0', '1', '2', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le mode d'animation est invalide ")
|
|
return False, " Le mode d'animation est invalide "
|
|
|
|
|
|
"""
|
|
Si cette admission à lié à une promotion
|
|
"""
|
|
if( "class_session_id" in diction.keys() and diction['class_session_id']):
|
|
is_valide_promotion = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(diction['class_session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if( is_valide_promotion != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la promotion est invalide ")
|
|
return False, " L'identifiant de la promotion est invalide "
|
|
|
|
"""
|
|
Si cette admission à lié à un process d'admission
|
|
"""
|
|
if ("process_inscription_id" in diction.keys() and diction['process_inscription_id']):
|
|
is_valide_process_admiss = MYSY_GV.dbname['admission_setup'].count_documents(
|
|
{'_id': ObjectId(str(diction['process_inscription_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_process_admiss != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du processus d'admission est invalide ")
|
|
return False, " L'identifiant du processus d'admission est invalide "
|
|
|
|
|
|
if ("price_by" in diction.keys()):
|
|
if (str(diction['price_by']) not in MYSY_GV.TRAINING_PRICE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le prix par " + str(
|
|
diction['price_by']) + " n'est valide. Les valeurs autorisées sont " + str(MYSY_GV.TRAINING_PRICE))
|
|
return False, " Le prix par " + str(
|
|
diction['price_by']) + " n'est valide. Les valeurs autorisées sont " + str(
|
|
MYSY_GV.TRAINING_PRICE) + " "
|
|
|
|
if ("location_type" in diction.keys()):
|
|
if (str(diction['location_type']).lower() not in MYSY_GV.TRAINING_LOCATION_TYPE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le champ 'location_type' est incorrecte.")
|
|
return False, "Le champ 'location_type' est incorrect."
|
|
|
|
if ("entre_scolaire" in diction.keys()):
|
|
if (str(diction['entre_scolaire']).lower() not in MYSY_GV.TRAINING_ENTREE_SCOLAIRE):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le champ 'Entrée scolaire' est incorrecte.")
|
|
return False, "Le champ 'Entrée scolaire' est incorrect."
|
|
|
|
|
|
if ("formateur_id" in diction.keys() and diction['formateur_id']):
|
|
formateur_id = diction['formateur_id']
|
|
# Verification de la validité du formateur (collection employé)
|
|
is_formateur_id_ok = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(formateur_id)),
|
|
'partner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'
|
|
})
|
|
|
|
if (is_formateur_id_ok <= 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'identifiant du responsable est invalide")
|
|
return False, " L'identifiant du responsable est invalide "
|
|
|
|
if (datetime.strptime(str(diction['date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(
|
|
diction['date_debut'])[0:10] +
|
|
" est postérieure à la date de fin " + str(diction['date_fin'])[0:10])
|
|
|
|
return False, " La date debut de formation " + str(diction['date_debut'])[0:10] + \
|
|
" est postérieure à la date de fin de formation " + str(diction['date_fin'])[0:10] + " "
|
|
|
|
# Verification de la cohérence des dates d'inscription si on a bien une date debut et une date de fin
|
|
if ("date_debut_inscription" in diction.keys() and "date_fin_inscription" in diction.keys()):
|
|
if (str(diction['date_debut_inscription']).strip() != "" and str(
|
|
diction['date_fin_inscription']).strip() != ""):
|
|
local_status = mycommon.CheckisDate(str(diction['date_debut_inscription'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date_debut_inscription n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de début d'inscription n'est pas au format jj/mm/aaaa "
|
|
|
|
local_status = mycommon.CheckisDate(str(diction['date_fin_inscription'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin d'inscription n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de fin d'inscription n'est pas au format jj/mm/aaaa "
|
|
|
|
if (datetime.strptime(str(diction['date_debut_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin_inscription'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de début d'inscription " + str(
|
|
diction['date_debut_inscription'])[0:10] + \
|
|
" est postérieure à la date de fin d'inscription " + str(diction['date_fin_inscription'])[
|
|
0:10] + " ")
|
|
|
|
return False, " La date de début d'inscription " + str(
|
|
diction['date_debut_inscription'])[0:10] + \
|
|
" est postérieure à la date de fin d'inscription " + str(
|
|
diction['date_fin_inscription'])[0:10] + " "
|
|
|
|
# Verification : Date de debut inscription n'est pas > date de fin de formation
|
|
if (datetime.strptime(str(diction['date_debut_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut d'inscription " + str(diction[
|
|
'date_debut_inscription']) + " est postérieure à la date de fin de formation " + str(
|
|
diction['date_fin']))
|
|
|
|
return False, " La date de debut d'inscription " + str(
|
|
diction['date_debut_inscription'])[
|
|
0:10] + " est postérieure à la date de fin de formation " + str(
|
|
diction['date_fin'])[0:10] + " "
|
|
|
|
# Verification : Date de fin inscription n'est pas > date de fin de formation
|
|
if (datetime.strptime(str(diction['date_fin_inscription'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date de fin d'inscription " + str(
|
|
diction['date_fin_inscription'])[
|
|
0:10] + " est postérieure à la date de fin de la formation " + str(
|
|
diction['date_fin'])[0:10])
|
|
|
|
return False, " La date de fin d'inscription " + str(diction['date_fin_inscription'])[
|
|
0:10] + " est postérieure à la date de fin de la formation " + str(
|
|
diction['date_fin'])[0:10] + " "
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
|
|
new_data['update_date'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
|
|
result = MYSY_GV.dbname['admission_session'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour la session d'admission (2) ")
|
|
return False, " Impossible de mettre à jour la session d'admission (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session"
|
|
history_event_dict['related_collection_recid'] = str(local_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Mise à jour "
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " La session a été correctement mise à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour la session d'admission "
|
|
|
|
|
|
"""
|
|
Suppression d'une session d'admission
|
|
regles :
|
|
- supprimer les inscrits
|
|
"""
|
|
|
|
def Delete_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id',]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id',]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
|
|
delete = MYSY_GV.dbname['admission_session'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
}, )
|
|
|
|
|
|
return True, " La session d'admission a été correctement supprimée "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer la session d'admission "
|
|
|
|
|
|
"""
|
|
Recuperer la liste des session d'admission d'un partenaire
|
|
"""
|
|
def Get_List_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['admission_session'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
class_session_id_code = ""
|
|
if( "class_session_id" in retval.keys() and retval['class_session_id'] ):
|
|
promo_data = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(retval['class_session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if(promo_data and "code_session" in promo_data.keys() ):
|
|
class_session_id_code = promo_data['code_session']
|
|
|
|
user['class_session_id_code'] = class_session_id_code
|
|
|
|
process_inscription_id_code = ""
|
|
if ("process_inscription_id" in retval.keys() and retval['process_inscription_id']):
|
|
process_admiss_data = MYSY_GV.dbname['admission_setup'].find_one(
|
|
{'_id': ObjectId(str(retval['process_inscription_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (process_admiss_data and "code" in process_admiss_data.keys()):
|
|
process_inscription_id_code = process_admiss_data['code']
|
|
|
|
user['process_inscription_id_code'] = process_inscription_id_code
|
|
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer la liste des sessions d'admission "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer les données d'une session d'admission donnée
|
|
"""
|
|
def Get_Given_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id' ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['admission_session'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer les données de la session d'admission "
|
|
|
|
|
|
"""
|
|
Inscrire une personne à une session d'admission
|
|
"""
|
|
|
|
def Add_Stagiaire_To_Admission_Session(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', 'nom', 'prenom', 'email', 'telephone', 'modefinancement',
|
|
'session_id', 'employeur', 'status', 'price',
|
|
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
|
|
'type_apprenant', 'civilite', 'date_naissance', 'memo', 'comment',
|
|
"num_secu", "is_rgpd", "situation_famille", "piece_identite_type", "piece_identite_num",
|
|
"type_mobilite", "telephone_bis", "nationalite", "is_handicap", "is_handicap", "is_droit_image",
|
|
'naissance_lieu', 'naissance_departement', 'naissance_pays', 'session_etape', 'ine', 'nom_fille'
|
|
]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['nom', 'prenom', 'email', 'telephone',
|
|
'session_id', 'token']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier qu'il n'y pas un étudiant avec le meme INE (Identifiant National Étudiant)
|
|
"""
|
|
if ("ine" in diction.keys() and diction['ine']):
|
|
is_exist_ine_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'ine': str(diction['ine']),
|
|
'session_id':str(diction['session_id']),
|
|
'partner_owner_recid':str(my_partner['recid'])
|
|
})
|
|
|
|
if (is_exist_ine_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) ")
|
|
return False, " Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) "
|
|
|
|
"""
|
|
Verififier l'existance et la valididé de la session
|
|
"""
|
|
my_session_data_qry = {"_id": ObjectId(str(diction['session_id'])), 'valide': '1'}
|
|
# print(" AddStagiairetoClass my_session_data_qry = ", my_session_data_qry)
|
|
|
|
my_session_data = MYSY_GV.dbname['admission_session'].find_one(my_session_data_qry)
|
|
if (my_session_data is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide"
|
|
|
|
"""
|
|
Verifier qu'il n'y pas déjà une presonne inscrite avec le meme email pour la meme session
|
|
"""
|
|
is_inscrit_exist = MYSY_GV.dbname['admission_session_inscrit'].count_documents({'email':diction['email'],
|
|
'session_id':diction['session_id'],
|
|
'partner_owner_recid':my_partner['recid']})
|
|
|
|
if( is_inscrit_exist > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Une personne est déjà inscrite à cette session avec la même adresse email ")
|
|
return False, " Une personne est déjà inscrite à cette session avec la même adresse email "
|
|
|
|
"""
|
|
Verifier la validité de l'etape
|
|
"""
|
|
if ("session_etape" in diction.keys() and str(diction['session_etape'])):
|
|
session_etape_id = MYSY_GV.dbname['admission_setup_etape'].count_documents(
|
|
{"_id": ObjectId(str(diction['session_etape'])),
|
|
'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (session_etape_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'etape est invalide ")
|
|
return False, " L'identifiant de l'etape est invalide "
|
|
|
|
|
|
if ("is_handicap" in diction.keys() and str(diction['is_handicap']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_handicap' est invalide ")
|
|
return False, " Le champ 'is_handicap' est invalide "
|
|
|
|
if ("is_droit_image" in diction.keys() and str(diction['is_droit_image']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_droit_image' est invalide ")
|
|
return False, " Le champ 'is_droit_image' est invalide "
|
|
|
|
if ("is_rgpd" in diction.keys() and str(diction['is_rgpd']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_rgpd' est invalide ")
|
|
return False, " Le champ 'is_rgpd' est invalide "
|
|
|
|
|
|
if ("date_naissance" in diction.keys()):
|
|
if diction['date_naissance']:
|
|
date_naissance = str(diction['date_naissance']).strip()
|
|
local_status = mycommon.CheckisDate(date_naissance)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de naissance n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de naissance n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
|
|
|
|
if ("type_apprenant" in diction.keys() and diction['type_apprenant']):
|
|
type_apprenant = str(mycommon.tryInt(diction['type_apprenant']))
|
|
if (type_apprenant not in MYSY_GV.INSCRIPTION_TYPE_APPRENANT):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type d'apprenant est invalide ")
|
|
return False, " Le type d'apprenant est invalide. Valeurs autorisées" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT)
|
|
|
|
new_data = diction
|
|
del diction['token']
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
new_data[str(val)] = ""
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
new_data['creation_date'] = str(datetime.now())
|
|
new_data['creation_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
if ("date_naissance" in new_data.keys() and new_data['date_naissance'] == ""):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
if ("date_naissance" not in new_data.keys()):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
inserted_data = MYSY_GV.dbname['admission_session_inscrit'].insert_one(new_data)
|
|
if (not inserted_data.inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible d'ajouter le candidat à la session d'admission (2) ")
|
|
return False, " Impossible d'ajouter le candidat à la session d'admission (2) "
|
|
|
|
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session_inscrit"
|
|
history_event_dict['related_collection_recid'] = str(inserted_data.inserted_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Inscription du candidat "+str(new_data['nom'])+" "+str(new_data['prenom'])+" "+str(inserted_data.inserted_id)
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " Le candidat a été correctement ajouté"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'ajouter le candidat à la session d'admission"
|
|
|
|
|
|
"""
|
|
Mettre à jour le session_etape d'une personne à une session d'admission
|
|
"""
|
|
|
|
def Update_Stagiaire_Only_Process_Step_Admission_Session(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', '_id', 'new_session_etape_code' ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id', 'new_session_etape_code' ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validé de l'inscrit
|
|
"""
|
|
is_existe_inscrit = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_inscrit != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
|
|
|
|
"""
|
|
Verifier la validité de l'etape
|
|
"""
|
|
session_etape_id = MYSY_GV.dbname['admission_setup_etape'].count_documents({"code":str(diction['new_session_etape_code']),
|
|
'valide':'1', 'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (session_etape_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'etape est invalide ")
|
|
return False, " L'identifiant de l'etape est invalide "
|
|
|
|
session_etape_id_data = MYSY_GV.dbname['admission_setup_etape'].find_one({"code":str(diction['new_session_etape_code']),
|
|
'valide':'1', 'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
new_data = {}
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['update_date'] = str(datetime.now())
|
|
new_data['session_etape'] = str(session_etape_id_data['_id'])
|
|
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
|
|
result = MYSY_GV.dbname['admission_session_inscrit'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
if (not result or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le candidat (2) ")
|
|
return False, " Impossible de mettre à jour le candidat (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session_inscrit"
|
|
history_event_dict['related_collection_recid'] = str(local_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Changement étape pour " + str(result['nom']) + " " + str(
|
|
result['prenom']) + " " + str(result['_id'])
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " Le candidat a été correctement mise à jour"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le candidat "
|
|
|
|
|
|
|
|
"""
|
|
Mettre à jour le statut d'acceptation d'une personne à une session d'admission (PROCESS_ADMISSION_STATUS)
|
|
- accepté
|
|
- rejeté
|
|
- liste attente
|
|
"""
|
|
|
|
def Update_Stagiaire_Only_Status_Admission_Session(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', '_id', 'new_status' ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id', 'new_status' ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validé de l'inscrit
|
|
"""
|
|
is_existe_inscrit = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_inscrit != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
is_existe_inscrit_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
old_statut = is_existe_inscrit_data['status']
|
|
|
|
if( diction['new_status'] not in MYSY_GV.PROCESS_ADMISSION_STATUS):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le statut est invalide ")
|
|
return False, " Le statut est invalide "
|
|
|
|
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
new_data = {}
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['update_date'] = str(datetime.now())
|
|
new_data['status'] = str(diction['new_status'])
|
|
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
|
|
result = MYSY_GV.dbname['admission_session_inscrit'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
if (not result or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le candidat (2) ")
|
|
return False, " Impossible de mettre à jour le candidat (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session_inscrit"
|
|
history_event_dict['related_collection_recid'] = str(local_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Changement statut pour " + str(result['nom']) + " " + str(
|
|
result['prenom']) + " " + str(result['_id'])+" ==> de "+str(old_statut) +" => "+diction['new_status']
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " Le statut a été correctement mis à jour"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le candidat "
|
|
|
|
|
|
|
|
"""
|
|
Mettre à jour une personne à une session d'admission
|
|
"""
|
|
|
|
def Update_Stagiaire_To_Admission_Session(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', '_id', 'nom', 'prenom', 'email', 'telephone', 'modefinancement',
|
|
'session_id', 'employeur', 'status', 'price',
|
|
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
|
|
'type_apprenant', 'civilite', 'date_naissance', 'memo', 'comment',
|
|
"num_secu", "is_rgpd", "situation_famille", "piece_identite_type", "piece_identite_num",
|
|
"type_mobilite", "telephone_bis", "nationalite", "is_handicap", "is_droit_image",
|
|
'naissance_lieu', 'naissance_departement', 'naissance_pays', 'session_etape', 'rang', 'ine',
|
|
'nom_fille'
|
|
]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['session_id', 'token', '_id']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
"""
|
|
Verifier qu'il n'y pas un étudiant avec le meme INE (Identifiant National Étudiant)
|
|
"""
|
|
if( "ine" in diction.keys() and diction['ine']):
|
|
is_exist_ine_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents({'_id':{'$ne':ObjectId(str(diction['_id']))},
|
|
'ine':str(diction['ine']),
|
|
'session_id': str(diction[
|
|
'session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])
|
|
})
|
|
|
|
if( is_exist_ine_count > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) ")
|
|
return False, " Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) "
|
|
|
|
"""
|
|
Verifier la validé de l'inscrit
|
|
"""
|
|
is_existe_inscrit = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_inscrit != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
"""
|
|
Verififier l'existance et la valididé de la session
|
|
"""
|
|
my_session_data_qry = {"_id": ObjectId(str(diction['session_id'])), 'valide': '1'}
|
|
# print(" AddStagiairetoClass my_session_data_qry = ", my_session_data_qry)
|
|
|
|
my_session_data = MYSY_GV.dbname['admission_session'].find_one(my_session_data_qry)
|
|
if (my_session_data is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide"
|
|
|
|
|
|
if ("rang" in diction.keys()):
|
|
local_status, local_note_max = mycommon.IsInt(str(diction['rang']).strip())
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" Le rang est " + str(diction['rang']) + " est invalide ")
|
|
return False, " Le rang est " + str(diction['rang']) + " est invalide "
|
|
|
|
|
|
"""
|
|
Verifier la validité de l'etape
|
|
"""
|
|
if("session_etape" in diction.keys() and str(diction['session_etape']) ):
|
|
session_etape_id = MYSY_GV.dbname['admission_setup_etape'].count_documents(
|
|
{"_id": ObjectId(str(diction['session_etape'])),
|
|
'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (session_etape_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'etape est invalide ")
|
|
return False, " L'identifiant de l'etape est invalide "
|
|
|
|
|
|
if ("is_handicap" in diction.keys() and str(diction['is_handicap']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_handicap' est invalide ")
|
|
return False, " Le champ 'is_handicap' est invalide "
|
|
|
|
if ("is_droit_image" in diction.keys() and str(diction['is_droit_image']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_droit_image' est invalide ")
|
|
return False, " Le champ 'is_droit_image' est invalide "
|
|
|
|
if ("is_rgpd" in diction.keys() and str(diction['is_rgpd']) not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'is_rgpd' est invalide ")
|
|
return False, " Le champ 'is_rgpd' est invalide "
|
|
|
|
if ("date_naissance" in diction.keys()):
|
|
if diction['date_naissance']:
|
|
date_naissance = str(diction['date_naissance']).strip()
|
|
local_status = mycommon.CheckisDate(date_naissance)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de naissance n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de naissance n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
|
|
|
|
if ("type_apprenant" in diction.keys() and diction['type_apprenant']):
|
|
type_apprenant = str(mycommon.tryInt(diction['type_apprenant']))
|
|
if (type_apprenant not in MYSY_GV.INSCRIPTION_TYPE_APPRENANT):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type d'apprenant est invalide ")
|
|
return False, " Le type d'apprenant est invalide. Valeurs autorisées" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT)
|
|
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
new_data = diction
|
|
new_data['update_date'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
if( "date_naissance" in new_data.keys() and new_data['date_naissance'] == ""):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
if( "date_naissance" not in new_data.keys() ):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
#print(" ### data_cle = ", data_cle)
|
|
|
|
|
|
result = MYSY_GV.dbname['admission_session_inscrit'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
if (not result or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le candidat (2) ")
|
|
return False, " Impossible de mettre à jour le candidat (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session_inscrit"
|
|
history_event_dict['related_collection_recid'] = str(local_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Inscription du candidat " + str(result['nom']) + " " + str(
|
|
result['prenom']) + " " + str(result['_id'])
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " Le candidat a été correctement mis à jour"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le candidat "
|
|
|
|
|
|
"""
|
|
Mise à jour en mode bulk avec un stringigy
|
|
"""
|
|
def Update_Stagiaire_To_Admission_Session_Bulk(diction):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['session_id', 'token', 'tab_rang_candidat']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Le champ '" + val + "' n'est pas autorisé")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['session_id', 'token', 'tab_rang_candidat']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verififier l'existance et la valididé de la session
|
|
"""
|
|
my_session_data_qry = {"_id": ObjectId(str(diction['session_id'])), 'valide': '1'}
|
|
# print(" AddStagiairetoClass my_session_data_qry = ", my_session_data_qry)
|
|
|
|
my_session_data = MYSY_GV.dbname['admission_session'].find_one(my_session_data_qry)
|
|
if (my_session_data is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide"
|
|
|
|
tab_rang_candidat = diction['tab_rang_candidat']
|
|
tab_rang_candidat_JSON = ast.literal_eval(tab_rang_candidat)
|
|
|
|
|
|
for local_data in tab_rang_candidat_JSON:
|
|
|
|
"""
|
|
Verifier la validé de l'inscrit
|
|
"""
|
|
is_existe_inscrit = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(str(local_data['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_inscrit != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
|
|
if ("rang" in local_data.keys()):
|
|
local_status, local_rang = mycommon.IsInt(str(local_data['rang']).strip())
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" Le rang est " + str(local_data['rang']) + " est invalide ")
|
|
return False, " Le rang est " + str(local_data['rang']) + " est invalide "
|
|
|
|
|
|
for local_data in tab_rang_candidat_JSON:
|
|
|
|
local_id = str(local_data['_id'])
|
|
new_data = {}
|
|
new_data['rang'] = str(local_data['rang'])
|
|
new_data['update_date'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
if( "date_naissance" in new_data.keys() and new_data['date_naissance'] == ""):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
if( "date_naissance" not in new_data.keys() ):
|
|
new_data['date_naissance'] = "01/01/1900"
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
result = MYSY_GV.dbname['admission_session_inscrit'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
if (not result or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le candidat (2) ")
|
|
return False, " Impossible de mettre à jour le candidat (2) "
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(token)
|
|
history_event_dict['related_collection'] = "admission_session_inscrit"
|
|
history_event_dict['related_collection_recid'] = str(local_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Inscription du candidat " + str(result['nom']) + " " + str(
|
|
result['prenom']) + " " + str(result['_id'])
|
|
|
|
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de logguer l'historique pour l'évènement : " + str(history_event_dict))
|
|
|
|
return True, " La mise à jour a été correctement faite"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de mettre à jour le candidat "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Suppression de l'inscription d'une personne à une session d'admission
|
|
"""
|
|
def Delete_Stagiaire_To_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id' ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id' ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
delete = MYSY_GV.dbname['admission_session_inscrit'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
}, )
|
|
|
|
return True, " L'inscription a été correctement supprimée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer l'inscription "
|
|
|
|
|
|
"""
|
|
Recuperer la liste des personne à une session d'admission
|
|
"""
|
|
def Get_List_Stagiaire_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'session_id']
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['session_id'] = str(diction['session_id'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['admission_session_inscrit'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
|
|
if ("date_naissance" not in retval.keys() or retval['date_naissance'] == ""):
|
|
retval['date_naissance'] = "01/01/1900"
|
|
|
|
if ("civilite" not in retval.keys() or retval['civilite'] == ""):
|
|
retval['civilite'] = "neutre"
|
|
|
|
if ("nom_fille" not in retval.keys() ):
|
|
retval['nom_fille'] = ""
|
|
|
|
age = relativedelta( date.today(), datetime.strptime(str(retval['date_naissance']), '%d/%m/%Y') )
|
|
retval['age'] = str(age.years)
|
|
|
|
session_etape_code = ""
|
|
if( "session_etape" in retval.keys() and retval['session_etape'] ):
|
|
admiss_session_etape_data = MYSY_GV.dbname['admission_setup_etape'].find_one(({'_id':ObjectId(str(retval['session_etape'])),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])}))
|
|
if( admiss_session_etape_data and "code" in admiss_session_etape_data.keys()):
|
|
session_etape_code = admiss_session_etape_data['code']
|
|
|
|
retval['session_etape_code'] = str(session_etape_code)
|
|
|
|
local_status, local_retval = Internal_Get_Pourcentage_Candidat_Document({'partner_recid':str(my_partner['recid']), 'inscrit_id':str(retval['_id'])})
|
|
if(local_status ):
|
|
retval['document_satatus'] = local_retval
|
|
if( "pourcentage_accepted" in local_retval.keys()):
|
|
retval['document_pourcentage_accepted'] = str(local_retval['pourcentage_accepted'])
|
|
|
|
if ("pourcentage_send" in local_retval.keys()):
|
|
retval['taux_document_pourcentage_received'] = str(local_retval['pourcentage_send'])
|
|
|
|
else:
|
|
retval['document_pourcentage_accepted'] = "0"
|
|
retval['taux_document_pourcentage_received'] = "0"
|
|
|
|
if( retval['document_pourcentage_accepted'] != "1"):
|
|
retval['document_alert_message'] = "Tous les documents ne sont pas validés"
|
|
else:
|
|
retval['document_alert_message'] = ""
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer la liste des inscrits"
|
|
|
|
"""
|
|
Recuperer les données d'une personne inscrite à une session d'admission
|
|
"""
|
|
def Get_Given_Stagiaire_Admission_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id' ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
print(" ## data_cle = ", data_cle)
|
|
|
|
for retval in MYSY_GV.dbname['admission_session_inscrit'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
if ("date_naissance" not in retval.keys() or retval['date_naissance'] == ""):
|
|
retval['date_naissance'] = "01/01/1900"
|
|
|
|
if ("civilite" not in retval.keys() or retval['civilite'] == ""):
|
|
retval['civilite'] = "neutre"
|
|
|
|
if ("nom_fille" not in retval.keys() ):
|
|
retval['nom_fille'] = ""
|
|
|
|
age = relativedelta(date.today(), datetime.strptime(str(retval['date_naissance']), '%d/%m/%Y'))
|
|
retval['age'] = str(age.years)
|
|
|
|
session_etape_code = ""
|
|
if ("session_etape" in retval.keys() and retval['session_etape']):
|
|
admiss_session_etape_data = MYSY_GV.dbname['admission_setup_etape'].find_one(
|
|
({'_id': ObjectId(str(retval['session_etape'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])}))
|
|
if (admiss_session_etape_data and "code" in admiss_session_etape_data.keys()):
|
|
session_etape_code = admiss_session_etape_data['code']
|
|
|
|
retval['session_etape_code'] = str(session_etape_code)
|
|
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer les données de l'inscrit "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction ajoute ou met à jour une image de profil d'un inscrit à une session d'admission
|
|
"""
|
|
def Add_Update_Inscrit_Admiss_Session_Image(file_img=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', 'file_img_recid', 'inscrit_id' ]
|
|
|
|
|
|
incom_keys = diction.keys()
|
|
|
|
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " : Le champ '"+val + "' n'est pas autorisé ")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'file_img_recid', 'inscrit_id' ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
# recuperation des paramettre
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que l'apprenant est valide
|
|
is_inscrit_id_valide_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents({'_id':ObjectId(diction['inscrit_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_inscrit_id_valide_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
inscrit_id_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(diction['inscrit_id']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if( file_img ):
|
|
recordimage_diction = {}
|
|
recordimage_diction['token'] = diction['token']
|
|
recordimage_diction['related_collection'] = "admission_session_inscrit"
|
|
recordimage_diction['type_img'] = "user"
|
|
recordimage_diction['related_collection_recid'] = str(inscrit_id_data['_id'])
|
|
recordimage_diction['image_recid'] = diction['file_img_recid']
|
|
|
|
#print(" ### recordimage_diction stagaire = ", recordimage_diction)
|
|
local_status, local_message = mycommon.recordClassImage_v2(file_img, MYSY_GV.upload_folder, recordimage_diction)
|
|
if( local_status is False):
|
|
return local_status, local_message
|
|
|
|
return True, "L'image a été correctement enregistrée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'enregistrer l'image"
|
|
|
|
|
|
""" Recuperation de l'image d'un inscrit
|
|
|
|
Important : important : on prend le 'related_collection_recid' comme le '_id' de la collection de l'apprenant
|
|
"""
|
|
def Get_Inscrit_Admiss_Session_Recorded_Image_from_front(diction=None):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'inscrit_id']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le champ '" + val + "' n'existe pas, requete annulée")
|
|
return False, " Impossible de récupérer les informations"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'inscrit_id']
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Impossible de récupérer les informations"
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que le candidat est valide
|
|
is_inscrit_id_valide_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(diction['inscrit_id']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_inscrit_id_valide_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
inscrit_id_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(diction['inscrit_id']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
|
|
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'admission_session_inscrit',
|
|
'related_collection_recid': str(inscrit_id_data['_id'])}
|
|
|
|
|
|
RetObject = []
|
|
partner_images = {}
|
|
# Recuperation des image 'logo' et 'cachet' si le partenaire en a
|
|
for retVal in MYSY_GV.dbname['mysy_images'].find(qery_images):
|
|
if ('type_img' in retVal.keys()):
|
|
if (retVal['type_img'] == "user"):
|
|
partner_images['logo_img'] = retVal['img'].decode()
|
|
partner_images['logo_img_recid'] = retVal['recid']
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(partner_images))
|
|
|
|
return True, RetObject
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recupérer l'image"
|
|
|
|
"""
|
|
Suppression d'un image d'un inscrit à une session d'admission
|
|
"""
|
|
def Delete_Inscrit_Admiss_Session_Image(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'image_recid', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'image_recid']
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
image_recid = ""
|
|
if ("image_recid" in diction.keys()):
|
|
if diction['image_recid']:
|
|
image_recid = diction['image_recid']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# " Lecture du fichier "
|
|
# print(" Lecture du fichier : " + saved_file + ". le token est :" + str(mytoken))
|
|
nb_line = 0
|
|
coll_name = MYSY_GV.dbname['mysy_images']
|
|
|
|
query_delete = {"recid": image_recid,}
|
|
|
|
|
|
ret_val = coll_name.delete_one({"recid": image_recid,}, )
|
|
|
|
|
|
|
|
#print(" ### recordClassImage_v2 :L'image a été correctement supprimée ")
|
|
return True, "L'image a été correctement supprimée"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de supprimer l'image "
|
|
|
|
|
|
"""
|
|
Recuperer les document fournis par un candidat dans le cadre d'un process d'inscription
|
|
"""
|
|
|
|
def Get_List_Candidat_Document(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'inscrit_id', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'inscrit_id', ]
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
image_recid = ""
|
|
if ("image_recid" in diction.keys()):
|
|
if diction['image_recid']:
|
|
image_recid = diction['image_recid']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
candidat_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(str(diction['inscrit_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
tab_relance_doc = []
|
|
if( "relances_document" in candidat_data.keys()):
|
|
tab_relance_doc = candidat_data['relances_document']
|
|
|
|
#print(" ## tab_relance_doc = ", tab_relance_doc)
|
|
|
|
qry_match = {"partner_owner_recid": str(my_partner['recid']), 'valide': '1', 'locked': '0'}
|
|
|
|
pipe_qry = ([
|
|
{"$addFields": {"admission_setup_document_id": {"$toString": "$_id"}}},
|
|
{'$match': qry_match},
|
|
{'$sort': {'_id': -1}},
|
|
{'$lookup': {
|
|
'from': 'download_files',
|
|
"let": {'admission_setup_document_id': "$admission_setup_document_id", 'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
{'$eq': ["$admission_setup_document_id", '$$admission_setup_document_id']},
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']},
|
|
|
|
{'$eq': ["$object_owner_id", str(diction['inscrit_id'])]},
|
|
{'$eq': ["$object_owner_collection", 'admission_session_inscrit_document']},
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
],
|
|
'as': 'collection_download_files'
|
|
}
|
|
},
|
|
|
|
])
|
|
|
|
print(" #### Get_List_Candidat_Document pipe_qry = ", pipe_qry)
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
for New_retVal in MYSY_GV.dbname['admission_setup_document'].aggregate(pipe_qry):
|
|
#print(" ## New_retVal = ",New_retVal)
|
|
|
|
if( "collection_download_files" in New_retVal.keys()):
|
|
for tmp_data in New_retVal['collection_download_files']:
|
|
if( "acceptance_status" not in tmp_data.keys()):
|
|
tmp_data['acceptance_status'] = ''
|
|
|
|
"""
|
|
Recuperer la dernière date de relance si il y a déja eu de la relance
|
|
"""
|
|
last_relance = ""
|
|
list_relance = []
|
|
|
|
for tmp in tab_relance_doc :
|
|
|
|
if( "document_id" in tmp.keys() and
|
|
"document_id" in New_retVal.keys() and
|
|
tmp['document_id'] == New_retVal['admission_setup_document_id']):
|
|
|
|
list_relance.append(tmp)
|
|
last_relance = "Dernière relance : "+str(tmp['document_date_relance'])[0:16]+" - Email"
|
|
|
|
|
|
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
user['relances_document'] = list_relance
|
|
user['last_relance'] = last_relance
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de recuperer la liste des documents du candidat "
|
|
|
|
|
|
"""
|
|
Cette fonction definit la completude des pièce jointe jointe d'un candidat
|
|
% de pièce validé
|
|
"""
|
|
def Get_Pourcentage_Candidat_Document(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'inscrit_id', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'inscrit_id', ]
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
image_recid = ""
|
|
if ("image_recid" in diction.keys()):
|
|
if diction['image_recid']:
|
|
image_recid = diction['image_recid']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
qry_match = {"partner_owner_recid": str(my_partner['recid']), 'valide': '1', 'locked': '0'}
|
|
|
|
pipe_qry = ([
|
|
{"$addFields": {"admission_setup_document_id": {"$toString": "$_id"}}},
|
|
{'$match': qry_match},
|
|
{'$sort': {'_id': -1}},
|
|
{'$lookup': {
|
|
'from': 'download_files',
|
|
"let": {'admission_setup_document_id': "$admission_setup_document_id", 'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
{'$eq': ["$admission_setup_document_id", '$$admission_setup_document_id']},
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']},
|
|
|
|
{'$eq': ["$object_owner_id", str(diction['inscrit_id'])]},
|
|
{'$eq': ["$object_owner_collection", 'admission_session_inscrit_document']},
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
],
|
|
'as': 'collection_download_files'
|
|
}
|
|
},
|
|
|
|
])
|
|
|
|
print(" #### Get_List_Candidat_Document pipe_qry = ", pipe_qry)
|
|
RetObject = []
|
|
nb_document_accepted = 0
|
|
nb_document_rejected = 0
|
|
nb_document_send = 0
|
|
nb_document_no_status = 0
|
|
nb_document_not_send = 0
|
|
|
|
total_document_waited = 0
|
|
|
|
node_status = {}
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
for New_retVal in MYSY_GV.dbname['admission_setup_document'].aggregate(pipe_qry):
|
|
#print(" ## New_retVal = ",New_retVal
|
|
total_document_waited = total_document_waited + 1
|
|
|
|
if( "collection_download_files" in New_retVal.keys()):
|
|
|
|
for tmp_data in New_retVal['collection_download_files']:
|
|
|
|
|
|
if( "acceptance_status" not in tmp_data.keys()):
|
|
tmp_data['acceptance_status'] = ''
|
|
nb_document_no_status = nb_document_no_status + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif ( tmp_data['acceptance_status'] == "1"):
|
|
nb_document_accepted = nb_document_accepted + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif (tmp_data['acceptance_status'] == "-1"):
|
|
nb_document_rejected = nb_document_rejected + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif (tmp_data['acceptance_status'] == ""):
|
|
nb_document_no_status = nb_document_no_status + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
|
|
nb_document_not_send = total_document_waited - nb_document_send
|
|
|
|
pourcentage_accepted = ""
|
|
pourcentage_rejected = ""
|
|
pourcentage_send = ""
|
|
|
|
if( total_document_waited > 0 ):
|
|
pourcentage_accepted = round(float(nb_document_accepted) / float(total_document_waited), 2)
|
|
pourcentage_rejected = round(float(nb_document_rejected) / float(total_document_waited), 2)
|
|
pourcentage_send = round(float(nb_document_send) / float(total_document_waited), 2)
|
|
|
|
|
|
node_status['nb_document_accepted'] = str(nb_document_accepted)
|
|
node_status['nb_document_rejected'] = str(nb_document_rejected)
|
|
node_status['nb_document_send'] = str(nb_document_send)
|
|
node_status['nb_document_no_status'] = str(nb_document_no_status)
|
|
node_status['nb_document_not_send'] = str(nb_document_not_send)
|
|
node_status['total_document_waited'] = str(total_document_waited)
|
|
|
|
node_status['pourcentage_accepted'] = str(pourcentage_accepted)
|
|
node_status['pourcentage_rejected'] = str(pourcentage_rejected)
|
|
node_status['pourcentage_send'] = str(pourcentage_send)
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(node_status))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de recuperer la liste des documents du candidat "
|
|
|
|
|
|
"""
|
|
Pour usage interne
|
|
"""
|
|
def Internal_Get_Pourcentage_Candidat_Document(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['partner_recid', 'inscrit_id', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['partner_recid', 'inscrit_id', ]
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
|
|
|
|
qry_match = {"partner_owner_recid": str(diction['partner_recid']), 'valide': '1', 'locked': '0'}
|
|
|
|
pipe_qry = ([
|
|
{"$addFields": {"admission_setup_document_id": {"$toString": "$_id"}}},
|
|
{'$match': qry_match},
|
|
{'$sort': {'_id': -1}},
|
|
{'$lookup': {
|
|
'from': 'download_files',
|
|
"let": {'admission_setup_document_id': "$admission_setup_document_id", 'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
{'$eq': ["$admission_setup_document_id", '$$admission_setup_document_id']},
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']},
|
|
|
|
{'$eq': ["$object_owner_id", str(diction['inscrit_id'])]},
|
|
{'$eq': ["$object_owner_collection", 'admission_session_inscrit_document']},
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
],
|
|
'as': 'collection_download_files'
|
|
}
|
|
},
|
|
|
|
])
|
|
|
|
|
|
RetObject = []
|
|
nb_document_accepted = 0
|
|
nb_document_rejected = 0
|
|
nb_document_send = 0
|
|
nb_document_no_status = 0
|
|
nb_document_not_send = 0
|
|
|
|
total_document_waited = 0
|
|
|
|
node_status = {}
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
for New_retVal in MYSY_GV.dbname['admission_setup_document'].aggregate(pipe_qry):
|
|
#print(" ## New_retVal = ",New_retVal
|
|
total_document_waited = total_document_waited + 1
|
|
|
|
if( "collection_download_files" in New_retVal.keys()):
|
|
|
|
for tmp_data in New_retVal['collection_download_files']:
|
|
|
|
|
|
if( "acceptance_status" not in tmp_data.keys()):
|
|
tmp_data['acceptance_status'] = ''
|
|
nb_document_no_status = nb_document_no_status + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif ( tmp_data['acceptance_status'] == "1"):
|
|
nb_document_accepted = nb_document_accepted + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif (tmp_data['acceptance_status'] == "-1"):
|
|
nb_document_rejected = nb_document_rejected + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
elif (tmp_data['acceptance_status'] == ""):
|
|
nb_document_no_status = nb_document_no_status + 1
|
|
nb_document_send = nb_document_send + 1
|
|
|
|
|
|
nb_document_not_send = total_document_waited - nb_document_send
|
|
|
|
pourcentage_accepted = ""
|
|
pourcentage_rejected = ""
|
|
pourcentage_send = ""
|
|
|
|
if( total_document_waited > 0 ):
|
|
pourcentage_accepted = round(float(nb_document_accepted) / float(total_document_waited), 2)
|
|
pourcentage_rejected = round(float(nb_document_rejected) / float(total_document_waited), 2)
|
|
pourcentage_send = round(float(nb_document_send) / float(total_document_waited), 2)
|
|
|
|
|
|
node_status['nb_document_accepted'] = str(nb_document_accepted)
|
|
node_status['nb_document_rejected'] = str(nb_document_rejected)
|
|
node_status['nb_document_send'] = str(nb_document_send)
|
|
node_status['nb_document_no_status'] = str(nb_document_no_status)
|
|
node_status['nb_document_not_send'] = str(nb_document_not_send)
|
|
node_status['total_document_waited'] = str(total_document_waited)
|
|
|
|
node_status['pourcentage_accepted'] = str(pourcentage_accepted)
|
|
node_status['pourcentage_rejected'] = str(pourcentage_rejected)
|
|
node_status['pourcentage_send'] = str(pourcentage_send)
|
|
|
|
|
|
|
|
|
|
return True, node_status
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de recuperer la liste des documents du candidat "
|
|
|
|
|
|
"""
|
|
Cette fonction retourne une synthèse
|
|
des candidats à une session d'admission.
|
|
|
|
Cette synthèse est un outil d'aide à l'acceptation du candidat
|
|
"""
|
|
|
|
def Get_Synthese_Candidat_Process_Admission(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'session_id']
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['session_id'] = str(diction['session_id'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['admission_session_inscrit'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
|
|
if ("date_naissance" not in retval.keys() or retval['date_naissance'] == ""):
|
|
retval['date_naissance'] = "01/01/1900"
|
|
|
|
if ("civilite" not in retval.keys() or retval['civilite'] == ""):
|
|
retval['civilite'] = "neutre"
|
|
|
|
if ("rang" not in retval.keys() or retval['rang'] == ""):
|
|
retval['rang'] = "999"
|
|
|
|
if ("inscrit_session_id" not in retval.keys() ):
|
|
retval['inscrit_session_id'] = ""
|
|
|
|
inscrit_session_code = ""
|
|
if( "inscrit_session_id" in retval.keys() and retval['inscrit_session_id']):
|
|
local_session_data = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(retval['inscrit_session_id']), 'partner_owner_recid':str(my_partner['recid'])})
|
|
if( local_session_data and 'code_session' in local_session_data.keys()):
|
|
inscrit_session_code = local_session_data['code_session']
|
|
|
|
retval['inscrit_session_code'] = inscrit_session_code
|
|
|
|
|
|
|
|
age = relativedelta( date.today(), datetime.strptime(str(retval['date_naissance']), '%d/%m/%Y') )
|
|
retval['age'] = str(age.years)
|
|
|
|
session_etape_code = ""
|
|
if( "session_etape" in retval.keys() and retval['session_etape'] ):
|
|
admiss_session_etape_data = MYSY_GV.dbname['admission_setup_etape'].find_one(({'_id':ObjectId(str(retval['session_etape'])),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])}))
|
|
if( admiss_session_etape_data and "code" in admiss_session_etape_data.keys()):
|
|
session_etape_code = admiss_session_etape_data['code']
|
|
|
|
retval['session_etape_code'] = str(session_etape_code)
|
|
|
|
local_status, local_retval = Internal_Get_Pourcentage_Candidat_Document({'partner_recid':str(my_partner['recid']), 'inscrit_id':str(retval['_id'])})
|
|
if(local_status ):
|
|
#retval['document_satatus'] = local_retval
|
|
if( "pourcentage_accepted" in local_retval.keys()):
|
|
retval['document_pourcentage_accepted'] = str(local_retval['pourcentage_accepted'])
|
|
|
|
if ("pourcentage_send" in local_retval.keys()):
|
|
retval['taux_document_pourcentage_received'] = str(local_retval['pourcentage_send'])
|
|
|
|
else:
|
|
retval['document_pourcentage_accepted'] = "0"
|
|
retval['taux_document_pourcentage_received'] = "0"
|
|
|
|
if( retval['document_pourcentage_accepted'] != "1"):
|
|
retval['document_alert_message'] = "Tous les documents ne sont pas validés"
|
|
else:
|
|
retval['document_alert_message'] = ""
|
|
|
|
|
|
"""
|
|
Recuperer les notes et observation pour chacun des jury et examen de session pour ce candidat
|
|
"""
|
|
|
|
tab_jury_exam_note_obser = []
|
|
|
|
tab_entete_exam_jury = []
|
|
|
|
for local_jury_examen_data in MYSY_GV.dbname['jury'].find(
|
|
{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0',
|
|
'cible': 'admission', 'session_id': str(diction['session_id'])}, ):
|
|
|
|
for jury_apprenant_data in MYSY_GV.dbname['jury_apprenant'].find({'inscription_id':str(retval['_id']),
|
|
'jury_id':str(local_jury_examen_data['_id']),
|
|
'partner_owner_recid':str(my_partner['recid'])}):
|
|
|
|
retval[str(local_jury_examen_data['code'])+"_note"] = jury_apprenant_data['jury_note']
|
|
retval[str(local_jury_examen_data['code']) + "_obs."] = jury_apprenant_data['jury_observation']
|
|
|
|
tab_entete_exam_jury.append(str(local_jury_examen_data['code'])+"_note");
|
|
tab_entete_exam_jury.append(str(local_jury_examen_data['code']) + "_obs.")
|
|
|
|
|
|
|
|
#retval['tab_jury_exam_note_observation'] = tab_jury_exam_note_obser
|
|
|
|
user['tab_entete_exam_jury'] = tab_entete_exam_jury
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer la liste des inscrits"
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'envoyer un email de relance manuelle
|
|
use case : relancer un candidat sur l'envoie d'un document
|
|
"""
|
|
def Candidat_Relance_Given_Document(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'inscrit_id', 'admission_setup_document_id' ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'inscrit_id', 'admission_setup_document_id' ]
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments des champs")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments "
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Verifier la validé de l'inscrit
|
|
"""
|
|
is_existe_candidat = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'_id': ObjectId(str(diction['inscrit_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_candidat != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du candidat est invalide ")
|
|
return False, " L'identifiant du candidat est invalide "
|
|
|
|
candidat_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(str(diction['inscrit_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
"""
|
|
verifier la validité du document a relancer
|
|
"""
|
|
is_valide_admission_setup_document_id = MYSY_GV.dbname['admission_setup_document'].count_documents({'_id':ObjectId(str(diction['admission_setup_document_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_admission_setup_document_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du document à relancer est invalide ")
|
|
return False, " L'identifiant du document à relancer est invalide "
|
|
|
|
admission_setup_document_data = MYSY_GV.dbname['admission_setup_document'].find_one(
|
|
{'_id': ObjectId(str(diction['admission_setup_document_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}, {'_id':1, 'code':1, 'description':1, 'type':1})
|
|
|
|
|
|
"""
|
|
Recuperer le modèle de document
|
|
"""
|
|
local_diction = {}
|
|
local_diction['ref_interne'] = "ADMISSION_RELANCE_DOCUMENT"
|
|
local_diction['type_doc'] = "email"
|
|
local_diction['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
courrier_data_status, courrier_data_retval = mycommon.Get_Courrier_Template_Include_Default_Data(local_diction)
|
|
if (courrier_data_status is False):
|
|
return courrier_data_status, courrier_data_retval
|
|
|
|
if ("contenu_doc" not in courrier_data_retval.keys() or str(courrier_data_retval['contenu_doc']) == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le modèle de courrier 'ADMISSION_RELANCE_DOCUMENT' n'est pas correctement configuré ")
|
|
return False, " Le modèle de courrier 'ADMISSION_RELANCE_DOCUMENT' n'est pas correctement configuré "
|
|
|
|
tab_candidat = []
|
|
tab_candidat.append(ObjectId(str(diction['inscrit_id'])))
|
|
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = str(mytoken)
|
|
new_diction['list_stagiaire_id'] = []
|
|
new_diction['list_session_id'] = []
|
|
new_diction['list_class_id'] = []
|
|
new_diction['list_client_id'] = []
|
|
new_diction['list_candidat_admission_id'] = tab_candidat
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
local_retval['relance_document'] = admission_setup_document_data
|
|
|
|
|
|
body = {
|
|
"params": local_retval,
|
|
}
|
|
|
|
# Recuperation des donnes smtp
|
|
local_stpm_status, partner_SMTP_COUNT_smtpsrv, partner_own_smtp_value, partner_SMTP_COUNT_password, partner_SMTP_COUNT_user, partner_SMTP_COUNT_From_User, partner_SMTP_COUNT_port = mycommon.Get_Partner_SMTP_Param(
|
|
my_partner['recid'])
|
|
|
|
if (local_stpm_status is False):
|
|
return local_stpm_status, partner_SMTP_COUNT_smtpsrv
|
|
|
|
## Creation du mail au format email
|
|
corps_mail_Template = jinja2.Template(str(courrier_data_retval['contenu_doc']))
|
|
sourceHtml = corps_mail_Template.render(params=body["params"])
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Traitement du sujet du mail
|
|
sujet_mail_Template = jinja2.Template(str(courrier_data_retval['sujet']))
|
|
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = sujetHtml
|
|
# Attacher l'eventuelle pièces jointes
|
|
|
|
|
|
msg['to'] = str(candidat_data['email'])
|
|
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
|
|
|
val = smtpserver.send_message(msg)
|
|
smtpserver.close()
|
|
|
|
print(" Email envoyé " + str(val))
|
|
|
|
"""
|
|
Mettre à jour les relances
|
|
"""
|
|
|
|
node = {}
|
|
document_code = ""
|
|
document_desc = ""
|
|
if( "code" in admission_setup_document_data.keys()):
|
|
document_code = admission_setup_document_data['code']
|
|
|
|
if ("description" in admission_setup_document_data.keys()):
|
|
document_desc = admission_setup_document_data['description']
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
node['document_id'] = str(admission_setup_document_data['_id'])
|
|
node['document_code'] = document_code
|
|
node['document_desc'] = document_desc
|
|
node['document_date_relance'] = now
|
|
node['document_type_relance'] = "email"
|
|
node['document_relance_by'] = str(my_partner['_id'])
|
|
|
|
relance_by_nom = ""
|
|
if( "nom" in my_partner.keys()):
|
|
relance_by_nom = my_partner['nom']
|
|
|
|
relance_by_email = ""
|
|
if ("email" in my_partner.keys()):
|
|
relance_by_email = my_partner['email']
|
|
|
|
node['relance_by_nom'] = str(relance_by_nom)
|
|
node['relance_by_email'] = str(relance_by_email)
|
|
|
|
|
|
update = MYSY_GV.dbname['admission_session_inscrit'].update_one( {'_id': ObjectId(str(diction['inscrit_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
|
|
{
|
|
'$push': {
|
|
"relances_document": {'$each': [node]},
|
|
|
|
}
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return True, "L'email de relance a été correctement envoyé "
|
|
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'envoyer l'email de relance "
|
|
|
|
|
|
|
|
"""
|
|
Inscrire une liste d'apprenant à une session de formation
|
|
|
|
Si une unité d'enseignement est fourni, alors l'incription
|
|
concernant uniquement cette ue (collection : inscription_liste_ue)
|
|
|
|
Algorithme :
|
|
1 - Création ou récupération du dossier de l'apprenant
|
|
2 - Inscription de l'apprenant à promotion concernée
|
|
3 - Ajouter les pièce jointes : ajouter 'tab_related_collection' au 'download_files'
|
|
add : related_collection = {'inscription', 'related_collection_id' : isncription_id}
|
|
"""
|
|
def Candidat_Inscrire_To_Session(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'list_candidat_id', 'admission_session_id', 'session_id',
|
|
'type_apprenant' , 'modefinancement',
|
|
'client_rattachement_id', 'tab_ue_ids', 'statut_inscription']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'list_candidat_id', 'admission_session_id', 'session_id',
|
|
'type_apprenant' , 'statut_inscription']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
"""
|
|
S'il y a des ue, verifier la validité des ue
|
|
"""
|
|
my_ue_ids = ""
|
|
tab_ue_ids = []
|
|
if ("tab_ue_ids" in diction.keys()):
|
|
if diction['tab_ue_ids']:
|
|
my_ue_ids = diction['tab_ue_ids']
|
|
tab_ue_ids_work = str(my_ue_ids).split(",")
|
|
|
|
for tmp in tab_ue_ids_work:
|
|
if( tmp ):
|
|
tab_ue_ids.append(tmp)
|
|
|
|
for val in tab_ue_ids :
|
|
is_eu_count = MYSY_GV.dbname['unite_enseignement'].count_documents({'_id':ObjectId(str(val)),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_eu_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'unité d'enseignement "+str(val)+" est invalide ")
|
|
return False, " L'unité d'enseignement "+str(val)+" est invalide "
|
|
|
|
|
|
|
|
if( "statut_inscription" in diction.keys() and diction['statut_inscription'] not in ['', '1', '0']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Le statut d'inscription est invalide ")
|
|
return False, " Le statut d'inscription est invalide "
|
|
|
|
# Verifier que le type d'apprenant est bien valide
|
|
if ( "type_apprenant" in diction.keys() and str(diction['type_apprenant']) ):
|
|
is_valide_type_apprenant = MYSY_GV.dbname['type_apprenant'].count_documents({'_id':ObjectId( str(diction['type_apprenant'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
if( is_valide_type_apprenant != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type d'apprenant est invalide ")
|
|
return False, " Le type d'apprenant est invalide "
|
|
|
|
|
|
# Verifier que le mode de finance est bien valide
|
|
if ("modefinancement" in diction.keys() and str(diction['modefinancement'])):
|
|
is_valide_modefinancementt = MYSY_GV.dbname['financement_mode'].count_documents(
|
|
{'_id': ObjectId(str(diction['modefinancement'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_modefinancementt != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le mode de financement est invalide ")
|
|
return False, " Le mode de financement est invalide "
|
|
|
|
|
|
|
|
|
|
# Verifier la validité du client, s'il ya un client
|
|
client_rattachement_id = ""
|
|
if ("client_rattachement_id" in diction.keys() and diction['client_rattachement_id']):
|
|
is_client_rattachement_id_exist = MYSY_GV.dbname['partner_client'].count_documents(
|
|
{'_id': ObjectId(diction['client_rattachement_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
if (is_client_rattachement_id_exist <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client n'est pas valide ")
|
|
return False, " L'identifiant du client n'est pas valide ",
|
|
|
|
client_rattachement_id = str(diction['client_rattachement_id'])
|
|
|
|
|
|
"""
|
|
Creation ou mise à jour dossier apprenant
|
|
"""
|
|
list_candidat_ids = []
|
|
if ("list_candidat_id" in diction.keys()):
|
|
if diction['list_candidat_id']:
|
|
my_list_candidat_id = diction['list_candidat_id']
|
|
list_candidat_id_work = str(my_list_candidat_id).split(",")
|
|
|
|
for tmp in list_candidat_id_work:
|
|
if (tmp):
|
|
is_valide_candidat_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents({'_id':ObjectId(tmp),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'locked':'0',
|
|
'valide':'1'})
|
|
|
|
if( is_valide_candidat_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant "+str(tmp)+" du candidat est invalide ")
|
|
return False, " L'identifiant "+str(tmp)+" du candidat est invalide "
|
|
|
|
candidat_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(tmp),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'locked': '0',
|
|
'valide': '1'},
|
|
{'email': 1, })
|
|
|
|
|
|
is_candidat_exist_in_apprenant_count = MYSY_GV.dbname['apprenant'].count_documents(
|
|
{'email': candidat_data['email'],
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_candidat_exist_in_apprenant_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Il existe déjà plusieurs apprenants ayant pour adresse email " + str(
|
|
candidat_data['email']))
|
|
return False, " Il existe déjà plusieurs apprenants ayant pour adresse email " + str(
|
|
candidat_data['email'])
|
|
|
|
list_candidat_ids.append(tmp)
|
|
|
|
|
|
|
|
|
|
# Verifier que la session de formation existe et est valide et qu'elle n'est pas completement facturée
|
|
is_session_existe = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'invoiced_statut': {'$ne': '2'},
|
|
})
|
|
|
|
if (is_session_existe <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la promotion / session de formation n'est pas valide ")
|
|
return False, " L'identifiant de la promotion / session de formation n'est pas valide ",
|
|
|
|
|
|
"""
|
|
Creation du dossier apprenant avec un mise à jour
|
|
"""
|
|
list_apprenant_id = []
|
|
|
|
for candidat_id in list_candidat_ids:
|
|
candidat_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(candidat_id),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'locked': '0',
|
|
'valide': '1'}, {'_id':0, 'relances_document':0, 'rang':0, 'update_by':0, 'update_date':0, 'session_etape':0})
|
|
|
|
|
|
is_candidat_exist_in_apprenant_count = MYSY_GV.dbname['apprenant'].count_documents({'email':candidat_data['email'],
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_candidat_exist_in_apprenant_count == 1):
|
|
# On fait une mise à jour du dossier apprenant
|
|
candidat_data['update_date'] = str(datetime.now())
|
|
candidat_data['update_by'] = str(my_partner['_id'])
|
|
|
|
|
|
elif( is_candidat_exist_in_apprenant_count == 0):
|
|
# Il s'agit d'une creation
|
|
candidat_data['creation_date'] = str(datetime.now())
|
|
candidat_data['creation_by'] = str(my_partner['_id'])
|
|
|
|
"""
|
|
Creation du matricule de l'apprenant
|
|
"""
|
|
# Récuperation de la sequence de l'objet "apprenant_matricule" dans la collection : "mysy_sequence"
|
|
retval_sequence_matricule_apprenant = MYSY_GV.dbname['mysy_sequence'].find_one(
|
|
{'related_mysy_object': 'apprenant_matricule',
|
|
'valide': '1', 'partner_owner_recid': str(
|
|
my_partner['recid'])})
|
|
|
|
if (retval_sequence_matricule_apprenant is None):
|
|
# Il n'y pas de sequence pour le partenaire, on va aller chercher la sequence par defaut
|
|
retval_sequence_matricule_apprenant = MYSY_GV.dbname['mysy_sequence'].find_one(
|
|
{'related_mysy_object': 'apprenant_matricule',
|
|
'valide': '1', 'partner_owner_recid': 'default'})
|
|
|
|
apprenant_matricule = ""
|
|
if (
|
|
retval_sequence_matricule_apprenant is None or "current_val" not in retval_sequence_matricule_apprenant.keys()):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible de récupérer la sequence 'apprenant_matricule' pour créer le matricule")
|
|
else:
|
|
current_seq_value = str(retval_sequence_matricule_apprenant['current_val'])
|
|
new_sequence_value = int(mycommon.tryInt(current_seq_value)) + 1
|
|
new_sequance_data_to_update = {'current_val': new_sequence_value}
|
|
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update(
|
|
{'_id': ObjectId(str(retval_sequence_matricule_apprenant['_id'])), 'valide': '1'},
|
|
{"$set": new_sequance_data_to_update},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
apprenant_matricule = retval_sequence_matricule_apprenant['prefixe'] + str(current_seq_value)
|
|
|
|
candidat_data['matricule'] = str(apprenant_matricule)
|
|
|
|
|
|
candidat_data['admission_session_inscrit_id'] = str(candidat_id)
|
|
|
|
result = MYSY_GV.dbname['apprenant'].find_one_and_update(
|
|
{'email': candidat_data['email'],
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": candidat_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if( result and '_id' in result.keys()):
|
|
list_apprenant_id.append(result['_id'])
|
|
|
|
|
|
is_blocking_message = False
|
|
blocking_message = "Erreur : "
|
|
|
|
|
|
for apprenant_id in list_apprenant_id :
|
|
|
|
# Recuperer les données de l'apprenant
|
|
apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id': ObjectId(str(apprenant_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
# Verifier que l'apprenant n'est pas inscrit à cette session
|
|
is_inscrit_session_count = MYSY_GV.dbname['inscription'].count_documents({'session_id':str(diction['session_id']),
|
|
'apprenant_id':str(apprenant_id)})
|
|
|
|
if( is_inscrit_session_count > 0 ):
|
|
is_blocking_message = True
|
|
blocking_message = "\n L'apprenant :" + str(apprenant_data['email']) + " est déjà inscrit à cette session "
|
|
|
|
if( is_blocking_message is True):
|
|
return False, blocking_message
|
|
|
|
is_warning_message = False
|
|
warning_message = "Warning : "
|
|
# field_list = ['token', '_id', 'session_id', 'type_apprenant' , 'modefinancement']
|
|
#print(" ### list_apprenant_id = ", list_apprenant_id)
|
|
|
|
for apprenant_id in list_apprenant_id:
|
|
|
|
# Recuperer les données de l'apprenant
|
|
apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'_id': ObjectId(str(apprenant_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
local_diction = {}
|
|
local_diction['token'] = diction['token']
|
|
local_diction['_id'] = str(apprenant_id)
|
|
local_diction['session_id'] = diction['session_id']
|
|
local_diction['type_apprenant'] = diction['type_apprenant']
|
|
local_diction['modefinancement'] = diction['modefinancement']
|
|
local_diction['client_rattachement_id'] = client_rattachement_id
|
|
if( "tab_ue_ids" in diction.keys() ):
|
|
local_diction['tab_ue_ids'] = str(diction['tab_ue_ids'])
|
|
|
|
if( "statut_inscription" in diction.keys() and diction['statut_inscription'] == "1"):
|
|
local_diction['statut_inscription'] = "1"
|
|
else:
|
|
local_diction['statut_inscription'] = "0"
|
|
|
|
#print(" ### local_diction inscription apprenant = ", local_diction)
|
|
local_status, local_retval, local_inscrit_id = apprenant_mgt.Internal_Apprenant_Inscrire_Session_Ret_id(local_diction)
|
|
|
|
if( local_status is False ):
|
|
is_warning_message = True
|
|
warning_message = "\n Impossible d'inscrire l'apprenant : " + str(apprenant_data['email']) + " "
|
|
|
|
else:
|
|
|
|
for download_files_data in MYSY_GV.dbname['download_files'].find({'object_owner_collection':'admission_session_inscrit_document',
|
|
'object_owner_id':str(apprenant_data['admission_session_inscrit_id'])}):
|
|
new_related_collection = {
|
|
"related_collection": "inscription",
|
|
"related_collection_id": str(local_inscrit_id)
|
|
}
|
|
|
|
qry = {
|
|
"_id": ObjectId(str(download_files_data['_id'])),
|
|
"partner_owner_recid": str(my_partner["recid"]),
|
|
"valide": "1"
|
|
}
|
|
|
|
update = {
|
|
"$addToSet": {
|
|
"tab_related_collection": new_related_collection
|
|
}
|
|
}
|
|
|
|
result = MYSY_GV.dbname['download_files'].update_one(qry, update)
|
|
|
|
"""
|
|
Mettre à jour le candidat pour dire qu'il a été inscrit
|
|
|
|
"""
|
|
for candidat_id in list_candidat_ids:
|
|
candidat_data = MYSY_GV.dbname['admission_session_inscrit'].find_one(
|
|
{'_id': ObjectId(candidat_id),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'locked': '0',
|
|
'valide': '1'}, {'_id':0, 'relances_document':0, 'rang':0, 'update_by':0, 'update_date':0, 'session_etape':0})
|
|
|
|
local_update_data = {}
|
|
local_update_data['inscrit_session_id'] = diction['session_id']
|
|
local_update_data['update_date'] = str(datetime.now())
|
|
local_update_data['update_by'] = str(my_partner['_id'])
|
|
local_update_data['inscrit_session_date'] = str(datetime.now())
|
|
|
|
ret_val2 = MYSY_GV.dbname['admission_session_inscrit'].find_one_and_update(
|
|
{'_id': ObjectId(candidat_id), 'partner_owner_recid': str(my_partner['recid']),},
|
|
{"$set": local_update_data},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if (is_warning_message is True):
|
|
return True, " Les apprenants ont été inscrits avec les erreurs suivantes : \n " + str(warning_message)
|
|
|
|
return True, " Les apprenants ont été correctement inscrits "
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible d'inscrire les apprenants à la session de formation "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'importer en masse des candidat à une session d'admission
|
|
"""
|
|
|
|
def Add_Admission_Candidat_mass_for_One_Session(file=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
|
|
field_list = ['token', 'admission_session_id']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, Creation participants annulée")
|
|
return False, " Verifier votre API"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'admission_session_id']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", my_token)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
|
return False, " Les information de connexion sont incorrectes. Impossible d'importer la liste des participants"
|
|
|
|
"""
|
|
Si le champ 'admission_session_id' est fourni, alors il faut s'assurer que l'import ne se fait exclusivement
|
|
pour la session indiquée
|
|
"""
|
|
admission_session_id = None
|
|
admission_session_id_data = None
|
|
|
|
if ("admission_session_id" in diction.keys() and diction['admission_session_id']):
|
|
admission_session_id = diction['admission_session_id']
|
|
admission_session_id_count = MYSY_GV.dbname['admission_session'].count_documents(
|
|
{'_id': ObjectId(str(admission_session_id)),
|
|
'valide': '1',
|
|
'partner_owner_recid': partner_recid})
|
|
|
|
if (admission_session_id_count != 1):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " L'identifiant de la session d'admission est invalide ")
|
|
return False, " L'identifiant de la session d'admission est invalide"
|
|
|
|
admission_session_id_data = MYSY_GV.dbname['admission_session'].find_one(
|
|
{'_id': ObjectId(str(admission_session_id)),
|
|
'valide': '1',
|
|
'partner_owner_recid': partner_recid})
|
|
|
|
status, saved_file = mycommon.Upload_Save_CSV_File(file, Folder)
|
|
if (status == False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible d'importer la liste des participants, le nom du fichier est incorrect "
|
|
|
|
# " Lecture du fichier "
|
|
# print(" Lecture du fichier : "+saved_file)
|
|
nb_line = 0
|
|
|
|
""""
|
|
update du 11/07/26 : Controle de l'integrité du fichier
|
|
"""
|
|
local_controle_status, local_controle_message = Controle_Add_Admission_Candidat_mass_for_One_Session(saved_file,
|
|
Folder,
|
|
diction)
|
|
|
|
if (local_controle_status is False):
|
|
return local_controle_status, local_controle_message
|
|
|
|
print(" #### local_controle_message = ", local_controle_message)
|
|
|
|
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore',
|
|
skipinitialspace=True)
|
|
df = df.fillna('')
|
|
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les noms des colonne sont bien corrects"
|
|
'''
|
|
field_list = ['prenom', 'nom', 'prenom', 'email', 'telephone', 'modefinancement',
|
|
'employeur', 'status', 'price',
|
|
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
|
|
'type_apprenant', 'civilite', 'date_naissance', 'memo', 'comment',
|
|
"num_secu", "is_rgpd", "situation_famille", "piece_identite_type", "piece_identite_num",
|
|
"type_mobilite", "telephone_bis", "nationalite", "is_handicap", "is_handicap", "is_droit_image",
|
|
'naissance_lieu', 'naissance_departement', 'naissance_pays', 'session_etape_code', 'ine',
|
|
'nom_fille']
|
|
|
|
# Controle du nombre de lignes dans le fichier.
|
|
total_rows = len(df)
|
|
if (total_rows > MYSY_GV.MAX_PARTICIPANT_BY_CSV):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le fichier comporte plus de " + str(
|
|
MYSY_GV.MAX_PARTICIPANT_BY_CSV) + " lignes.")
|
|
return False, " Le fichier comporte plus de " + str(MYSY_GV.MAX_PARTICIPANT_BY_CSV) + " lignes."
|
|
|
|
# print(" ### df.columns = ", df.columns)
|
|
for val in df.columns:
|
|
# print(" ### val = ", val)
|
|
if str(val).lower() not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " : entete du fichier csv. '" + val + "' n'est pas acceptée")
|
|
return False, " Entete du fichier csv. La Colonne '" + val + "' n'est pas acceptée"
|
|
|
|
|
|
# Verification des champs obligatoires dans le fichier
|
|
field_list_obligatoire_file = ['nom', 'prenom', 'email', 'telephone']
|
|
|
|
for val in field_list_obligatoire_file:
|
|
if val not in df.columns:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
|
|
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
|
|
|
|
|
|
|
|
mysession_count_qry = {'_id': ObjectId(str(diction['admission_session_id'])), 'valide': '1',
|
|
'partner_owner_recid': str(partner_recid), }
|
|
|
|
# print(" ### mysession_count_qry = ", mysession_count_qry)
|
|
|
|
mysession_count = MYSY_GV.dbname['admission_session'].count_documents(mysession_count_qry)
|
|
|
|
if (mysession_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La session d'admission est invalide ")
|
|
return False, "La session d'admission est invalide "
|
|
|
|
mysession_data = MYSY_GV.dbname['session_formation'].find_one(mysession_count_qry)
|
|
|
|
x = range(0, total_rows)
|
|
cpt_valide_row = 0
|
|
for n in x:
|
|
if (str(df['prenom'].values[n]) and str(df['nom'].values[n]) and str(df['email'].values[n])):
|
|
mydata = {}
|
|
|
|
mydata['session_id'] = str(diction['admission_session_id'])
|
|
mydata['prenom'] = str(df['prenom'].values[n])
|
|
mydata['nom'] = str(df['nom'].values[n])
|
|
if (len(str(mydata['nom']).strip()) < 2):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'nom' de la ligne " + str(
|
|
n + 2) + " doit faire plus de deux caractères.")
|
|
return False, " Le champ nom de la ligne " + str(
|
|
n + 2) + " doit faire plus de deux caractères. "
|
|
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['email'] = str(df['email'].values[n]).strip().lower()
|
|
# print(" contole du mail = ", mydata['email'])
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(mydata['email']))):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(n + 2) + " : L'adresse email " + str(
|
|
mydata['email']) + " est invalide")
|
|
return False, " Ligne : " + str(n + 2) + " : L'adresse email -" + str(
|
|
mydata['email']) + "- est invalide"
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
"""
|
|
Verifier qu'il n'y pas un étudiant avec le meme INE (Identifiant National Étudiant)
|
|
"""
|
|
local_ine = ""
|
|
if ("ine" in df.keys()):
|
|
local_ine = str(df['ine'].values[n])
|
|
is_exist_ine_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'ine': str(local_ine),
|
|
'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(partner_recid)
|
|
})
|
|
|
|
if (is_exist_ine_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Ligne : " + str(
|
|
n + 2) + " : Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) ")
|
|
return False, " Ligne : " + str(
|
|
n + 2) + " : Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) "
|
|
|
|
mydata['ine'] = str(local_ine)
|
|
|
|
|
|
"""
|
|
Verifier qu'il n'y pas déjà une presonne inscrite avec le meme email pour la meme session
|
|
"""
|
|
local_email = ""
|
|
if ("email" in df.keys()):
|
|
local_email = str(df['email'].values[n]).lower()
|
|
is_inscrit_exist = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{
|
|
"email": {
|
|
"$regex": f"^{re.escape(str(local_email))}$",
|
|
"$options": "i"
|
|
},
|
|
'session_id': diction['admission_session_id'],
|
|
'partner_owner_recid': partner_recid})
|
|
|
|
if (is_inscrit_exist > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Ligne : " + str(
|
|
n + 2) + " : Une personne est déjà inscrite à cette session avec la même adresse email ")
|
|
return False, " Ligne : " + str(
|
|
n + 2) + " : Une personne est déjà inscrite à cette session avec la même adresse email "
|
|
|
|
mydata['email'] = str(local_email)
|
|
|
|
"""
|
|
Verifier la validité de l'etape
|
|
"""
|
|
local_session_etape_id = ""
|
|
if ("session_etape_code" in df.keys()):
|
|
|
|
local_session_etape = str(df['session_etape'].values[n]).lower().strip()
|
|
|
|
session_etape_id = MYSY_GV.dbname['admission_setup_etape'].count_documents(
|
|
{
|
|
"code": {
|
|
"$regex": f"^{re.escape(str(local_session_etape))}$",
|
|
"$options": "i"
|
|
},
|
|
'valide': '1', 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if (session_etape_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne : " + str(
|
|
n + 2) + " : Le code de l'étape est invalide ")
|
|
return False, " Ligne : " + str(n + 2) + " : Le code de l'étape est invalide "
|
|
|
|
session_etape_data = MYSY_GV.dbname['admission_setup_etape'].find_one(
|
|
{
|
|
"code": {
|
|
"$regex": f"^{re.escape(str(local_session_etape))}$",
|
|
"$options": "i"
|
|
},
|
|
'valide': '1', 'partner_owner_recid': str(partner_recid)})
|
|
|
|
local_session_etape_id = str(session_etape_data['_id'])
|
|
mydata['session_etape'] = str(local_session_etape_id)
|
|
|
|
|
|
local_is_handicap = ""
|
|
if ("is_handicap" in df.keys()):
|
|
local_is_handicap = str(df['is_handicap'].values[n]).lower().strip()
|
|
if (local_is_handicap not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + " : Le champ 'is_handicap' est invalide ")
|
|
return False, "Ligne : " + str(n + 2) + " : Le champ 'is_handicap' est invalide "
|
|
|
|
mydata['is_handicap'] = str(local_is_handicap)
|
|
|
|
|
|
local_is_droit_image = ""
|
|
if ("is_droit_image" in df.keys()):
|
|
local_is_droit_image = str(df['is_droit_image'].values[n]).lower().strip()
|
|
if (local_is_droit_image not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + " : Le champ 'is_droit_image' est invalide ")
|
|
return False, "Ligne : " + str(n + 2) + " : Le champ 'is_droit_image' est invalide "
|
|
mydata['is_droit_image'] = str(local_is_droit_image)
|
|
|
|
|
|
local_is_rgpd = ""
|
|
if ("is_rgpd" in df.keys()):
|
|
local_is_rgpd = str(df['is_rgpd'].values[n]).lower().strip()
|
|
if (local_is_rgpd not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + " : Le champ 'is_rgpd' est invalide ")
|
|
return False, "Ligne : " + str(n + 2) + " : Le champ 'is_rgpd' est invalide "
|
|
mydata['is_rgpd'] = str(local_is_rgpd)
|
|
|
|
|
|
local_date_naissance = "01/01/1900"
|
|
if ("date_naissance" in df.keys()):
|
|
local_date_naissance = str(df['date_naissance'].values[n]).strip().split(" ")[0]
|
|
if (local_date_naissance):
|
|
local_status = mycommon.CheckisDate(local_date_naissance)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de naissance à ligne " + str(
|
|
n + 2) + " n'est pas au format 'jj/mm/aaaa' .")
|
|
|
|
return False, " La date de naissance à ligne " + str(
|
|
n + 2) + " n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
mydata['date_naissance'] = str(local_date_naissance)
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in df.keys()):
|
|
if (str(df['adresse'].values[n])):
|
|
adresse = str(df['adresse'].values[n])
|
|
mydata['adresse'] = adresse
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in df.keys()):
|
|
if (str(df['code_postal'].values[n])):
|
|
code_postal = str(df['code_postal'].values[n])
|
|
mydata['code_postal'] = code_postal
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['ville'] = ville
|
|
|
|
pays = ""
|
|
if ("pays" in df.keys()):
|
|
if (str(df['pays'].values[n])):
|
|
pays = str(df['pays'].values[n])
|
|
mydata['pays'] = pays
|
|
|
|
civilite = ""
|
|
if ("civilite" in df.keys()):
|
|
if (str(df['civilite'].values[n])):
|
|
civilite = str(df['civilite'].values[n]).lower()
|
|
mydata['civilite'] = str(civilite).lower()
|
|
|
|
if (str(civilite).strip() == ""):
|
|
mydata['civilite'] = "neutre"
|
|
|
|
if (civilite not in MYSY_GV.CIVILITE):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne : " + str(
|
|
n + 2) + ". La civilité :" + str(
|
|
civilite) + " est invalide. Les valeurs acceptées sont : " + str(MYSY_GV.CIVILITE))
|
|
return False, " Ligne : " + str(
|
|
n + 2) + ". La civilité :" + str(
|
|
civilite) + " est invalide. Les valeurs acceptées sont : " + str(MYSY_GV.CIVILITE)
|
|
|
|
""""
|
|
Gestion du client de rattachement/
|
|
Avec l'email et le nom, on va aller récupérer l'_id du client
|
|
"""
|
|
client_rattachement_email = ""
|
|
if ("client_rattachement_email" in df.keys()):
|
|
if (str(df['client_rattachement_email'].values[n]) and str(
|
|
df['client_rattachement_email'].values[n]) != "nan"):
|
|
client_rattachement_email = str(df['client_rattachement_email'].values[n]).strip()
|
|
|
|
client_rattachement_nom = ""
|
|
if ("client_rattachement_nom" in df.keys()):
|
|
if (str(df['client_rattachement_nom'].values[n]) and str(
|
|
df['client_rattachement_nom'].values[n]) != "nan"):
|
|
client_rattachement_nom = str(df['client_rattachement_nom'].values[n]).strip()
|
|
if (client_rattachement_email and client_rattachement_nom):
|
|
local_client_retval_qry = {'email': str(client_rattachement_email),
|
|
'nom': str(client_rattachement_nom),
|
|
'valide': '1', 'locked': '0', 'partner_owner_recid': str(partner_recid)}
|
|
|
|
print(" ### local_client_retval_qry = ", local_client_retval_qry)
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(
|
|
local_client_retval_qry)
|
|
|
|
if (local_client_retval_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Plusieurs clients correspondent aux critère de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Plusieurs clients correspondent aux critère de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email)
|
|
|
|
if (local_client_retval_count < 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email)
|
|
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(local_client_retval_qry)
|
|
if (local_client_retval_data is not None):
|
|
mydata['client_rattachement_id'] = str(local_client_retval_data['_id'])
|
|
|
|
""""
|
|
Gestion du client dà facturer/
|
|
Avec l'email et le nom, on va aller récupérer l'_id du client
|
|
"""
|
|
facture_client_rattachement_email = ""
|
|
if ("facture_client_rattachement_email" in df.keys()):
|
|
if (str(df['facture_client_rattachement_email'].values[n]) and str(
|
|
df['facture_client_rattachement_email'].values[n]) != "nan"):
|
|
facture_client_rattachement_email = str(
|
|
df['facture_client_rattachement_email'].values[n]).strip()
|
|
|
|
facture_client_rattachement_nom = ""
|
|
if ("facture_client_rattachement_nom" in df.keys()):
|
|
if (str(df['facture_client_rattachement_nom'].values[n]) and str(
|
|
df['facture_client_rattachement_nom'].values[n]) != "nan"):
|
|
facture_client_rattachement_nom = str(df['facture_client_rattachement_nom'].values[n]).strip()
|
|
|
|
if (facture_client_rattachement_email and facture_client_rattachement_nom):
|
|
local_client_retval_qry = {'email': str(facture_client_rattachement_email),
|
|
'nom': str(facture_client_rattachement_nom),
|
|
'valide': '1', 'locked': '0', 'partner_owner_recid': str(partner_recid)}
|
|
|
|
print(" ### local_client_retval_qry = ", local_client_retval_qry)
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(
|
|
local_client_retval_qry)
|
|
|
|
if (local_client_retval_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Plusieurs entités de facturation correspondent aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(
|
|
facture_client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Plusieurs entités de facturation correspondent aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email)
|
|
|
|
if (local_client_retval_count < 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Aucune entité de facturation ne repond aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(
|
|
facture_client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Aucune entité de facturation ne repond aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email)
|
|
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(local_client_retval_qry)
|
|
if (local_client_retval_data is not None):
|
|
mydata['facture_client_rattachement_id'] = str(local_client_retval_data['_id'])
|
|
|
|
mystatus = ""
|
|
if ("status" in df.keys()):
|
|
if (str(df['status'].values[n])):
|
|
mystatus = mycommon.tryInt(str(df['status'].values[n]).strip())
|
|
mydata['status'] = str(mystatus).strip()
|
|
|
|
local_price = ""
|
|
if ("prix" in df.keys()):
|
|
local_price = str(df['prix'].values[n]).strip()
|
|
local_status, new_price = mycommon.IsFloat(local_price)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'prix' de la ligne " + str(
|
|
n + 2) + " est incorrecte.")
|
|
return False, " Le champ prix de la ligne " + str(n + 2) + " est incorrecte. "
|
|
mydata['price'] = local_price
|
|
|
|
|
|
type_apprenant = "0"
|
|
if ("type_apprenant" in df.keys()):
|
|
if (str(df['type_apprenant'].values[n])):
|
|
type_apprenant = str(df['type_apprenant'].values[n]).strip()
|
|
type_apprenant = str(mycommon.tryInt(type_apprenant))
|
|
|
|
if (type_apprenant not in MYSY_GV.INSCRIPTION_TYPE_APPRENANT):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Le type apprenant doit etre l'une des valeurs suivantes :" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Le type apprenant doit etre l'une des valeurs suivantes :" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT)
|
|
|
|
mydata['type_apprenant'] = type_apprenant
|
|
|
|
cpt_valide_row = cpt_valide_row + 1
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if (str(mydata[k]) != "nan")}
|
|
|
|
print( "#### clean_dict ", clean_dict)
|
|
status, retval = Add_Stagiaire_To_Admission_Session(clean_dict)
|
|
if (status is False):
|
|
return status, retval
|
|
|
|
|
|
|
|
print(str(cpt_valide_row) + " candidat ont été insérés")
|
|
|
|
return True, str(cpt_valide_row) + " participants ont été inserés / Mises à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
|
|
|
|
|
|
"""
|
|
Fonction de controle du fichier
|
|
"""
|
|
def Controle_Add_Admission_Candidat_mass_for_One_Session(saved_file=None, Folder=None, diction=None):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token','admission_session_id']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, Creation participants annulée")
|
|
return False, " Verifier votre API"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", my_token)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
|
return False, " Les information de connexion sont incorrectes. Impossible d'importer la liste des participants"
|
|
|
|
|
|
|
|
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore', skipinitialspace=True)
|
|
df = df.fillna('')
|
|
df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x)
|
|
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les noms des colonne sont bien corrects"
|
|
'''
|
|
field_list = [ 'prenom', 'nom', 'prenom', 'email', 'telephone', 'modefinancement',
|
|
'employeur', 'status', 'price',
|
|
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
|
|
'type_apprenant', 'civilite', 'date_naissance', 'memo', 'comment',
|
|
"num_secu", "is_rgpd", "situation_famille", "piece_identite_type", "piece_identite_num",
|
|
"type_mobilite", "telephone_bis", "nationalite", "is_handicap", "is_handicap", "is_droit_image",
|
|
'naissance_lieu', 'naissance_departement', 'naissance_pays', 'session_etape_code', 'ine', 'nom_fille']
|
|
|
|
|
|
# Controle du nombre de lignes dans le fichier.
|
|
total_rows = len(df)
|
|
if( total_rows > MYSY_GV.MAX_PARTICIPANT_BY_CSV ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes.")
|
|
return False, " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes."
|
|
|
|
|
|
#print(" ### df.columns = ", df.columns)
|
|
for val in df.columns:
|
|
#print(" ### val = ", val)
|
|
if str(val).lower() not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3])+" : entete du fichier csv. '" + val + "' n'est pas acceptée")
|
|
return False, " Entete du fichier csv. La Colonne '" + val + "' n'est pas acceptée"
|
|
|
|
|
|
# Verification des champs obligatoires dans le fichier
|
|
field_list_obligatoire_file = ['nom', 'prenom', 'email', 'telephone']
|
|
|
|
for val in field_list_obligatoire_file:
|
|
if val not in df.columns:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
|
|
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
|
|
|
|
|
|
|
|
"""
|
|
# Recuperation des info de la session.
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'formation_session_id':str(session_id)})
|
|
if( session_data is None ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La session de formation n'existe pas : Impossible d'importer la liste des participants ")
|
|
return False, "la session de formation n'existe pas. Impossible d'importer la liste des participants"
|
|
|
|
#print(" #### session_data = ",session_data)
|
|
"""
|
|
|
|
mysession_count_qry = {'_id': ObjectId(str(diction['admission_session_id'])), 'valide': '1',
|
|
'partner_owner_recid': str(partner_recid), }
|
|
|
|
# print(" ### mysession_count_qry = ", mysession_count_qry)
|
|
|
|
mysession_count = MYSY_GV.dbname['admission_session'].count_documents(mysession_count_qry)
|
|
|
|
if (mysession_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La session d'admission est invalide ")
|
|
return False, "La session d'admission est invalide "
|
|
|
|
mysession_data = MYSY_GV.dbname['session_formation'].find_one(mysession_count_qry)
|
|
|
|
|
|
x = range(0, total_rows)
|
|
cpt_valide_row = 0
|
|
for n in x:
|
|
if( str(df['prenom'].values[n]) and str(df['nom'].values[n]) and str(df['email'].values[n]) ) :
|
|
mydata = {}
|
|
#mydata['code_session'] = str(df['code_session'].values[n])
|
|
mydata['prenom'] = str(df['prenom'].values[n])
|
|
mydata['nom'] = str(df['nom'].values[n])
|
|
if (len(str(mydata['nom']).strip()) < 2):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'nom' de la ligne " + str(
|
|
n + 2) + " doit faire plus de deux caractères.")
|
|
return False, " Le champ nom de la ligne " + str(
|
|
n + 2) + " doit faire plus de deux caractères. "
|
|
|
|
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['email'] = str(df['email'].values[n]).strip().lower()
|
|
#print(" contole du mail = ", mydata['email'])
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str( mydata['email']) )):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : "+str(n+2) +" : L'adresse email " + str(mydata['email']) + " est invalide")
|
|
return False, " Ligne : "+str(n+2) +" : L'adresse email -" + str(mydata['email']) + "- est invalide"
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
"""
|
|
Verifier qu'il n'y pas un étudiant avec le meme INE (Identifiant National Étudiant)
|
|
"""
|
|
if ("ine" in df.keys() ):
|
|
local_ine = str(df['ine'].values[n])
|
|
is_exist_ine_count = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{'ine': str(local_ine),
|
|
'session_id': str(diction['admission_session_id']),
|
|
'partner_owner_recid': str(partner_recid)
|
|
})
|
|
|
|
if (is_exist_ine_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Ligne : "+str(n+2) +" : Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) ")
|
|
return False, " Ligne : "+str(n+2) +" : Il y a déjà un candidat avec le même numéro Identifiant National Étudiant (INE) "
|
|
|
|
"""
|
|
Verifier qu'il n'y pas déjà une presonne inscrite avec le meme email pour la meme session
|
|
"""
|
|
if ("email" in df.keys()):
|
|
local_email = str(df['email'].values[n]).lower()
|
|
is_inscrit_exist = MYSY_GV.dbname['admission_session_inscrit'].count_documents(
|
|
{
|
|
"email": {
|
|
"$regex": f"^{re.escape(str(local_email))}$",
|
|
"$options": "i"
|
|
},
|
|
'session_id': diction['admission_session_id'],
|
|
'partner_owner_recid': partner_recid})
|
|
|
|
if (is_inscrit_exist > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Ligne : "+str(n+2) +" : Une personne est déjà inscrite à cette session avec la même adresse email ")
|
|
return False, " Ligne : "+str(n+2) +" : Une personne est déjà inscrite à cette session avec la même adresse email "
|
|
|
|
"""
|
|
Verifier la validité de l'etape
|
|
"""
|
|
if ("session_etape_code" in df.keys()):
|
|
local_session_etape = str(df['session_etape'].values[n]).lower().strip()
|
|
|
|
session_etape_id = MYSY_GV.dbname['admission_setup_etape'].count_documents(
|
|
{
|
|
"code": {
|
|
"$regex": f"^{re.escape(str(local_session_etape))}$",
|
|
"$options": "i"
|
|
},
|
|
'valide': '1', 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if (session_etape_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne : "+str(n+2) +" : Le code de l'étape est invalide ")
|
|
return False, " Ligne : "+str(n+2) +" : Le code de l'étape est invalide "
|
|
|
|
if ("is_handicap" in df.keys() ):
|
|
local_is_handicap = str(df['is_handicap'].values[n]).lower().strip()
|
|
if( local_is_handicap not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : "+str(n+2) +" : Le champ 'is_handicap' est invalide ")
|
|
return False, "Ligne : "+str(n+2) +" : Le champ 'is_handicap' est invalide "
|
|
|
|
if ("is_droit_image" in df.keys() ):
|
|
local_is_droit_image = str(df['is_droit_image'].values[n]).lower().strip()
|
|
if( local_is_droit_image not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : "+str(n+2) +" : Le champ 'is_droit_image' est invalide ")
|
|
return False, "Ligne : "+str(n+2) +" : Le champ 'is_droit_image' est invalide "
|
|
|
|
|
|
if ("is_rgpd" in df.keys() ):
|
|
local_is_rgpd = str(df['is_rgpd'].values[n]).lower().strip()
|
|
if( local_is_rgpd not in ['0', '1', '']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : "+str(n+2) +" : Le champ 'is_rgpd' est invalide ")
|
|
return False, "Ligne : "+str(n+2) +" : Le champ 'is_rgpd' est invalide "
|
|
|
|
|
|
|
|
if ("date_naissance" in df.keys()):
|
|
mydata['date_naissance'] = str(df['date_naissance'].values[n]).strip().split(" ")[0]
|
|
if( mydata['date_naissance'] ) :
|
|
local_status = mycommon.CheckisDate(mydata['date_naissance'])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de naissance à ligne " + str(
|
|
n + 2) + " n'est pas au format 'jj/mm/aaaa' .")
|
|
|
|
return False, " La date de naissance à ligne " + str(n + 2) + " n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in df.keys()):
|
|
if (str(df['adresse'].values[n])):
|
|
adresse = str(df['adresse'].values[n])
|
|
mydata['adresse'] = adresse
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in df.keys()):
|
|
if (str(df['code_postal'].values[n])):
|
|
code_postal = str(df['code_postal'].values[n])
|
|
mydata['code_postal'] = code_postal
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['ville'] = ville
|
|
|
|
pays = ""
|
|
if ("pays" in df.keys()):
|
|
if (str(df['pays'].values[n])):
|
|
pays = str(df['pays'].values[n])
|
|
mydata['pays'] = pays
|
|
|
|
civilite = ""
|
|
if ("civilite" in df.keys()):
|
|
if (str(df['civilite'].values[n])):
|
|
civilite = str(df['civilite'].values[n]).lower()
|
|
mydata['civilite'] = str(civilite).lower()
|
|
|
|
if( str(civilite).strip() == ""):
|
|
mydata['civilite'] = "neutre"
|
|
|
|
if( civilite not in MYSY_GV.CIVILITE):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne : " + str(
|
|
n + 2) + ". La civilité :" + str(
|
|
civilite) + " est invalide. Les valeurs acceptées sont : "+str(MYSY_GV.CIVILITE))
|
|
return False, " Ligne : " + str(
|
|
n + 2) + ". La civilité :" + str(
|
|
civilite) + " est invalide. Les valeurs acceptées sont : "+str(MYSY_GV.CIVILITE)
|
|
|
|
""""
|
|
Gestion du client de rattachement/
|
|
Avec l'email et le nom, on va aller récupérer l'_id du client
|
|
"""
|
|
client_rattachement_email = ""
|
|
if ("client_rattachement_email" in df.keys()):
|
|
if (str(df['client_rattachement_email'].values[n]) and str(df['client_rattachement_email'].values[n]) != "nan"):
|
|
client_rattachement_email = str(df['client_rattachement_email'].values[n]).strip()
|
|
|
|
|
|
client_rattachement_nom = ""
|
|
if ("client_rattachement_nom" in df.keys()):
|
|
if (str(df['client_rattachement_nom'].values[n]) and str(df['client_rattachement_nom'].values[n]) != "nan" ):
|
|
client_rattachement_nom = str(df['client_rattachement_nom'].values[n]).strip()
|
|
if (client_rattachement_email and client_rattachement_nom):
|
|
local_client_retval_qry = {'email':str(client_rattachement_email), 'nom':str(client_rattachement_nom),
|
|
'valide':'1', 'locked':'0', 'partner_owner_recid' :str(partner_recid)}
|
|
|
|
print(" ### local_client_retval_qry = ", local_client_retval_qry)
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(local_client_retval_qry)
|
|
|
|
if( local_client_retval_count > 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) +"Ligne : "+str(n+2) +". Plusieurs clients correspondent aux critère de nom :"+str(client_rattachement_nom)+" et email : "+str(client_rattachement_email))
|
|
return False, "Ligne : "+str(n+2) +". Plusieurs clients correspondent aux critère de nom :"+str(client_rattachement_nom)+" et email : "+str(client_rattachement_email)
|
|
|
|
if (local_client_retval_count < 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : "+str(n+2) +". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : "+str(n+2) +". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email)
|
|
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(local_client_retval_qry)
|
|
if( local_client_retval_data is not None ):
|
|
mydata['client_rattachement_id'] = str(local_client_retval_data['_id'])
|
|
|
|
""""
|
|
Gestion du client dà facturer/
|
|
Avec l'email et le nom, on va aller récupérer l'_id du client
|
|
"""
|
|
facture_client_rattachement_email = ""
|
|
if ("facture_client_rattachement_email" in df.keys()):
|
|
if (str(df['facture_client_rattachement_email'].values[n]) and str(
|
|
df['facture_client_rattachement_email'].values[n]) != "nan"):
|
|
facture_client_rattachement_email = str(df['facture_client_rattachement_email'].values[n]).strip()
|
|
|
|
facture_client_rattachement_nom = ""
|
|
if ("facture_client_rattachement_nom" in df.keys()):
|
|
if (str(df['facture_client_rattachement_nom'].values[n]) and str(
|
|
df['facture_client_rattachement_nom'].values[n]) != "nan"):
|
|
facture_client_rattachement_nom = str(df['facture_client_rattachement_nom'].values[n]).strip()
|
|
|
|
if (facture_client_rattachement_email and facture_client_rattachement_nom):
|
|
local_client_retval_qry = {'email': str(facture_client_rattachement_email),
|
|
'nom': str(facture_client_rattachement_nom),
|
|
'valide': '1', 'locked': '0', 'partner_owner_recid': str(partner_recid)}
|
|
|
|
print(" ### local_client_retval_qry = ", local_client_retval_qry)
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(local_client_retval_qry)
|
|
|
|
if (local_client_retval_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Plusieurs entités de facturation correspondent aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Plusieurs entités de facturation correspondent aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email)
|
|
|
|
if (local_client_retval_count < 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Aucune entité de facturation ne repond aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Aucune entité de facturation ne repond aux critères de nom :" + str(
|
|
facture_client_rattachement_nom) + " et email : " + str(facture_client_rattachement_email)
|
|
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(local_client_retval_qry)
|
|
if (local_client_retval_data is not None):
|
|
mydata['facture_client_rattachement_id'] = str(local_client_retval_data['_id'])
|
|
|
|
mystatus = ""
|
|
if ("status" in df.keys()):
|
|
if (str(df['status'].values[n])):
|
|
mystatus = mycommon.tryInt(str(df['status'].values[n]).strip())
|
|
mydata['status'] = str(mystatus).strip()
|
|
|
|
|
|
local_price = ""
|
|
if ("prix" in df.keys()):
|
|
local_price = str(df['prix'].values[n]).strip()
|
|
local_status, new_price = mycommon.IsFloat(local_price)
|
|
if( local_status is False ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][ 3]) + " Le champ 'prix' de la ligne " + str( n+2) + " est incorrecte.")
|
|
return False, " Le champ prix de la ligne " + str(n+2) + " est incorrecte. "
|
|
mydata['price'] = local_price
|
|
|
|
type_apprenant = "0"
|
|
if ("type_apprenant" in df.keys()):
|
|
if (str(df['type_apprenant'].values[n])):
|
|
type_apprenant = str(df['type_apprenant'].values[n]).strip()
|
|
type_apprenant = str(mycommon.tryInt(type_apprenant))
|
|
|
|
print(" ### type_apprenant === ", type_apprenant)
|
|
if (type_apprenant not in MYSY_GV.INSCRIPTION_TYPE_APPRENANT):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ". Le type apprenant doit etre l'une des valeurs suivantes :" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT))
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ". Le type apprenant doit etre l'une des valeurs suivantes :" + str(
|
|
MYSY_GV.INSCRIPTION_TYPE_APPRENANT)
|
|
|
|
mydata['type_apprenant'] = type_apprenant
|
|
|
|
cpt_valide_row = cpt_valide_row + 1
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
#print( "#### clean_dict ", clean_dict)
|
|
|
|
|
|
return True, str(cpt_valide_row)+" candidats dans le fichier"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de controler le fichier des candidat a importer en masse "
|