08/12/2023 - 22h30

master
cherif 2023-12-08 23:04:02 +01:00
parent fadc95f768
commit 9bdf6a03a6
7 changed files with 3450 additions and 26 deletions

View File

@ -1,16 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="07/12/2023 - 11h30">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="07/12/2023 - 21h30">
<change afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Collection_Historique.py" beforeDir="false" afterPath="$PROJECT_DIR$/Collection_Historique.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Dashbord_queries/session_tbd_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/session_tbd_qries.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/agenda.py" beforeDir="false" afterPath="$PROJECT_DIR$/agenda.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/partner_document_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_document_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
@ -81,13 +78,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00116" summary="30/09/2023 - 14h">
<created>1696076203877</created>
<option name="number" value="00116" />
<option name="presentableId" value="LOCAL-00116" />
<option name="project" value="LOCAL" />
<updated>1696076203877</updated>
</task>
<task id="LOCAL-00117" summary="30/09/2023 - 18h">
<created>1696091230108</created>
<option name="number" value="00117" />
@ -424,7 +414,14 @@
<option name="project" value="LOCAL" />
<updated>1701945586589</updated>
</task>
<option name="localTasksCounter" value="165" />
<task id="LOCAL-00165" summary="07/12/2023 - 21h30">
<created>1701980089273</created>
<option name="number" value="00165" />
<option name="presentableId" value="LOCAL-00165" />
<option name="project" value="LOCAL" />
<updated>1701980089274</updated>
</task>
<option name="localTasksCounter" value="166" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -439,7 +436,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="08/11/2023 - 23h" />
<MESSAGE value="09/11/2023 - 23h" />
<MESSAGE value="sdds" />
<MESSAGE value="11/11/2023 - 17h" />
@ -464,6 +460,7 @@
<MESSAGE value="05/12/2023 - 21h" />
<MESSAGE value="06/12/2023 - 21h" />
<MESSAGE value="07/12/2023 - 11h30" />
<option name="LAST_COMMIT_MESSAGE" value="07/12/2023 - 11h30" />
<MESSAGE value="07/12/2023 - 21h30" />
<option name="LAST_COMMIT_MESSAGE" value="07/12/2023 - 21h30" />
</component>
</project>

View File

@ -6227,6 +6227,14 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
'status':'1',
'partner_owner_recid':str(my_partner['recid'])})
# Recuperation des données du partenaire associé à l'utilisateur connecté
local_status, local_retval = mycommon.Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
if( local_status is False):
return local_status, local_retval
company_data = local_retval
# Recupération des données du modèle de document
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
{'_id': ObjectId(str(diction['courrier_template_id'])),
@ -6271,6 +6279,21 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
#Recuperations des info de la session de formation
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(inscription_data['session_id'])),'valide': '1',
'partner_owner_recid':str(my_partner['recid'])})
formateur_nom_prenom = ""
# Si il y a un code formateur_id, alors on va recuperer les nom et prenom du formation
if ("formateur_id" in session_data.keys() and session_data['formateur_id']):
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id': ObjectId(str(session_data['formateur_id'])),
'valide': '1',
'locked': '0',
'partner_recid': str(my_partner['recid'])
})
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
formateur_nom_prenom = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
session_data['formateur_nom_prenom'] = formateur_nom_prenom
# Recuperation du titre de la formation
@ -6281,6 +6304,8 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
# Creation du dictionnaire d'information à utiliser pour la creation du doc
convention_dictionnary_data = {}
@ -6293,7 +6318,7 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
'tuteur1_pays', 'tuteur1_telephone', 'tuteur1_ville', 'tuteur1_prenom',
'tuteur2_adresse', 'tuteur2_cp', 'tuteur2_email', 'tuteur2_nom', 'tuteur2_pays',
'tuteur2_prenom',
'tuteur2_telephone', 'tuteur2_ville']
'tuteur2_telephone', 'tuteur2_ville', 'adresse', 'code_postal', 'ville', 'pays']
for champ in stagiaire_liste_champ:
if( champ in inscription_data ):
@ -6309,7 +6334,9 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
Recuperartion des champs de la session
"""
session_liste_champ = ['code_session', 'class_internal_url', 'date_debut', 'session_etape', 'date_fin', 'distantiel', 'presentiel', 'session_ondemande', 'nb_participant',
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse', 'code_postal', 'ville', 'pays', 'date_debut_inscription', 'date_fin_inscription']
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse', 'code_postal', 'ville', 'pays', 'date_debut_inscription',
'date_fin_inscription', 'formateur_nom_prenom'
]
for champ in session_liste_champ:
if (champ in session_data):
@ -6324,7 +6351,7 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
"""
Recuperartion des champs de la formation
"""
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title']
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title', 'duration', 'duration_unit']
for champ in myclass_liste_champ:
if (champ in class_data):
@ -6337,6 +6364,42 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
convention_dictionnary_data.update(new_field)
"""
Recuperartion des champs de la personne connecté
"""
connected_user_liste_champ = ['email', 'contact_nom', 'contact_prenom']
for champ in connected_user_liste_champ:
if (champ in my_partner):
new_champ_name = "utilisateur_" + str(champ)
new_field = {new_champ_name: str(my_partner[champ])}
convention_dictionnary_data.update(new_field)
else:
new_champ_name = "utilisateur_" + str(champ)
new_field = {new_champ_name: ""}
convention_dictionnary_data.update(new_field)
"""
Recuperartion des champs de la société
"""
company_liste_champ = ['nom', 'email', 'num_nda', 'website', 'adr_street', 'adr_zip', 'adr_city', 'adr_country']
for champ in company_liste_champ:
if (champ in company_data):
new_champ_name = "societe_" + str(champ)
new_field = {new_champ_name: str(company_data[champ])}
convention_dictionnary_data.update(new_field)
else:
new_champ_name = "societe_" + str(champ)
new_field = {new_champ_name: ""}
convention_dictionnary_data.update(new_field)
# Ajout des champs système comme la date du jour
ct = datetime.now()
ts = ct.timestamp()
date_jour = ct.strftime("%d/%m/%Y")
new_field = {"date_jour": str(date_jour)}
convention_dictionnary_data.update(new_field)
## Creation du PDF
body = {
@ -6636,6 +6699,13 @@ def Download_Convention_Stagiaire_PDF(diction):
'status': '1',
'partner_owner_recid': str(my_partner['recid'])})
# Recuperation des données du partenaire associé à l'utilisateur connecté
local_status, local_retval = mycommon.Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
if (local_status is False):
return local_status, local_retval
company_data = local_retval
# Recupération des données du modèle de document
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
{'_id': ObjectId(str(diction['courrier_template_id'])),
@ -6649,6 +6719,28 @@ def Download_Convention_Stagiaire_PDF(diction):
{'_id': ObjectId(str(inscription_data['session_id'])), 'valide': '1',
'partner_owner_recid': str(my_partner['recid'])})
formateur_nom_prenom = ""
# Si il y a un code formateur_id, alors on va recuperer les nom et prenom du formation
if ("formateur_id" in session_data.keys() and session_data['formateur_id']):
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one(
{'_id': ObjectId(str(session_data['formateur_id'])),
'valide': '1',
'locked': '0',
'partner_recid': str(my_partner['recid'])
})
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
formateur_nom_prenom = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
session_data['formateur_nom_prenom'] = formateur_nom_prenom
# Recupérer la liste des participant pour une eventuelle à afficher pour les conventions d'entreprise
list_participants_session = MYSY_GV.dbname['inscription'].find({'session_id':str(session_data['_id']), 'status':'1',
'partner_owner_recid':str(my_partner['recid'])},
{'email':1, 'nom':1, 'prenom':1}).sort([("nom", pymongo.DESCENDING)])
# Recuperation du titre de la formation
class_data = MYSY_GV.dbname['myclass'].find_one(
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
@ -6665,7 +6757,7 @@ def Download_Convention_Stagiaire_PDF(diction):
'tuteur1_pays', 'tuteur1_telephone', 'tuteur1_ville', 'tuteur1_prenom',
'tuteur2_adresse', 'tuteur2_cp', 'tuteur2_email', 'tuteur2_nom', 'tuteur2_pays',
'tuteur2_prenom',
'tuteur2_telephone', 'tuteur2_ville']
'tuteur2_telephone', 'tuteur2_ville','adresse', 'code_postal', 'ville', 'pays']
for champ in stagiaire_liste_champ:
if (champ in inscription_data):
@ -6683,7 +6775,8 @@ def Download_Convention_Stagiaire_PDF(diction):
session_liste_champ = ['code_session', 'class_internal_url', 'date_debut', 'session_etape', 'date_fin',
'distantiel', 'presentiel', 'session_ondemande', 'nb_participant',
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse',
'code_postal', 'ville', 'pays', 'date_debut_inscription', 'date_fin_inscription']
'code_postal', 'ville', 'pays', 'date_debut_inscription', 'date_fin_inscription',
'formateur_nom_prenom']
for champ in session_liste_champ:
if (champ in session_data):
@ -6698,7 +6791,7 @@ def Download_Convention_Stagiaire_PDF(diction):
"""
Recuperartion des champs de la formation
"""
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title']
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title', 'duration', 'duration_unit']
for champ in myclass_liste_champ:
if (champ in class_data):
@ -6710,6 +6803,50 @@ def Download_Convention_Stagiaire_PDF(diction):
new_field = {new_champ_name: ""}
convention_dictionnary_data.update(new_field)
"""
Recuperartion des champs de la personne connecté
"""
connected_user_liste_champ = ['email', 'contact_nom', 'contact_prenom']
for champ in connected_user_liste_champ:
if (champ in my_partner):
new_champ_name = "utilisateur_" + str(champ)
new_field = {new_champ_name: str(my_partner[champ])}
convention_dictionnary_data.update(new_field)
else:
new_champ_name = "utilisateur_" + str(champ)
new_field = {new_champ_name: ""}
convention_dictionnary_data.update(new_field)
"""
Recuperartion des champs de la société
"""
company_liste_champ = ['nom', 'email', 'num_nda', 'website', 'adr_street', 'adr_zip', 'adr_city', 'adr_country']
for champ in company_liste_champ:
if (champ in company_data):
new_champ_name = "societe_" + str(champ)
new_field = {new_champ_name: str(company_data[champ])}
convention_dictionnary_data.update(new_field)
else:
new_champ_name = "societe_" + str(champ)
new_field = {new_champ_name: ""}
convention_dictionnary_data.update(new_field)
# Ajout des champs système comme la date du jour
ct = datetime.now()
ts = ct.timestamp()
date_jour = ct.strftime("%d/%m/%Y")
new_field = {"date_jour": str(date_jour)}
convention_dictionnary_data.update(new_field)
node_list_part = []
for val in list_participants_session:
print(" #### val = ", val)
del val['_id']
node_list_part.append(val)
convention_dictionnary_data['list_participants'] = node_list_part
print(" ### convention_dictionnary_data = ", convention_dictionnary_data)
body = {

File diff suppressed because one or more lines are too long

View File

@ -172,8 +172,6 @@ def Add_Update_Agenda_Event(diction):
return True, " L'événement a été ajouté"
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))

527
apprenant_mgt.py Normal file
View File

@ -0,0 +1,527 @@
"""
Ce fichier permet de gerer les apprenants.
Un apprenant est crée apres la validation d'une inscription ou sans.
"""
import pymongo
from pymongo import MongoClient
import json
from bson import ObjectId
import re
from datetime import datetime
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
"""
Ajout d'un apprenant.
La clé est l'adresse email
"""
- log historique dans les fonction
def Add_Apprenant(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'email', 'nom', 'prenom', 'telephone', 'opco', 'employeur', 'comment',
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
'tuteur1_nom', 'tuteur1_prenom', 'tuteur1_email', 'tuteur1_telephone', 'tuteur1_adresse',
'tuteur1_cp', 'tuteur1_ville', 'tuteur1_pays', 'tuteur1_include_com',
'tuteur2_nom', 'tuteur2_prenom', 'tuteur2_email', 'tuteur2_telephone', 'tuteur2_adresse',
'tuteur2_cp', 'tuteur2_ville', 'tuteur2_pays', 'tuteur2_include_com',
]
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','email', 'nom', 'prenom' ]
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 liste ")
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 que l'adresse email est valide
if( "email" in diction.keys() and diction['email']):
if( mycommon.isEmailValide(str(diction['email'])) is False ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '"+str(diction['email'])+"' n'est pas valide")
return False, " L'adresse email '"+str(diction['email'])+"' n'est pas valide ",
# Verifier l'adresse email du tuteur 1
if ("tuteur1_email" in diction.keys() and diction['tuteur1_email']):
if (mycommon.isEmailValide(str(diction['tuteur1_email'])) is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '" + str(diction['tuteur1_email']) + "' n'est pas valide")
return False, " L'adresse email '" + str(diction['tuteur1_email']) + "' n'est pas valide ",
# Verifier l'adresse email du tuteur 2
if ("tuteur2_email" in diction.keys() and diction['tuteur2_email']):
if (mycommon.isEmailValide(str(diction['tuteur2_email'])) is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '" + str(
diction['tuteur2_email']) + "' n'est pas valide")
return False, " L'adresse email '" + str(diction['tuteur2_email']) + "' n'est pas valide ",
# Verifier que le client_rattachement_id est valide
if ("client_rattachement_id" in diction.keys() and diction['client_rattachement_id']):
is_client_rattachement_id_valide = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(diction['client_rattachement_id'])),
'valide':'1',
'locked':'0',
'partner_recid':str(my_partner['recid'])})
if( is_client_rattachement_id_valide <= 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 ",
# Verifier si un apprenant n'a pas deja ce meme email
is_apprenant_exist = MYSY_GV.dbname['apprenant'].count_documents({'email':str(diction['email']),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1'})
if( is_apprenant_exist > 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " Il existe déjà un apprenant avec la même adresse email. ")
return False, " Il existe déjà un apprenant avec la même adresse email. ",
new_data = diction
del new_data['token']
new_data['valide'] = '1'
new_data['locked'] = '0'
new_data['date_update'] = str(datetime.now())
new_data['update_by'] = str(my_partner['_id'])
inserted_id = MYSY_GV.dbname['apprenant'].insert_one(new_data).inserted_id
if (not inserted_id):
mycommon.myprint(
" Impossible de créer l'apprenant (1) ")
return False, " Impossible de créer l'apprenant (1) "
return True, "L'apprenant 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) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de créer l'apprenant "
"""
Mise à jour d'un apprenant.
La clé : _id
"""
def Update_Apprenant(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', 'email', 'nom', 'prenom', 'telephone', 'opco', 'employeur', 'comment',
'client_rattachement_id', 'adresse', 'code_postal', 'ville', 'pays',
'tuteur1_nom', 'tuteur1_prenom', 'tuteur1_email', 'tuteur1_telephone', 'tuteur1_adresse',
'tuteur1_cp', 'tuteur1_ville', 'tuteur1_pays', 'tuteur1_include_com',
'tuteur2_nom', 'tuteur2_prenom', 'tuteur2_email', 'tuteur2_telephone', 'tuteur2_adresse',
'tuteur2_cp', 'tuteur2_ville', 'tuteur2_pays', 'tuteur2_include_com',
]
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 liste ")
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 que l'apprenant existe deja
is_apprenant_exist = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_apprenant_exist <= 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant n'est pas valide ")
return False, " L'identifiant de l'apprenant n'est pas valide ",
# Verifier que l'adresse email est valide
if ("email" in diction.keys() and diction['email']):
if (mycommon.isEmailValide(str(diction['email'])) is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '" + str(diction['email']) + "' n'est pas valide")
return False, " L'adresse email '" + str(diction['email']) + "' n'est pas valide ",
# Verifier l'adresse email du tuteur 1
if ("tuteur1_email" in diction.keys() and diction['tuteur1_email']):
if (mycommon.isEmailValide(str(diction['tuteur1_email'])) is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '" + str(
diction['tuteur1_email']) + "' n'est pas valide")
return False, " L'adresse email '" + str(diction['tuteur1_email']) + "' n'est pas valide ",
# Verifier l'adresse email du tuteur 2
if ("tuteur2_email" in diction.keys() and diction['tuteur2_email']):
if (mycommon.isEmailValide(str(diction['tuteur2_email'])) is False):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'adresse email '" + str(
diction['tuteur2_email']) + "' n'est pas valide")
return False, " L'adresse email '" + str(diction['tuteur2_email']) + "' n'est pas valide ",
# Verifier que le client_rattachement_id est valide
if ("client_rattachement_id" in diction.keys() and diction['client_rattachement_id']):
is_client_rattachement_id_valide = MYSY_GV.dbname['partner_client'].count_documents(
{'_id': ObjectId(str(diction['client_rattachement_id'])),
'valide': '1',
'locked': '0',
'partner_recid': str(my_partner['recid'])})
if (is_client_rattachement_id_valide <= 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 ",
apprenant_id = str(diction['_id'])
new_data = diction
del new_data['token']
del new_data['_id']
new_data['valide'] = '1'
new_data['locked'] = '0'
new_data['date_update'] = str(datetime.now())
new_data['update_by'] = str(my_partner['_id'])
ret_val = MYSY_GV.dbname['apprenant'].find_one_and_update(
{'_id': ObjectId(str(apprenant_id)),
'partner_owner_recid':str(my_partner['recid'])},
{"$set": new_data},
upsert=False,
return_document=ReturnDocument.AFTER
)
if ret_val is None or ret_val['_id'] is None:
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de mettre à jour l'apprenant (1) ")
return False, " Impossible de mettre à jour l'apprenant (1) "
return True, "L'apprenant 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 l'apprenant "
"""
Recuperer les données detaillée d'un apprenant
"""
def Get_Given_Apprenant_Data(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 liste ")
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 que l'apprenant existe deja
is_apprenant_exist = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_apprenant_exist <= 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant n'est pas valide ")
return False, " L'identifiant de l'apprenant n'est pas valide ",
RetObject = []
val_tmp = 1
for val in MYSY_GV.dbname['apprenant'].find_one({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'}):
user = val
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
# Recuperer les données du client
if( "client_rattachement_id" in val.keys() and val['client_rattachement_id'] ):
client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(val['client_rattachement_id'])),
'valide':'1',
'locked':'0'})
user['client_nom'] = client_data['nom']
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'apprenant "
"""
Récuperer la liste des apprenants d'un partenaire
"""
def Get_List_Partner_Apprenant(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 liste ")
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
RetObject = []
val_tmp = 1
for val in MYSY_GV.dbname['apprenant'].find_one({'partner_owner_recid': str(my_partner['recid']),
'valide': '1',
'locked': '0'}):
user = val
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
# Recuperer les données du client
if ("client_rattachement_id" in val.keys() and val['client_rattachement_id']):
client_data = MYSY_GV.dbname['partner_client'].find_one(
{'_id': ObjectId(str(val['client_rattachement_id'])),
'valide': '1',
'locked': '0'})
user['client_nom'] = client_data['nom']
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 apprenants "
"""
Inscrire un apprenant à un session de formation
"""
def Apprenant_Inscrire_Session(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', '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', '_id', '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 liste ")
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 que l'apprenant existe
is_apprenant_exist = MYSY_GV.dbname['apprenant'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_apprenant_exist <= 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant n'est pas valide ")
return False, " L'identifiant de l'apprenant n'est pas valide ",
# Recuperer les données de l'apprenant
apprenant_data = MYSY_GV.dbname['apprenant'].count_documents({'_id': ObjectId(str(diction['_id'])),
'partner_owner_recid': str(my_partner['recid']),
'valide': '1',
'locked': '0'})
# Verifier que la session de formation existe et est valide
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',
})
if (is_apprenant_exist <= 0):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de la session de formation n'est pas valide ")
return False, " L'identifiant de la session de formation n'est pas valide ",
# Recuperer les données de la session
session_data = MYSY_GV.dbname['session_formation'].find_one(
{'_id': ObjectId(str(diction['session_id'])),
'partner_owner_recid': str(my_partner['recid']),
'valide': '1',
})
new_data = {}
new_data['email'] = apprenant_data['email']
new_data['apprenant_id'] = str(apprenant_data['_id'])
new_data['session_id'] = str(session_data['_id'])
new_data['class_internal_url'] = session_data['class_internal_url']
new_data['status'] = "1"
new_data['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
new_data['date_update'] = str(datetime.now())
new_data['update_by'] = str(my_partner['_id'])
new_data['partner_owner_recid'] = str(my_partner['recid'])
# Reste à faire :
- ajout dans la collection 'inscription'
- log historique
- envoie email inscription
return True
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 l'apprenant à la session de formation "

View File

@ -1106,7 +1106,7 @@ def Get_Given_Personnalisable_Fields_By_courrier_template_id(diction):
val_tmp = 1
#print(" ### data_cle = ", data_cle)
for retval in MYSY_GV.dbname['courrier_template_champ_config'].find(data_cle):
for retval in MYSY_GV.dbname['courrier_template_champ_config'].find(data_cle).sort([("nom_champ_fonctionel", pymongo.ASCENDING)]):
user = retval
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1

View File

@ -3622,7 +3622,8 @@ def Check_Connexion_And_Return_Partner_Data(diction):
"""
/!\ Update du 26/11/2023 :
On a plutot besoin de recuperer les données du user connecté au lieu du partenaire
On a plutot besoin de recuperer les données du user connecté au lieu du partenaire,
"""
local_status, my_connected_user = get_connected_data_from_token(token)
if (local_status is False):
@ -3636,6 +3637,23 @@ def Check_Connexion_And_Return_Partner_Data(diction):
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de verifier la connexion"
"""
Cette fonction retourne les données du partenair rattaché au user connecté
"""
def Get_Connected_User_Partner_Data_From_RecID(user_recid):
try:
mydata = MYSY_GV.dbname['partnair_account'].find_one({'recid':str(user_recid), 'is_partner_admin_account':'1', 'active':'1', 'locked':'0'})
if( mydata is None):
return False, " Aucun compte partenaire actif pour cet utilisateur"
return True,mydata
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de récupérer les données du partenaire"
"""