14480 lines
645 KiB
Python
14480 lines
645 KiB
Python
"""
|
|
Ce fichier permets de créer les inscription des stagiaires à une formation
|
|
"""
|
|
import base64
|
|
import smtplib
|
|
|
|
import segno
|
|
import xlsxwriter
|
|
from email import encoders
|
|
from email.mime.base import MIMEBase
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
import ast
|
|
import pymongo
|
|
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 module_editique
|
|
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
|
|
from datetime import timedelta
|
|
import email_inscription_mgt as email_session
|
|
from flask import send_file
|
|
import re
|
|
from xhtml2pdf import pisa
|
|
import jinja2
|
|
import ftplib
|
|
import pysftp
|
|
import email_mgt as email_mgt
|
|
import lms_chamilo.mysy_lms as mys_lms
|
|
from email.message import EmailMessage
|
|
import attached_file_mgt as attached_file_mgt
|
|
from zipfile import ZipFile
|
|
import partner_client as partner_client
|
|
import E_Sign_Document as E_Sign_Document
|
|
"""
|
|
Enregistrement d'un stagiaire
|
|
|
|
Voici les valeurs possibles du statut d'un stagiaire
|
|
# 0 ==> Preinscription
|
|
# 1 ==> Inscription validée
|
|
# 2 ==> Encours d'inscription. Ce statut est surtout utilisé quand on fait de inscription depuis le backoffice par un gestionnaire de formation.
|
|
# -1 ==> Inscription annulée
|
|
|
|
/!\ : Cette foncton est utilisé aussi bien en mode non-connecté qu'en mode connecté
|
|
il ne faut donc controler le token que s'il est fourni avec une valeur donnée
|
|
Si il n'est pas fourni, on prend le 'partner_owner_recid' de la formation
|
|
|
|
/!\ 2 : le 'partner_owner_recid' doit etre celui de la session de formation, EN AUCUN CAS CELUI DE LA PERSONNE CONNECTEE
|
|
|
|
"""
|
|
def AddStagiairetoClass(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 = ['nom', 'prenom', 'email', 'telephone', 'modefinancement', 'opco',
|
|
'class_internal_url', 'session_id', 'employeur', 'status', 'price',
|
|
'inscription_validation_date', 'token', 'client_rattachement_id',
|
|
'adresse', 'code_postal', 'ville', 'pays', 'type_apprenant', 'apprenant_id', 'civilite',
|
|
'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','date_naissance',
|
|
'financeur_rattachement_id', 'tuteur1_civilite', 'tuteur2_civilite', 'quotation_id',
|
|
'facture_client_rattachement_id', 'tab_ue_ids'
|
|
]
|
|
|
|
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, "Impossible de créer le stagiaire. Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['nom', 'prenom', 'email', 'telephone', 'modefinancement',
|
|
'class_internal_url', '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, "Impossible de créer le stagiaire. La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_partner = None
|
|
connected_user_id = "None"
|
|
if( "token" in diction.keys() and 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
|
|
|
|
connected_user_id = my_partner['recid']
|
|
|
|
|
|
#print(" #### my_partner = ", my_partner)
|
|
|
|
"""
|
|
Verifier que la formation est valide
|
|
"""
|
|
is_myclass_valide_count = MYSY_GV.dbname['myclass'].count_documents({'internal_url':str(diction['class_internal_url']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
})
|
|
|
|
|
|
if( is_myclass_valide_count <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la formation est invalide ")
|
|
return False, " L'identifiant de la formation est invalide "
|
|
|
|
if (is_myclass_valide_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + str(is_myclass_valide_count)+" formations ont le même internal_url. Or un 'internal_url' correspond à une et une seule formation. internal_url est "+str(diction['class_internal_url']))
|
|
return False, str(is_myclass_valide_count)+" formations ont le même internal_url."
|
|
|
|
is_myclass_valide_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(diction['class_internal_url']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
})
|
|
|
|
|
|
|
|
"""
|
|
/!\ : 01/08/2024
|
|
Si 'my_partner' est NONE, on va recuperer les données coorespondant au compte admin du partnenaire .
|
|
On ajoute aussi le token au dictionnaire
|
|
"""
|
|
if(my_partner is None ):
|
|
local_status, my_partner = mycommon.Get_Connected_User_Partner_Data_From_RecID(
|
|
str(is_myclass_valide_data['partner_owner_recid']))
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
diction['token'] = my_partner['token']
|
|
|
|
#print(" #### my_partner V2 = ", my_partner)
|
|
|
|
mydata = {}
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
mydata[str(val)] = ""
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
mydata[str(val)] = ""
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = str(diction['session_id']).strip()
|
|
mydata['session_id'] = session_id
|
|
|
|
|
|
"""
|
|
Verififier l'existance et la valididé de la session
|
|
"""
|
|
my_session_data_qry = {"_id":ObjectId(str(session_id)), 'valide':'1' }
|
|
#print(" AddStagiairetoClass my_session_data_qry = ", my_session_data_qry)
|
|
|
|
my_session_data = MYSY_GV.dbname['session_formation'].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 session_id = "+ str(session_id))
|
|
return False, " L'identifiant de la session est invalide"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = str(diction['token']).strip()
|
|
|
|
apprenant_id = ""
|
|
if ("apprenant_id" in diction.keys()):
|
|
if diction['apprenant_id']:
|
|
apprenant_id = str(diction['apprenant_id']).strip()
|
|
mydata['apprenant_id'] = str(apprenant_id)
|
|
|
|
date_naissance = ""
|
|
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' "
|
|
|
|
mydata['date_naissance'] = str(date_naissance)
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des info de la session de formation
|
|
"""
|
|
|
|
"""
|
|
update : 13/07/23 : gestion des prix
|
|
|
|
- par defaut si Le champ diction['price'] est rempli, alors on prend cette valeur.
|
|
- si cette valeur est vide ou inexistante, on va chercher le prix sur la session.
|
|
- Si aucun prix n'est mis sur la session, on va aller cherche le prix sur la formation.
|
|
|
|
|
|
"""
|
|
|
|
# Verifier que le type d'apprenant est bien valide
|
|
type_apprenant = "0"
|
|
|
|
|
|
if ("type_apprenant" in diction.keys() and str(diction['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 "
|
|
|
|
elif ("type_apprenant" in diction.keys()) :
|
|
type_apprenant = str(diction['type_apprenant'])
|
|
|
|
|
|
new_price = "-1" # 0 ==> par defaut
|
|
session_partner_owner_recid = ""
|
|
for tmp_val in MYSY_GV.dbname['session_formation'].find({"_id":ObjectId(str(session_id)), 'valide':'1' }):
|
|
mydata['date_du'] = str(tmp_val['date_debut'])[0:10]
|
|
mydata['date_au'] = str(tmp_val['date_fin'])[0:10]
|
|
mydata['partner_owner_recid'] = tmp_val['partner_owner_recid']
|
|
|
|
if ("prix_session" in tmp_val.keys()):
|
|
if tmp_val['prix_session']:
|
|
new_price = tmp_val['prix_session']
|
|
mydata['price'] = str(new_price)
|
|
|
|
|
|
if( "partner_owner_recid" in tmp_val.keys() ):
|
|
session_partner_owner_recid = tmp_val['partner_owner_recid']
|
|
|
|
## Update du 11/12/2023 : On doit prendre le class_internal_url sur la session et non sur la valeur du ditionnaire d'entré.
|
|
## car realité ces deux doivent etre les meme.
|
|
if ("class_internal_url" in tmp_val.keys()):
|
|
mydata['class_internal_url'] = str(tmp_val['class_internal_url']).strip()
|
|
|
|
|
|
civilite = "neutre"
|
|
if ("civilite" in diction.keys()):
|
|
if diction['civilite']:
|
|
civilite = str(diction['civilite']).strip().lower()
|
|
|
|
if (str(civilite) not in MYSY_GV.CIVILITE):
|
|
civilite = "neutre"
|
|
|
|
mydata['civilite'] = civilite
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
nom = str(diction['nom']).strip()
|
|
mydata['nom'] = nom
|
|
|
|
quotation_id = ""
|
|
if ("quotation_id" in diction.keys()):
|
|
if diction['quotation_id']:
|
|
quotation_id = str(diction['quotation_id']).strip()
|
|
|
|
|
|
is_valide_qotation = MYSY_GV.dbname['partner_order_header'].count_documents(
|
|
{'_id': ObjectId(str(diction['quotation_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'order_header_type': 'devis',
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_qotation != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du devis n'est pas valide ")
|
|
return False, " L'identifiant du devis n'est pas valide "
|
|
|
|
mydata['quotation_id'] = quotation_id
|
|
|
|
|
|
prenom = ""
|
|
if ("prenom" in diction.keys()):
|
|
if diction['prenom']:
|
|
prenom = str(diction['prenom']).strip()
|
|
mydata['prenom'] = prenom
|
|
|
|
employeur = ""
|
|
if ("employeur" in diction.keys()):
|
|
if diction['employeur']:
|
|
employeur = str(diction['employeur']).strip()
|
|
mydata['employeur'] = employeur
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
telephone = str(diction['telephone']).strip()
|
|
mydata['telephone'] = telephone
|
|
|
|
if ("client_rattachement_id" in diction.keys()):
|
|
if diction['client_rattachement_id']:
|
|
mydata['client_rattachement_id'] = diction['client_rattachement_id']
|
|
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents( {'_id': ObjectId(diction['client_rattachement_id']),
|
|
'valide': '1','locked': '0', 'partner_recid': str(my_session_data['partner_owner_recid'])})
|
|
|
|
if( local_client_retval_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le client de rattachement est invalide : local_client_retval_count = "+ str(local_client_retval_count))
|
|
return False, " Le client de rattachement est invalide "
|
|
|
|
else:
|
|
mydata['client_rattachement_id'] = ""
|
|
|
|
|
|
|
|
if ("facture_client_rattachement_id" in diction.keys()):
|
|
if diction['facture_client_rattachement_id']:
|
|
mydata['facture_client_rattachement_id'] = diction['facture_client_rattachement_id']
|
|
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents( {'_id': ObjectId(diction['facture_client_rattachement_id']),
|
|
'valide': '1','locked': '0', 'partner_recid': str(my_session_data['partner_owner_recid'])})
|
|
|
|
if( local_client_retval_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'entité à facturer est invalide : local_client_retval_count = "+ str(local_client_retval_count))
|
|
return False, " L'entité à facturer est invalide "
|
|
|
|
else:
|
|
mydata['facture_client_rattachement_id'] = ""
|
|
|
|
|
|
"""
|
|
11/07/2024 - si j'ai un client_client, mais pas de client facturé, alors on fait : client_facturé = client_client
|
|
"""
|
|
|
|
if ("facture_client_rattachement_id" in mydata.keys() and len(str(mydata['facture_client_rattachement_id']).strip()) <= 1 and "client_rattachement_id" in mydata.keys() and
|
|
len(str(mydata['client_rattachement_id']).strip()) > 3):
|
|
mydata['facture_client_rattachement_id'] = str(mydata['client_rattachement_id'])
|
|
|
|
"""
|
|
11/07/2024 - si j'ai un client facture , mais pas de client_client, alors on fait : client_client = client_facturé
|
|
"""
|
|
if ("client_rattachement_id" in mydata.keys() and len(str(mydata['client_rattachement_id']).strip()) <= 1 and len(
|
|
str(mydata['facture_client_rattachement_id']).strip()) > 3):
|
|
mydata['client_rattachement_id'] = str(mydata['facture_client_rattachement_id'])
|
|
|
|
|
|
|
|
if ("financeur_rattachement_id" in diction.keys()):
|
|
if diction['financeur_rattachement_id']:
|
|
mydata['financeur_rattachement_id'] = diction['financeur_rattachement_id']
|
|
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(
|
|
{'_id': ObjectId(diction['financeur_rattachement_id']),
|
|
'valide': '1', 'locked': '0', 'partner_recid': str(my_session_data['partner_owner_recid'])})
|
|
|
|
if (local_client_retval_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le client de rattachement est invalide : local_client_retval_count = " + str(
|
|
local_client_retval_count))
|
|
return False, " Le client de rattachement est invalide "
|
|
|
|
else:
|
|
mydata['financeur_rattachement_id'] = ""
|
|
|
|
if ("tuteur1_civilite" not in diction.keys()):
|
|
mydata['tuteur1_civilite'] = ""
|
|
|
|
elif (diction['tuteur1_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
mydata['tuteur1_civilite'] = ""
|
|
|
|
if ("tuteur2_civilite" not in diction.keys()):
|
|
mydata['tuteur2_civilite'] = ""
|
|
elif (diction['tuteur2_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
mydata['tuteur2_civilite'] = ""
|
|
|
|
|
|
if ("ville" in diction.keys()):
|
|
if diction['ville']:
|
|
mydata['ville'] = diction['ville']
|
|
else:
|
|
mydata['ville'] = ""
|
|
|
|
if ("code_postal" in diction.keys()):
|
|
if diction['code_postal']:
|
|
mydata['code_postal'] = diction['code_postal']
|
|
else:
|
|
mydata['code_postal'] = ""
|
|
|
|
if ("adresse" in diction.keys()):
|
|
if diction['adresse']:
|
|
mydata['adresse'] = diction['adresse']
|
|
else:
|
|
mydata['adresse'] = ""
|
|
|
|
|
|
if ("pays" in diction.keys()):
|
|
if diction['pays']:
|
|
mydata['pays'] = diction['pays']
|
|
else:
|
|
mydata['pays'] = ""
|
|
|
|
|
|
if ("inscription_validation_date" in diction.keys()):
|
|
if diction['inscription_validation_date']:
|
|
mydata['inscription_validation_date'] = str(diction['inscription_validation_date']).strip()
|
|
else:
|
|
mydata['inscription_validation_date'] = ""
|
|
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
mydata['email'] = str(diction['email']).strip()
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(diction['email']).strip() ) ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email "+str(diction['email']).strip() +" est invalide")
|
|
return False, " l'adresse email -"+str(diction['email']).strip() +"- est invalide"
|
|
|
|
|
|
if ("modefinancement" in diction.keys()):
|
|
if diction['modefinancement']:
|
|
mydata['modefinancement'] = str(diction['modefinancement']).strip()
|
|
else:
|
|
mydata['modefinancement'] = ""
|
|
|
|
if ("opco" in diction.keys()):
|
|
if diction['opco']:
|
|
mydata['opco'] = str(diction['opco']).strip()
|
|
else:
|
|
mydata['opco'] = ""
|
|
|
|
mydata['class_id'] = str(is_myclass_valide_data['_id'])
|
|
mydata['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
mydata['date_creation'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
|
mydata['update_by'] = str(connected_user_id)
|
|
mydata['created_by'] = str(connected_user_id)
|
|
mydata['valide'] = "1"
|
|
mydata['locked'] = "0"
|
|
|
|
new_status = "2" # 0 ==> par defaut Encours (Inscription en cours de creation, ici, on ne declenche aucun email)
|
|
if ("status" in diction.keys()):
|
|
if diction['status']:
|
|
new_status = str(diction['status']).strip()
|
|
if( new_status not in MYSY_GV.INSCRIPTION_STATUS):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le statut d'inscription : " + str(diction['status']) + " est invalide ")
|
|
return False, " Le statut d'inscription : " + str(diction['status']) + " est invalide "
|
|
|
|
|
|
mydata['status'] = str(new_status)
|
|
mydata['type_apprenant'] = str(type_apprenant)
|
|
|
|
|
|
# Si un prix est fourni dans le diction, j'ecrase le prise qui est venu de la session
|
|
if ("price" in diction.keys()):
|
|
if diction['price']:
|
|
new_price = str(diction['price']).strip()
|
|
mydata['price'] = str(diction['price']).strip()
|
|
|
|
|
|
# Verification des prix. si new_price = "-1" cela veut dire qu'il n'a pas de prix dans le diction ni sur la session
|
|
# Alors on va chercher le prix (prix public sans reduction) sur la formation
|
|
if( new_price == "-1"):
|
|
print(" aucun prix trouvé sur la session ")
|
|
local_class = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(diction['class_internal_url']).strip(),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( 'price' in local_class.keys()):
|
|
mydata['price'] = str(local_class['price']).strip()
|
|
else:
|
|
mydata['price'] = '0'
|
|
|
|
|
|
"""
|
|
Update du 22/10/2023 - Gestion des champs spécifiques ajoutés par le partenaire
|
|
"""
|
|
|
|
# Recuperation des champs spécifiques se trouvant dans le dictionnaire. ils commencent tous par 'my_'
|
|
for val in diction.keys():
|
|
if (val.startswith('my_')):
|
|
if (MYSY_GV.dbname['base_specific_fields'].count_documents(
|
|
{'partner_owner_recid': str(session_partner_owner_recid),
|
|
'related_collection': 'inscription',
|
|
'field_name': str(val),
|
|
'valide': '1',
|
|
'locked': '0'}) != 1):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
mydata[str(val)] = diction[str(val)]
|
|
|
|
|
|
#print(" #### mydata = " + str(mydata))
|
|
|
|
coll_inscription = MYSY_GV.dbname['inscription']
|
|
|
|
## Verification si cette adresse n'est pas deja inscrite à cette session
|
|
# print(" myquery pr demo_account = " + str(myquery))
|
|
qry_count = {'email':str(mydata['email']), 'session_id':str( mydata['session_id']), }
|
|
|
|
#print(" ### qry_count = ", qry_count)
|
|
tmp = coll_inscription.count_documents({'email':str(mydata['email']),
|
|
'session_id':str( mydata['session_id']),
|
|
})
|
|
|
|
if( tmp > 0 ) :
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'adresse email "+str(mydata['email'])+" est deja inscrite à la session du "
|
|
" "+str( mydata['session_id'])+ " ")
|
|
|
|
return False, "Impossible de créer le stagiaire. l'adresse email "+str(mydata['email'])\
|
|
+" est deja inscrite à cette session de formation "
|
|
|
|
|
|
"""
|
|
Un email ne pouvant s'inscrire qu'a une seule session_id; on fait un upsert
|
|
"""
|
|
#print(" #### mydata before inscr = ", mydata)
|
|
ret_val = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'session_id': str(mydata['session_id']), 'email': str(mydata['email']),},
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=True,
|
|
)
|
|
|
|
if (ret_val is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'ajouter la participant ")
|
|
return False, " Impossible d'ajouter la participant "
|
|
|
|
#ret_val = coll_inscription.insert_one(mydata)
|
|
|
|
Warning_message = ""
|
|
|
|
inserted_id = ret_val['_id']
|
|
|
|
"""
|
|
26/05/2024 : S'il s'agit d'une formation initiale, alors on lance la fonction 'xxxx'
|
|
qui permet de créer les contenus des collection 'inscription_liste_ue' et peut etre 'inscription_liste_ue_type_eval'
|
|
|
|
Il s'agit du remplissage par defaut ou tout est actif
|
|
|
|
"""
|
|
|
|
if ("tab_ue_ids" not in diction.keys() and "formation_initiale" in my_partner.keys() and my_partner['formation_initiale'] == "1" ):
|
|
local_diction = {}
|
|
local_diction['token'] = diction['token']
|
|
local_diction['inscription_id'] = str(inserted_id)
|
|
local_diction['class_id'] = str(is_myclass_valide_data['_id'])
|
|
|
|
print(" ### Init_AcceptAttendeeInscription_For_Initial_Formation 11 local_diction = ",local_diction )
|
|
|
|
local_inscription_liste_ue_status, local_inscription_liste_ue_retval = Init_AcceptAttendeeInscription_For_Initial_Formation(
|
|
local_diction)
|
|
|
|
print(" local_inscription_liste_ue_status, local_inscription_liste_ue_retval = ",
|
|
local_inscription_liste_ue_status, local_inscription_liste_ue_retval)
|
|
|
|
|
|
elif ("tab_ue_ids" in diction.keys() and "formation_initiale" in my_partner.keys() and my_partner['formation_initiale'] == "1" ):
|
|
# Ici l'utilisateur a fourni un list d'UE ou il faut inscrire l'apprenant.
|
|
# Ceci s'applique lorsque par exemple un apprenant d'inscrit à 1 ou 2 UE sur une formation
|
|
local_diction = {}
|
|
local_diction['token'] = diction['token']
|
|
local_diction['inscription_id'] = str(inserted_id)
|
|
local_diction['class_id'] = str(is_myclass_valide_data['_id'])
|
|
local_diction['tab_ue_ids'] = str(diction['tab_ue_ids'])
|
|
|
|
print(" ### Init_AcceptAttendeeInscription_For_Initial_Formation 22 local_diction = ",local_diction )
|
|
|
|
local_inscription_liste_ue_status, local_inscription_liste_ue_retval = Init_AcceptAttendeeInscription_For_Initial_Formation(
|
|
local_diction)
|
|
|
|
print(" local_inscription_liste_ue_status, local_inscription_liste_ue_retval = ",
|
|
local_inscription_liste_ue_status, local_inscription_liste_ue_retval)
|
|
|
|
|
|
|
|
"""
|
|
update du 25/08/23
|
|
On ne declenche l'envoie d'un email que l'inscription est soit :
|
|
- Preinscrit (hors reservation automatique - validation devis) soit
|
|
- inscrit soit
|
|
- annulé.
|
|
|
|
Donc pas d'email si le statut est (2 => 'encours de creation'
|
|
On doit donner la possibilité a l'utilisateur de saisir une inscription avec un statut en cours de creation : 'creation'
|
|
"""
|
|
|
|
if( inserted_id ):
|
|
# On verifie que le statut de l'inscription n'est pas (2 : en cours) avant de declencher des envoies d'email
|
|
|
|
"""
|
|
update 21/04/2024 -
|
|
si le champs devis est remplis, alors il s'agit d'une inscription qui vient de la validation automatique d'un devis
|
|
pour le moment, dans ce cas figure, vu que les email ne sont pas bon car il s'agit d'un resa, alors on ne declenche
|
|
pas d'envoie d'email
|
|
"""
|
|
if( new_status == "0" and quotation_id == ""):
|
|
# Le stagaire a bien ete inseré, on declenche l'envoi des emails
|
|
|
|
## Envoie de l'email de preinscription
|
|
mail_data = {}
|
|
mail_data['token'] = diction['token']
|
|
mail_data['email'] = diction['email']
|
|
mail_data['class_internal_url'] = diction['class_internal_url']
|
|
mail_data['session_id'] = diction['session_id']
|
|
mail_data['inscription_id'] = ret_val['_id']
|
|
|
|
#print(" ### l'inscription est ok, il faut declencher l'envoi des email a "+str(mail_data))
|
|
"""
|
|
26/02/2025 :
|
|
Si le paramettre, 'inscription_notification_email' de la collection 'base_partner_setup' est à 1,
|
|
alors on envoie un email de notification à l'apprenant
|
|
"""
|
|
local_insc_status, local_insc_retval = mycommon.Is_Partnair_Prenscription_Notification(
|
|
{'token': diction['token']})
|
|
if (local_insc_status and local_insc_retval == "1"):
|
|
local_status, message = SendPre_InscriptionEmail(mail_data)
|
|
if( local_status is False):
|
|
mycommon.myprint(" WARNING : Impossible d'envoyer le mail de preinscriton à "+
|
|
str(inspect.stack()[0][3]) + " - l'adresse email " + str(
|
|
mydata['email']) + " pour la session " + str(mydata['session_id']) + " ")
|
|
|
|
Warning_message = " WARNING : Impossible d'envoyer le mail de preinscriton à "+ str(inspect.stack()[0][3]) + " - l'adresse email " + str( mydata['email']) + " pour la session " + str(mydata['session_id']) + " "
|
|
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - ret_val.inserted_id is null ")
|
|
return False, "Impossible de créer le stagiaire"
|
|
|
|
|
|
|
|
"""
|
|
29/12/2023 : La creation s'est bien passée, si c'est une inscription definitive du premier cout,
|
|
c'est a dire que str(new_status) = 1 => Inscription (validée) alors on fait la creation ou une mise à jour
|
|
du dossier apprenant en meme tps
|
|
"""
|
|
if (new_status == "1"):
|
|
local_apprenant_id = ""
|
|
is_apprenant_existe_count = MYSY_GV.dbname['apprenant'].count_documents(
|
|
{'email': str(diction['email']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_apprenant_existe_count > 0):
|
|
# Il faut mettre à jour un dossier apprenant
|
|
is_apprenant_existe = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'email': str(diction['email']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'}, {'_id': 1})
|
|
|
|
|
|
new_apprenant_diction = diction
|
|
champ_to_delete = ['class_internal_url', 'session_id', 'inscription_validation_date', 'apprenant_id',
|
|
'status', 'modefinancement', 'type_apprenant', 'financeur_rattachement_id',
|
|
'quotation_id', 'facture_client_rattachement_id']
|
|
|
|
for val in champ_to_delete:
|
|
if (val in new_apprenant_diction.keys()):
|
|
del new_apprenant_diction[str(val)]
|
|
|
|
new_apprenant_diction['_id'] = str(is_apprenant_existe['_id'])
|
|
|
|
local_apprenant_id = str(is_apprenant_existe['_id'])
|
|
if( "tab_ue_ids" in new_apprenant_diction.keys()):
|
|
del new_apprenant_diction['tab_ue_ids']
|
|
|
|
local_status, local_retval = apprenant_mgt.Update_Apprenant(new_apprenant_diction)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
else:
|
|
|
|
new_apprenant_diction = diction
|
|
champ_to_delete = [ 'class_internal_url', 'session_id', 'inscription_validation_date', 'apprenant_id', 'status',
|
|
'modefinancement', 'type_apprenant', 'financeur_rattachement_id',
|
|
'quotation_id', 'facture_client_rattachement_id', 'tab_ue_ids']
|
|
for val in champ_to_delete:
|
|
if( val in new_apprenant_diction.keys()):
|
|
del new_apprenant_diction[str(val)]
|
|
|
|
local_status, local_retval = apprenant_mgt.Add_Apprenant(new_apprenant_diction)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
"""
|
|
recuperation de l'id du dossier qui vient d'etre créer
|
|
"""
|
|
apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'email': str(diction['email']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'_id': 1})
|
|
|
|
if (apprenant_data is None):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Impossible de récuperer l'identifiant du dossier créé ")
|
|
return False, " Impossible de récuperer l'identifiant du dossier créé "
|
|
|
|
local_apprenant_id = str(apprenant_data['_id'])
|
|
|
|
|
|
"""
|
|
Apres la creation du dossier on met à jour l'inscription en rajoutant l'apprenant_id
|
|
"""
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId(str(inserted_id)), 'email': str(diction['email']),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": {'apprenant_id': str(local_apprenant_id), 'date_update': str(datetime.now()),
|
|
'update_by': str(my_partner['_id'])}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
|
|
|
|
"""
|
|
Update du 08/10/2024 :
|
|
Vu que c'est une inscription validée du premier cout, alors on va lancer les opération de validation
|
|
"""
|
|
|
|
|
|
local_diction = {}
|
|
local_diction['token'] = str(mytoken)
|
|
local_diction['email'] = str(diction['email'])
|
|
local_diction['inscription_id'] = str(inserted_id)
|
|
|
|
#print(" ### -- local_diction = ", local_diction)
|
|
|
|
local_status, local_retval = AcceptAttendeeInscription(local_diction)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
seulement dans le cas de la preinscription, car le log de la validation de l'inscription
|
|
est porté par la fonction 'acceptinscription..."
|
|
"""
|
|
if( new_status == "0"):
|
|
|
|
# pour la collection 'inscription'
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
#print(" ####### laaaa diction = ", diction)
|
|
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = mytoken
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(inserted_id)
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = "Id Session : "+str(my_session_data['_id'])
|
|
if( "code_session" in my_session_data.keys() ):
|
|
local_session_info = local_session_info + ", Code Session : " + my_session_data["code_session"]
|
|
|
|
history_event_dict['action_description'] = "Preinscription à "+str(local_session_info)
|
|
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))
|
|
|
|
|
|
# Pour la collection session_formation
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = mytoken
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(my_session_data['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = " : " + str(inserted_id)
|
|
if ("email" in diction.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + diction["email"]
|
|
|
|
if ("nom" in diction.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + diction["nom"]
|
|
|
|
if ("prenom" in diction.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + diction["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Preinscription de " + str(local_inscrit_info)
|
|
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 stagiaire à bien été créé. "+str(Warning_message)
|
|
|
|
|
|
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 stagiaire"
|
|
|
|
"""
|
|
Mettre à jour les infomration d'un stgiaire
|
|
|
|
/!\ : on NE mets PAS à jour la session, juste les info du stagiaire
|
|
|
|
# status : 0 ==> Preinscription
|
|
# status : 1 ==> Inscription validée
|
|
# status : -1 ==> Inscription annulée
|
|
# status : 2 ==> Inscription encours de creation
|
|
|
|
/!\ Inscription sur le LMS :
|
|
Si la session de formation possede un code de formation lms 'lms_class_code'
|
|
|
|
Alors cela veut dire que c'est une formation qui est gérée avec le LMS de MYSY.
|
|
Donc l'inscription va generer :
|
|
1 - La creation du compte LMS participant
|
|
2 - L'inscription de l'utilisateur à la formation.
|
|
|
|
"""
|
|
def UpdateStagiairetoClass(diction):
|
|
try:
|
|
|
|
return_message = ""
|
|
field_list = ['token', 'email', 'nom', 'prenom', 'telephone', 'modefinancement', 'opco',
|
|
'status', 'class_internal_url', 'session_id', 'price', 'employeur', 'comment',
|
|
'_id', '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', 'type_apprenant', 'civilite',
|
|
'date_naissance', 'financeur_rattachement_id', 'facture_client_rattachement_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é, Creation partenaire annulée")
|
|
return False, "Impossible de mettre à jour stagiaire. Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'class_internal_url', 'session_id', '_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 mettre à jour stagiaire, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
query_key = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = str(diction['token']).strip()
|
|
#query_key['token'] = diction['token']
|
|
|
|
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
mydata = {}
|
|
user_nom = ""
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token':mytoken})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
myemail = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
myemail = str(diction['email']).strip()
|
|
if( mycommon.isEmailValide(myemail)) :
|
|
mydata['email'] = str(diction['email']).strip()
|
|
else:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - l'adresse email "+str(myemail)+" n'est pas valide")
|
|
return False, "- l'adresse email "+str(myemail)+" n'est pas valide "
|
|
|
|
|
|
object_id = ""
|
|
if ("_id" in diction.keys()):
|
|
if diction['_id']:
|
|
object_id = str(diction['_id']).strip()
|
|
query_key['_id'] = ObjectId (str(diction['_id']).strip())
|
|
|
|
myinternal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
myinternal_url = str(diction['class_internal_url']).strip()
|
|
#query_key['class_internal_url'] = str(diction['class_internal_url']).strip()
|
|
|
|
mysession_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
mysession_id = str(diction['session_id']).strip()
|
|
#query_key['session_id'] = str(diction['session_id']).strip()
|
|
|
|
|
|
""""
|
|
/!\ : update du 18/08/2023 : On va autoriser le changement le session de formation.
|
|
en effet il peut arriver qu'on souhaite deplacer la formation d'une personne à une autre session.
|
|
"""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
mysession_id = str(diction['session_id']).strip()
|
|
mydata['session_id'] = str(diction['session_id']).strip()
|
|
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
mydata['nom'] = str(diction['nom']).strip()
|
|
user_nom = str(diction['nom']).strip()
|
|
|
|
if ("civilite" in diction.keys()):
|
|
mydata['civilite'] = str(diction['civilite']).strip().lower()
|
|
|
|
if (str(mydata['civilite']) not in MYSY_GV.CIVILITE):
|
|
mydata['civilite'] = "neutre"
|
|
|
|
|
|
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' "
|
|
|
|
mydata['date_naissance'] = str(date_naissance)
|
|
|
|
|
|
if ("price" in diction.keys()):
|
|
mydata['price'] = str(diction['price']).strip()
|
|
|
|
if ("employeur" in diction.keys()):
|
|
mydata['employeur'] = str(diction['employeur']).strip()
|
|
|
|
if ("tuteur1_nom" in diction.keys()):
|
|
mydata['tuteur1_nom'] = str(diction['tuteur1_nom']).strip()
|
|
|
|
if ("tuteur1_email" in diction.keys()):
|
|
mydata['tuteur1_email'] = str(diction['tuteur1_email']).strip()
|
|
|
|
if ("tuteur1_email" in diction.keys()):
|
|
mydata['tuteur1_email'] = str(diction['tuteur1_email']).strip()
|
|
|
|
if ("tuteur1_telephone" in diction.keys()):
|
|
mydata['tuteur1_telephone'] = str(diction['tuteur1_telephone']).strip()
|
|
|
|
if ("tuteur1_adresse" in diction.keys()):
|
|
mydata['tuteur1_adresse'] = str(diction['tuteur1_adresse']).strip()
|
|
|
|
if ("tuteur1_cp" in diction.keys()):
|
|
mydata['tuteur1_cp'] = str(diction['tuteur1_cp']).strip()
|
|
|
|
if ("tuteur1_ville" in diction.keys()):
|
|
mydata['tuteur1_ville'] = str(diction['tuteur1_ville']).strip()
|
|
|
|
if ("tuteur1_pays" in diction.keys()):
|
|
mydata['tuteur1_pays'] = str(diction['tuteur1_pays']).strip()
|
|
|
|
if ("tuteur1_include_com" in diction.keys()):
|
|
mydata['tuteur1_include_com'] = str(diction['tuteur1_include_com']).strip()
|
|
|
|
if ("tuteur2_nom" in diction.keys()):
|
|
mydata['tuteur2_nom'] = str(diction['tuteur2_nom']).strip()
|
|
|
|
if("tuteur2_email" in diction.keys()):
|
|
mydata['tuteur2_email'] = str(diction['tuteur2_email']).strip()
|
|
|
|
if ("tuteur2_email" in diction.keys()):
|
|
mydata['tuteur2_email'] = str(diction['tuteur2_email']).strip()
|
|
|
|
if ("tuteur2_telephone" in diction.keys()):
|
|
mydata['tuteur2_telephone'] = str(diction['tuteur2_telephone']).strip()
|
|
|
|
if ("tuteur2_adresse" in diction.keys()):
|
|
mydata['tuteur2_adresse'] = str(diction['tuteur2_adresse']).strip()
|
|
|
|
if ("tuteur2_cp" in diction.keys()):
|
|
mydata['tuteur2_cp'] = str(diction['tuteur2_cp']).strip()
|
|
|
|
if ("tuteur2_ville" in diction.keys()):
|
|
mydata['tuteur2_ville'] = str(diction['tuteur2_ville']).strip()
|
|
|
|
if ("tuteur2_pays" in diction.keys()):
|
|
mydata['tuteur2_pays'] = str(diction['tuteur2_pays']).strip()
|
|
|
|
if ("tuteur2_include_com" in diction.keys()):
|
|
mydata['tuteur2_include_com'] = str(diction['tuteur2_include_com']).strip()
|
|
|
|
# Verifier que le type d'apprenant est bien valide
|
|
if( "type_apprenant" in diction.keys() ):
|
|
if (str(diction['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 "
|
|
else:
|
|
mydata['type_apprenant'] = str(diction['type_apprenant'])
|
|
|
|
|
|
user_prenom = ""
|
|
if ("prenom" in diction.keys()):
|
|
mydata['prenom'] = str(diction['prenom']).strip()
|
|
user_prenom = str(diction['prenom']).strip()
|
|
|
|
if ("telephone" in diction.keys()):
|
|
mydata['telephone'] = str(diction['telephone']).strip()
|
|
|
|
if ("modefinancement" in diction.keys()):
|
|
mydata['modefinancement'] = str(diction['modefinancement']).strip()
|
|
|
|
if ("opco" in diction.keys()):
|
|
mydata['opco'] = str(diction['opco']).strip()
|
|
|
|
if ("price" in diction.keys()):
|
|
mydata['price'] = str(diction['price']).strip()
|
|
|
|
if ("adresse" in diction.keys()):
|
|
mydata['adresse'] = str(diction['adresse']).strip()
|
|
|
|
if ("code_postal" in diction.keys()):
|
|
mydata['code_postal'] = str(diction['code_postal']).strip()
|
|
|
|
if ("ville" in diction.keys()):
|
|
mydata['ville'] = str(diction['ville']).strip()
|
|
|
|
if ("pays" in diction.keys()):
|
|
mydata['pays'] = str(diction['pays']).strip()
|
|
|
|
new_status = ""
|
|
old_status = ""
|
|
if ("status" in diction.keys()):
|
|
if diction['status']:
|
|
mydata['status'] = str(diction['status']).strip()
|
|
new_status = str(diction['status']).strip()
|
|
|
|
# On stock le old_status avec la valeur de new_status.
|
|
# Cela permettra de comparer apres pour voir s'il y a un changement de statut.
|
|
old_status = str(diction['status']).strip()
|
|
|
|
if (new_status not in MYSY_GV.INSCRIPTION_STATUS):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le statut d'inscription : " + str(
|
|
diction['status']) + " est invalide ")
|
|
return False, " Le statut d'inscription : " + str(diction['status']) + " est invalide "
|
|
|
|
|
|
if ("comment" in diction.keys()):
|
|
mydata['comment'] = str(diction['comment']).strip()
|
|
|
|
|
|
if ("client_rattachement_id" in diction.keys()):
|
|
mydata['client_rattachement_id'] = str(diction['client_rattachement_id']).strip()
|
|
if(len(str(diction['client_rattachement_id']).strip()) > 0 ):
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents({'_id': ObjectId(diction['client_rattachement_id']),
|
|
'valide': '1', 'locked': '0', 'partner_recid': str(partner_recid)})
|
|
|
|
if (local_client_retval_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le client de rattachement est invalide : local_client_retval_count = "+str(local_client_retval_count))
|
|
return False, " Le client de rattachement est invalide "
|
|
|
|
|
|
if ("facture_client_rattachement_id" in diction.keys()):
|
|
mydata['facture_client_rattachement_id'] = str(diction['facture_client_rattachement_id']).strip()
|
|
if(len(str(diction['facture_client_rattachement_id']).strip()) > 0 ):
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents({'_id': ObjectId(diction['facture_client_rattachement_id']),
|
|
'valide': '1', 'locked': '0', 'partner_recid': str(partner_recid)})
|
|
|
|
if (local_client_retval_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'entité à facturer est invalide : local_client_retval_count = "+str(local_client_retval_count))
|
|
return False, "L'entité à facturer est invalide "
|
|
|
|
|
|
|
|
if ("financeur_rattachement_id" in diction.keys()):
|
|
mydata['financeur_rattachement_id'] = str(diction['financeur_rattachement_id']).strip()
|
|
if (len(str(diction['financeur_rattachement_id']).strip()) > 0):
|
|
## Verifier l'existance du client de rattachement
|
|
local_client_retval_count = MYSY_GV.dbname['partner_client'].count_documents(
|
|
{'_id': ObjectId(diction['financeur_rattachement_id']),
|
|
'valide': '1', 'locked': '0', 'partner_recid': str(partner_recid)})
|
|
|
|
if (local_client_retval_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le financeur de rattachement est invalide : local_client_retval_count = " + str(
|
|
local_client_retval_count))
|
|
return False, " Le financeur de rattachement est invalide "
|
|
|
|
|
|
# ici recup des infos de la session
|
|
local_query = {'_id': ObjectId(str(mysession_id)), 'valide': '1'}
|
|
print("### local_query = " + str(local_query))
|
|
|
|
local_tmp_session_count = MYSY_GV.dbname['session_formation'].count_documents(local_query)
|
|
if (local_tmp_session_count <= 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucune session de formation pour " + str(local_query))
|
|
return False, "Impossible de mettre à jour le stagiaire, Cette session de formation n'est pas valide "
|
|
|
|
if (local_tmp_session_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Plusieurs sessions existent pour ce code sessions " + str(
|
|
local_query))
|
|
return False, "Impossible de mettre à jour le stagiaire, Cette session de formation n'est pas valide (2) "
|
|
|
|
local_tmp_session_data = MYSY_GV.dbname['session_formation'].find_one(local_query)
|
|
|
|
"""
|
|
update de 20/08/23 :
|
|
Vu qu'on autorise maintenant le changement de session, alors pour parer à une eventuellement changement de sessio
|
|
pour une affectation a une session appartenant à une autre formation,
|
|
on va ecraser le 'class_internal_url' de la collection 'inscription' avec celui de la collection 'session_formation'
|
|
|
|
"""
|
|
mydata['class_internal_url'] = str(local_tmp_session_data['class_internal_url']).strip()
|
|
|
|
# Recuperation des champs spécifiques se trouvant dans le dictionnaire. ils commencent tous par 'my_'
|
|
for val in diction.keys():
|
|
if (val.startswith('my_')):
|
|
if (MYSY_GV.dbname['base_specific_fields'].count_documents(
|
|
{'partner_owner_recid': str(partner_recid),
|
|
'related_collection': 'inscription',
|
|
'field_name': str(val),
|
|
'valide': '1',
|
|
'locked': '0'}) != 1):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
mydata[str(val)] = diction[str(val)]
|
|
|
|
"""
|
|
Pour gerer la date de validation, différemment d'une simple mise à jour,
|
|
on récupérer le status actuellement en base, on verifie si le nouveau status != de status en base.
|
|
|
|
Si il y a changement de status alors c'est une date de changement de status.
|
|
"""
|
|
coll_inscription = MYSY_GV.dbname['inscription']
|
|
|
|
#print(" #### query_key = ", query_key)
|
|
local_retval = coll_inscription.find_one(query_key)
|
|
|
|
message_for_historic = ""
|
|
|
|
if( local_retval is not None ):
|
|
if( "status" in local_retval.keys()):
|
|
|
|
# On recupere le statut stock en base dans 'old_status'
|
|
old_status = local_retval['status']
|
|
inscription_line_id = local_retval['_id']
|
|
|
|
|
|
if( new_status != old_status ):
|
|
# Il y a eu un changement de status
|
|
if( new_status == "1"):
|
|
mydata['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
message_for_historic = "Validation Inscription"
|
|
|
|
if (new_status == "-1"):
|
|
mydata['inscription_refuse_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
message_for_historic = "Refus Inscription"
|
|
|
|
if (new_status == "2"):
|
|
mydata['inscription_preinscription_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
message_for_historic = "Préinscription "
|
|
|
|
mydata['date_update'] = str(datetime.now())
|
|
mydata['update_by'] = str(my_partner['_id'])
|
|
|
|
ret_val2 = coll_inscription.find_one_and_update(query_key,
|
|
{"$set": mydata},
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (ret_val2 and ret_val2['_id']):
|
|
|
|
"""
|
|
- Si le status == 1; alors il s'agit d'une validation d'une inscription.
|
|
- Si le status == -1; alors il s'agit d'une refus d'une inscription.
|
|
- Si le status == 0; alors il s'agit d'une preinscription.
|
|
|
|
Du coup, il faut envoyer le mail de confirmation de l'inscription:
|
|
1 - recuperation des infos de la session
|
|
1 BIS - recuperation du title
|
|
2 - Envoie de l'email
|
|
"""
|
|
email_data = {}
|
|
email_data['nom'] = user_nom
|
|
email_data['prenom'] = user_prenom
|
|
email_data['email'] = myemail
|
|
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
email_data['comment'] = diction['comment']
|
|
|
|
if ("code_session" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['code_session']:
|
|
email_data['code_session'] = local_tmp_session_data['code_session']
|
|
|
|
if ("date_debut" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['date_debut']:
|
|
email_data['date_debut'] = str(local_tmp_session_data['date_debut'])[0:10]
|
|
|
|
if ("date_fin" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['date_fin']:
|
|
email_data['date_fin'] = str(local_tmp_session_data['date_fin'])[0:10]
|
|
|
|
if ("adresse" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['adresse']:
|
|
email_data['adresse'] = local_tmp_session_data['adresse']
|
|
|
|
if ("code_postal" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['code_postal']:
|
|
email_data['code_postal'] = local_tmp_session_data['code_postal']
|
|
|
|
if ("ville" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['ville']:
|
|
email_data['ville'] = local_tmp_session_data['ville']
|
|
|
|
if ("session_ondemande" in local_tmp_session_data.keys()):
|
|
if local_tmp_session_data['session_ondemande']:
|
|
email_data['session_ondemande'] = local_tmp_session_data['session_ondemande']
|
|
|
|
|
|
|
|
# ici recup du titre
|
|
lms_class_code = ""
|
|
for local_tmp_myclass in MYSY_GV.dbname['myclass'].find(
|
|
{'internal_url': str(myinternal_url)}):
|
|
|
|
local_title = ""
|
|
if ("title" in local_tmp_myclass.keys() and local_tmp_myclass['title']):
|
|
local_title = local_tmp_myclass['title']
|
|
email_data['title'] = local_title
|
|
|
|
|
|
if ("lms_class_code" in local_tmp_myclass.keys() ):
|
|
lms_class_code = local_tmp_myclass['lms_class_code']
|
|
|
|
print(" #### new_status / old_status / diction['status'] = ",new_status, old_status, str(diction['status']) )
|
|
if ( new_status != old_status and diction['status'] == "0" ):
|
|
mail_data = {}
|
|
mail_data['email'] = diction['email']
|
|
mail_data['class_internal_url'] = diction['class_internal_url']
|
|
mail_data['session_id'] = diction['session_id']
|
|
mail_data['inscription_id'] = diction['_id']
|
|
|
|
# Il s'agit d'envoyer le message de presinscription
|
|
|
|
local_status, local_message = SendPre_InscriptionEmail(mail_data)
|
|
if (local_status is False):
|
|
mycommon.myprint(" WARNING : Impossible d'envoyer le mail de preinscriton à " +
|
|
str(inspect.stack()[0][3]) + " - l'adresse email " + str(
|
|
mydata['email']) + " pour la session " + str(mydata['session_id']) + " ")
|
|
|
|
Warning_message = " WARNING : Impossible d'envoyer le mail de preinscriton à " + str(
|
|
inspect.stack()[0][3]) + " - l'adresse email " + str(
|
|
mydata['email']) + " pour la session " + str(mydata['session_id']) + " "
|
|
|
|
message_for_historic = message_for_historic + " : Email Préinscription "
|
|
|
|
|
|
if (new_status != old_status and diction['status'] == "1" ):
|
|
|
|
# Il s'agit d'envoyer le message de confirmation d'une inscription
|
|
email_data['partner_owner_recid'] = str(partner_recid)
|
|
|
|
"""
|
|
26/02/2025 :
|
|
Si le paramettre, 'inscription_notification_email' de la collection 'base_partner_setup' est à 1,
|
|
alors on envoie un email de notification à l'apprenant
|
|
"""
|
|
local_insc_status, local_insc_retval = mycommon.Is_Partnair_Inscription_Notification(
|
|
{'token': diction['token']})
|
|
if (local_insc_status and local_insc_retval == "1"):
|
|
local_status, local_message = email_session.incription_training_confirmation_mail(email_data)
|
|
message_for_historic = message_for_historic + " : Email Inscription "
|
|
|
|
"""
|
|
Update du 28/12/2023
|
|
"""
|
|
local_diction = {}
|
|
local_diction['token'] = str(diction['token'])
|
|
local_diction['email'] = str(diction['email'])
|
|
local_diction['inscription_id'] = str(diction['_id'])
|
|
|
|
#print(" ### -- local_diction = ", local_diction)
|
|
|
|
|
|
local_status, local_retval = AcceptAttendeeInscription(local_diction)
|
|
if( local_status is False ):
|
|
return local_status, local_retval
|
|
|
|
|
|
|
|
elif ( new_status != old_status and diction['status'] == "-1" ):
|
|
# Il s'agit d'envoyer le message de refus d'une inscription
|
|
if( "date_debut" not in email_data.keys() ):
|
|
email_data['date_du'] = "--"
|
|
else:
|
|
email_data['date_du'] = str(email_data['date_debut'])
|
|
|
|
if ("date_fin" not in email_data.keys()):
|
|
email_data['date_au'] = "--"
|
|
else:
|
|
email_data['date_au'] = str(email_data['date_fin'])
|
|
|
|
email_data['partner_recid'] = str(partner_recid)
|
|
email_data['token'] = str(diction['token'])
|
|
|
|
#print(" ### avant refus : email_data = ", email_data)
|
|
|
|
local_status, local_message = email_session.incription_training_refused_mail(email_data)
|
|
message_for_historic = message_for_historic + " : Email Refus Inscription "
|
|
|
|
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique pour l'inscrit
|
|
"""
|
|
|
|
message_for_historic = message_for_historic+", pour la session : "+str(local_tmp_session_data['_id'])
|
|
if( "code_session" in local_tmp_session_data.keys() ):
|
|
message_for_historic = message_for_historic + ", code session " + str(local_tmp_session_data['code_session'])
|
|
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = str(message_for_historic)
|
|
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))
|
|
|
|
|
|
inscrit_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(diction['_id']).strip()),
|
|
'partner_owner_recid': str(partner_recid),})
|
|
"""
|
|
# Ajout de l'evenement dans l'historique pour la session
|
|
"""
|
|
session_info_message = "Annulation de l'inscription : "+str(inscrit_data['_id'])
|
|
if ("email" in local_tmp_session_data.keys()):
|
|
session_info_message = session_info_message + ", " + str(local_tmp_session_data['email'])
|
|
if ("nom" in local_tmp_session_data.keys()):
|
|
session_info_message = session_info_message + ", " + str(local_tmp_session_data['nom'])
|
|
if ("prenom" in local_tmp_session_data.keys()):
|
|
session_info_message = session_info_message + ", " + str(local_tmp_session_data['prenom'])
|
|
|
|
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(local_tmp_session_data['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = str(session_info_message)
|
|
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, "Les données du stagiaire ont été correctement mise à jour"
|
|
|
|
|
|
else:
|
|
mycommon.myprint(" Impossible de mettre à jour les données du stagiaire 1")
|
|
return False, "Impossible de mettre à jour les données du stagiaire "
|
|
|
|
|
|
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 les informations du stagiaire"
|
|
|
|
|
|
|
|
"""
|
|
Recuperation d'un stagiaire
|
|
"""
|
|
def GetStagiaire(diction):
|
|
try:
|
|
field_list = ['nom', 'adr_street', 'adr_city']
|
|
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é, Creation partenaire annulée")
|
|
return False, "Impossible de récupérer le stagiaire. Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['nom', 'email', 'pwd', ]
|
|
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 le stagiaire, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
|
|
return True
|
|
|
|
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 récupérer le stagiaire"
|
|
|
|
|
|
"""
|
|
Recuperation de liste des stagiaire d'une formation
|
|
# status : 0 ==> Preinscription
|
|
# status : 1 ==> Inscription validée
|
|
# status : -1 ==> Inscription annulée
|
|
"""
|
|
def GetAllClassStagiaire(diction):
|
|
try:
|
|
field_list = ['token', 'class_internal_url', 'session_id', '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é, Creation partenaire annulée")
|
|
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Impossible de récupérer la liste des stagiaires, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
|
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes "
|
|
|
|
"""
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
"""
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
status = ""
|
|
if ("status" in diction.keys()):
|
|
if diction['status']:
|
|
status = diction['status']
|
|
|
|
|
|
## Recuperation de toutes les stagiaire rattaché à cette session
|
|
coll_session = MYSY_GV.dbname['inscription']
|
|
myquery = {}
|
|
myquery['session_id'] = session_id
|
|
#myquery['class_internal_url'] = class_internal_url
|
|
|
|
if(len(status) > 0 ):
|
|
myquery['status'] = status
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
#print(" #### myquery 01111 = "+str(myquery))
|
|
|
|
|
|
for retval in coll_session.find(myquery):
|
|
val_tmp = val_tmp + 1
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
|
|
|
|
client_rattachement_id = ""
|
|
client_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
# print(" ### retVal = ", retVal )
|
|
if ("client_rattachement_id" in retval.keys()):
|
|
if (retval['client_rattachement_id'] and str(retval['client_rattachement_id']) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(retval['client_rattachement_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (client_retval is not None):
|
|
client_rattachement_id = client_retval['_id']
|
|
client_rattachement_nom = client_retval['nom']
|
|
|
|
user['client_rattachement_id'] = client_rattachement_id
|
|
user['client_rattachement_nom'] = client_rattachement_nom
|
|
|
|
if ("facture_client_rattachement_id" in retval.keys()):
|
|
user['facture_client_rattachement_id'] = retval['facture_client_rattachement_id']
|
|
else:
|
|
user['facture_client_rattachement_id'] = ""
|
|
|
|
|
|
if( "invoice_split" in retval.keys() ):
|
|
user['has_invoice_split'] = "1"
|
|
else:
|
|
user['has_invoice_split'] = "0"
|
|
|
|
|
|
#-----
|
|
financeur_rattachement_id = ""
|
|
financeur_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
# print(" ### retVal = ", retVal )
|
|
if ("financeur_rattachement_id" in retval.keys()):
|
|
if (retval['financeur_rattachement_id'] and str(retval['financeur_rattachement_id']) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(retval['financeur_rattachement_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (client_retval is not None):
|
|
financeur_rattachement_id = client_retval['_id']
|
|
financeur_rattachement_nom = client_retval['nom']
|
|
|
|
user['financeur_rattachement_id'] = financeur_rattachement_id
|
|
user['financeur_rattachement_nom'] = financeur_rattachement_nom
|
|
|
|
invoiced = ""
|
|
if( "invoiced" in retval.keys() ):
|
|
invoiced = retval['invoiced']
|
|
user['invoiced'] = invoiced
|
|
|
|
invoiced_ref = ""
|
|
if ("invoiced_ref" in retval.keys()):
|
|
invoiced_ref = retval['invoiced_ref']
|
|
user['invoiced_ref'] = invoiced_ref
|
|
|
|
invoiced_date = ""
|
|
if ("invoiced_date" in retval.keys()):
|
|
invoiced_date = str(retval['invoiced_date'])[0:10]
|
|
user['invoiced_date'] = invoiced_date
|
|
|
|
|
|
if ("civilite" in retval.keys()):
|
|
user['civilite'] = str(retval['civilite']).strip().lower()
|
|
else:
|
|
user['civilite'] = "neutre"
|
|
|
|
if( str( user['civilite']) not in MYSY_GV.CIVILITE):
|
|
user['civilite'] = "neutre"
|
|
|
|
lms_account_expiration_date = ""
|
|
if ("lms_account_expiration_date" in retval.keys()):
|
|
lms_account_expiration_date = retval['lms_account_expiration_date']
|
|
user['lms_account_expiration_date'] = lms_account_expiration_date
|
|
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in retval.keys()):
|
|
lms_class_code = retval['lms_class_code']
|
|
user['lms_class_code'] = lms_class_code
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in retval.keys()):
|
|
lms_user_id = retval['lms_user_id']
|
|
user['lms_user_id'] = lms_user_id
|
|
|
|
if ("rang" not in retval.keys()):
|
|
user['rang'] = "-"
|
|
else:
|
|
user['rang'] = retval['rang']
|
|
|
|
if ("rang_calculation_date" not in retval.keys()):
|
|
user['rang_calculation_date'] = "-"
|
|
else:
|
|
user['rang_calculation_date'] = retval['rang_calculation_date']
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des stagiaires de la formation"
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction envoie l'email de confirmation d'une inscription a une formation.
|
|
|
|
Ceci est mis en "mode function" pour permettre aux utilisateur de renvoyer
|
|
autant de fois que souhaité la confirmation d'inscription
|
|
"""
|
|
def SendInscriptionConfirmation(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'class_internal_url', '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, "Impossible d'envoyer la confirmation d'inscription"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
|
return False, " Impossible d'envoyer le mail de confirmation"
|
|
|
|
|
|
|
|
data_mail = {}
|
|
# 1 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url':str(diction['class_internal_url'])})
|
|
data_mail['title'] = local_class[0]['title']
|
|
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'session_id':str(diction['session_id']),
|
|
'email':str(diction['email'])})
|
|
local_nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
local_nom = local_inscription[0]['nom']
|
|
data_mail['nom'] = local_nom
|
|
|
|
local_prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
local_prenom = local_inscription[0]['prenom']
|
|
data_mail['prenom'] = local_prenom
|
|
|
|
data_mail['email'] = local_inscription[0]['email']
|
|
|
|
# 3 - Recuperations des info de la session (a distance, formateur, etc)
|
|
local_info_session = MYSY_GV.dbname['session_formation'].find({'_id': ObjectId(str(diction['session_id'])),
|
|
'class_internal_url': str(
|
|
diction['class_internal_url']),
|
|
'valide': '1'})
|
|
|
|
if (local_info_session is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - impossible d'envoyer le mail d'inscription. la session " + str(
|
|
diction['session_id']) + " est introuvable ")
|
|
return False, " impossible d'envoyer le mail d'inscription. la session " + str(
|
|
diction['session_id']) + " est introuvable "
|
|
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_info_session[0].keys()):
|
|
if local_info_session[0]['date_du']:
|
|
date_du = local_info_session[0]['date_du']
|
|
data_mail['date_du'] = str(date_du)[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_info_session[0].keys()):
|
|
if local_info_session[0]['date_au']:
|
|
date_au = local_info_session[0]['date_au']
|
|
data_mail['date_au'] = str(date_au)[0:10]
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_info_session[0].keys()):
|
|
if local_info_session[0]['adresse']:
|
|
adresse = local_info_session[0]['adresse']
|
|
data_mail['adresse'] = adresse
|
|
|
|
session_ondemande = ""
|
|
if ("session_ondemande" in local_info_session[0].keys()):
|
|
if local_info_session[0]['session_ondemande']:
|
|
session_ondemande = local_info_session[0]['session_ondemande']
|
|
data_mail['session_ondemande'] = session_ondemande
|
|
|
|
code_session = ""
|
|
if ("code_session" in local_info_session[0].keys()):
|
|
if local_info_session[0]['code_session']:
|
|
code_session = local_info_session[0]['code_session']
|
|
data_mail['code_session'] = code_session
|
|
|
|
data_mail['partner_owner_recid'] = str(partner_recid)
|
|
|
|
"""
|
|
26/02/2025 :
|
|
Si le paramettre, 'inscription_notification_email' de la collection 'base_partner_setup' est à 1,
|
|
alors on envoie un email de notification à l'apprenant
|
|
"""
|
|
local_insc_status, local_insc_retval = mycommon.Is_Partnair_Inscription_Notification(
|
|
{'token': diction['token']})
|
|
if (local_insc_status and local_insc_retval == "1"):
|
|
local_status, local_message = email_session.incription_training_confirmation_mail(data_mail)
|
|
return local_status, "La confirmation d'inscription a bien ete envoyée"
|
|
else:
|
|
return True, "La notification par email des inscriptions n'est pas activé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'envoyer la confirmation d'inscription"
|
|
|
|
|
|
"""
|
|
Cette fonction envoie les pre-inscritpions
|
|
"""
|
|
def SendPre_InscriptionEmail(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
|
|
field_list_obligatoire = [ 'email', 'session_id', 'inscription_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 d'envoyer la pre-inscription "
|
|
|
|
|
|
data_mail = {}
|
|
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_session = MYSY_GV.dbname['inscription'].find({'session_id':str(diction['session_id']),
|
|
'email':str(diction['email']),
|
|
'_id':ObjectId(str(diction['inscription_id']))})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Impossible de récupérer les information de la session de formation")
|
|
return False, "Impossible de récupérer les information de la session de formation "
|
|
|
|
data_mail['nom'] = local_session[0]['nom']
|
|
data_mail['prenom'] = local_session[0]['prenom']
|
|
data_mail['email'] = local_session[0]['email']
|
|
data_mail['partner_owner_recid'] = local_session[0]['partner_owner_recid']
|
|
|
|
|
|
if ("employeur" in local_session[0].keys()):
|
|
if local_session[0]['employeur']:
|
|
data_mail['employeur'] = local_session[0]['employeur']
|
|
|
|
if ("telephone" in local_session[0].keys()):
|
|
if local_session[0]['telephone']:
|
|
data_mail['telephone'] = local_session[0]['telephone']
|
|
|
|
# 1 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(local_session[0]['class_internal_url']),
|
|
'partner_owner_recid':str(local_session[0]['partner_owner_recid']),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( local_class is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Impossible de récupérer les information de la formation")
|
|
return False, "Impossible de récupérer les information de la formation "
|
|
|
|
|
|
data_mail['title'] = local_class[0]['title']
|
|
partner_recid = local_class[0]['partner_owner_recid']
|
|
|
|
# 1-BIS : Recuperation des donnees de l'editeur de la formation
|
|
local_partner = MYSY_GV.dbname['partnair_account'].find_one({'recid': str(partner_recid)})
|
|
if( local_partner is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Impossible de récupérer les information du partenaire")
|
|
return False, "Impossible de récupérer les information du partenaire "
|
|
|
|
|
|
data_mail['partner_mail'] = local_partner['email']
|
|
|
|
|
|
#3 - Recuperations des info de la session (a distance, formateur, etc)
|
|
local_info_session = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id'])), 'valide':'1'})
|
|
|
|
|
|
|
|
if( local_info_session is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - impossible d'envoyer le mail de presinscription. la session "+str(diction['session_id'])+" est introuvable ")
|
|
return False, " impossible d'envoyer le mail de presinscription. la session "+str(diction['session_id'])+" est introuvable "
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_info_session.keys()):
|
|
if local_info_session['code_postal']:
|
|
code_postal = local_info_session['code_postal']
|
|
data_mail['code_postal'] = code_postal
|
|
|
|
code_session = ""
|
|
if ("code_session" in local_info_session.keys()):
|
|
if local_info_session['code_session']:
|
|
code_session = local_info_session['code_session']
|
|
data_mail['code_session'] = code_postal
|
|
|
|
|
|
date_debut = ""
|
|
if ("date_debut" in local_info_session.keys()):
|
|
if local_info_session['date_debut']:
|
|
date_debut = str(local_info_session['date_debut'])[0:10]
|
|
data_mail['date_du'] = date_debut
|
|
|
|
date_fin = ""
|
|
if ("date_fin" in local_info_session.keys()):
|
|
if local_info_session['date_fin']:
|
|
date_fin = str(local_info_session['date_fin'])[0:10]
|
|
data_mail['date_au'] = date_fin
|
|
|
|
formateur = ""
|
|
if ("formateur_id" in local_info_session.keys()):
|
|
if local_info_session['formateur_id']:
|
|
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(local_info_session['formateur_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_recid':str(local_session[0]['partner_owner_recid'])})
|
|
|
|
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
|
formateur = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
|
|
|
|
data_mail['formateur'] = formateur
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in local_info_session.keys()):
|
|
if local_info_session['distantiel']:
|
|
distantiel = local_info_session['distantiel']
|
|
data_mail['distantiel'] = distantiel
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in local_info_session.keys()):
|
|
if local_info_session['presentiel']:
|
|
presentiel = local_info_session['presentiel']
|
|
data_mail['presentiel'] = presentiel
|
|
|
|
ville = ""
|
|
if ("ville" in local_info_session.keys()):
|
|
if local_info_session['ville']:
|
|
ville = local_info_session['ville']
|
|
data_mail['ville'] = ville
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_info_session.keys()):
|
|
if local_info_session['adresse']:
|
|
adresse = local_info_session['adresse']
|
|
data_mail['adresse'] = adresse
|
|
|
|
session_ondemande = ""
|
|
if ("session_ondemande" in local_info_session.keys()):
|
|
if local_info_session['session_ondemande']:
|
|
session_ondemande = local_info_session['session_ondemande']
|
|
data_mail['session_ondemande'] = session_ondemande
|
|
|
|
|
|
#print(" Pre_incription_training_confirmation_mail DATA = ",data_mail )
|
|
|
|
# Envoi de l'email de confirmation au demandeur de la formation
|
|
"""
|
|
26/02/2025 :
|
|
Si le paramettre, 'inscription_notification_email' de la collection 'base_partner_setup' est à 1,
|
|
alors on envoie un email de notification à l'apprenant
|
|
"""
|
|
local_insc_status, local_insc_retval = mycommon.Is_Partnair_Prenscription_Notification(
|
|
{'token': diction['token']})
|
|
if (local_insc_status and local_insc_retval == "1"):
|
|
local_status, local_message = email_session.Pre_incription_training_confirmation_mail(data_mail)
|
|
|
|
|
|
# Envoi de l'email de notification au formateur
|
|
local_status, local_message = email_session.Notification_partner_Pre_incription_mail(data_mail)
|
|
|
|
return local_status, "La confirmation de la pre-inscription a bien ete envoyé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'envoyer la confirmation d'inscription"
|
|
|
|
|
|
"""
|
|
Cette fonction retour en CSV la liste
|
|
des personnes inscrites à une session de formation
|
|
"""
|
|
def DownloadParticipantsList(diction):
|
|
try:
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = field_list = ['token', 'session_id', 'internal_url']
|
|
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 generer la liste des participants. les informations sont incompletes"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
|
return False, " Impossible de generer la liste des participants. les informations sont incompletes"
|
|
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
internal_url = ""
|
|
if ("internal_url" in diction.keys()):
|
|
if diction['internal_url']:
|
|
internal_url = diction['internal_url']
|
|
|
|
|
|
# Recuperation des données de la session
|
|
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(session_id)), 'class_internal_url':internal_url})
|
|
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cette de formation n'a pas d'informations detaillées ")
|
|
return False, " Cette session de formation n'a pas d'informations detaillées "
|
|
|
|
# Recuperation des données de la formation
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(internal_url)})
|
|
if (local_formation is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cette de formation n'a pas d'informations detaillées (2) ")
|
|
return False, " Cette de formation n'a pas d'informations detaillées (2) "
|
|
|
|
## Recuperation de toutes les stagiaire rattaché à cette session
|
|
coll_session = MYSY_GV.dbname['inscription']
|
|
myquery = {}
|
|
myquery['session_id'] = session_id
|
|
myquery['class_internal_url'] = internal_url
|
|
|
|
|
|
RetObject = []
|
|
|
|
for retval in coll_session.find(myquery, { 'session_id':0}):
|
|
|
|
local_data = {}
|
|
local_data['titre'] = local_formation['title']
|
|
local_data['debut_session'] = local_session ['date_debut']
|
|
local_data['fin_session'] = local_session['date_fin']
|
|
|
|
local_formateur = ""
|
|
if ("formateur" in local_session.keys()):
|
|
if local_session['formateur']:
|
|
local_formateur = local_session['formateur']
|
|
local_data['formateur'] = local_formateur
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in local_session.keys()):
|
|
if local_session['presentiel']:
|
|
presentiel = local_session['presentiel']
|
|
local_data['presentiel'] = presentiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in local_session.keys()):
|
|
if local_session['distantiel']:
|
|
distantiel = local_session['distantiel']
|
|
local_data['distantiel'] = distantiel
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_session.keys()):
|
|
if local_session['adresse']:
|
|
adresse = local_session['adresse']
|
|
local_data['adresse'] = adresse
|
|
|
|
ville = ""
|
|
if ("ville" in local_session.keys()):
|
|
if local_session['ville']:
|
|
ville = local_session['ville']
|
|
local_data['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_session.keys()):
|
|
if local_session['code_postal']:
|
|
code_postal = local_session['code_postal']
|
|
local_data['code_postal'] = code_postal
|
|
|
|
prix_session = ""
|
|
if ("prix_session" in local_session.keys()):
|
|
if local_session['prix_session']:
|
|
prix_session = local_session['prix_session']
|
|
local_data['prix_session'] = prix_session
|
|
|
|
nb_participant = ""
|
|
if ("nb_participant" in local_session.keys()):
|
|
if local_session['nb_participant']:
|
|
nb_participant = local_session['nb_participant']
|
|
local_data['nb_participants'] = nb_participant
|
|
|
|
|
|
|
|
local_data['prenom'] = retval['prenom']
|
|
local_data['nom'] = retval['nom']
|
|
local_data['email'] = retval['email']
|
|
local_data['telephone'] = retval['telephone']
|
|
local_data['date_inscription'] = str(retval['_id'].generation_time.strftime("%m/%d/%Y, %H:%M"))
|
|
|
|
|
|
employeur = ""
|
|
if ("employeur" in retval.keys()):
|
|
if (retval['employeur']):
|
|
employeur = retval['employeur']
|
|
local_data['employeur'] = employeur
|
|
|
|
financement = ""
|
|
if ("modefinancement" in retval.keys()):
|
|
if (retval['modefinancement']):
|
|
financement = retval['modefinancement']
|
|
local_data['financement'] = financement
|
|
|
|
opco = ""
|
|
if ("opco" in retval.keys()):
|
|
if (retval['opco']):
|
|
opco = retval['opco']
|
|
local_data['opco'] = opco
|
|
|
|
if '_id' in local_data:
|
|
del local_data['_id']
|
|
|
|
if( retval['status'] == "1"):
|
|
local_data['status'] = "inscrit"
|
|
|
|
elif (retval['status'] == "0"):
|
|
local_data['status'] = "en attente"
|
|
|
|
elif (retval['status'] == "-1"):
|
|
local_data['status'] = "refusé"
|
|
|
|
if ("inscription_validation_date" in retval.keys()):
|
|
if( retval['inscription_validation_date']):
|
|
local_data['inscription_validation_date'] = str(retval['inscription_validation_date'])[0:10]
|
|
|
|
if ("inscription_refuse_date" in retval.keys()):
|
|
if (retval['inscription_refuse_date']):
|
|
local_data['inscription_refuse_date'] = str(retval['inscription_refuse_date'])[0:10]
|
|
|
|
RetObject.append(local_data)
|
|
|
|
|
|
"""
|
|
/!\ : Quand il n'y a pas encore de stagaire, alors le grid : RetObject : est vide car la boucle precedent est vide
|
|
Donc on retourne juste les infos de la session
|
|
"""
|
|
|
|
print(" ### len(RetObject) = ", len(RetObject) , " RetObject = ", RetObject )
|
|
if(len(RetObject) <= 0 ):
|
|
local_data = {}
|
|
local_data['titre_formation'] = local_formation['title']
|
|
local_data['debut_session'] = local_session['date_debut']
|
|
local_data['fin_session'] = local_session['date_fin']
|
|
|
|
local_formateur = ""
|
|
if ("formateur" in local_session.keys()):
|
|
if local_session['formateur']:
|
|
local_formateur = local_session['formateur']
|
|
local_data['formateur'] = local_formateur
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in local_session.keys()):
|
|
if local_session['presentiel']:
|
|
local_formateur = local_session['presentiel']
|
|
local_data['presentiel'] = presentiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in local_session.keys()):
|
|
if local_session['distantiel']:
|
|
distantiel = local_session['distantiel']
|
|
local_data['distantiel'] = distantiel
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_session.keys()):
|
|
if local_session['adresse']:
|
|
adresse = local_session['adresse']
|
|
local_data['adresse'] = adresse
|
|
|
|
ville = ""
|
|
if ("ville" in local_session.keys()):
|
|
if local_session['ville']:
|
|
ville = local_session['ville']
|
|
local_data['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_session.keys()):
|
|
if local_session['code_postal']:
|
|
code_postal = local_session['code_postal']
|
|
local_data['code_postal'] = code_postal
|
|
|
|
prix_session = ""
|
|
if ("prix_session" in local_session.keys()):
|
|
if local_session['prix_session']:
|
|
prix_session = local_session['prix_session']
|
|
local_data['prix_session'] = prix_session
|
|
|
|
nb_participant = ""
|
|
if ("nb_participant" in local_session.keys()):
|
|
if local_session['nb_participant']:
|
|
nb_participant = local_session['nb_participant']
|
|
local_data['nb_participants'] = nb_participant
|
|
|
|
local_data['nb_inscrit'] = "0"
|
|
|
|
RetObject.append(local_data)
|
|
|
|
# Expand the cursor and construct the DataFrame
|
|
df = pd.DataFrame(list(RetObject))
|
|
|
|
file_name_tmp = mycommon.create_token_urlsafe()
|
|
file_name = ''.join(char for char in file_name_tmp if char.isalnum())
|
|
|
|
#print("#### filename = "+str(file_name))
|
|
|
|
df.to_excel(MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx", index=False)
|
|
if os.path.exists(MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx"):
|
|
path = MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx"
|
|
return True, send_file(path, as_attachment=True)
|
|
else:
|
|
return False, False
|
|
|
|
|
|
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'envoyer la confirmation d'inscription"
|
|
|
|
|
|
"""
|
|
Cette fonction imprime au formation csv la liste des evaluations d'une formation
|
|
"""
|
|
def DownloadEvaluationList(diction):
|
|
try:
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'session_id', 'internal_url']
|
|
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 generer la liste des participants. les informations sont incompletes"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
|
return False, " Impossible de generer la liste des participants. les informations sont incompletes"
|
|
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
internal_url = ""
|
|
if ("internal_url" in diction.keys()):
|
|
if diction['internal_url']:
|
|
internal_url = diction['internal_url']
|
|
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(session_id)), 'class_internal_url':internal_url})
|
|
|
|
|
|
if (local_session 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 "
|
|
|
|
# Recuperation des données de la formation
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(internal_url)})
|
|
if (local_formation is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cette de formation n'a pas d'informations detaillées (2) ")
|
|
return False, " Cette de formation n'a pas d'informations detaillées (2) "
|
|
|
|
## Recuperation de toutes les stagiaire rattaché à cette session
|
|
coll_session = MYSY_GV.dbname['inscription']
|
|
myquery = {}
|
|
myquery['session_id'] = session_id
|
|
myquery['class_internal_url'] = internal_url
|
|
myquery['status'] = "1"
|
|
|
|
|
|
RetObject = []
|
|
|
|
for retval in coll_session.find(myquery, { 'session_id':0}):
|
|
|
|
local_data = {}
|
|
local_data['titre'] = local_formation['title']
|
|
local_data['code_session'] = local_session['code_session']
|
|
titre_session = ""
|
|
if( "titre" in local_session.keys() ):
|
|
titre_session = local_session['titre']
|
|
local_data['titre_session'] = titre_session
|
|
|
|
nb_participants = ""
|
|
if ("nb_participant" in local_session.keys()):
|
|
nb_participants = local_session['nb_participant']
|
|
local_data['nb_participant'] = nb_participants
|
|
|
|
|
|
local_data['debut_session'] = local_session ['date_debut']
|
|
local_data['fin_session'] = local_session['date_fin']
|
|
|
|
|
|
|
|
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 local_session.keys() and local_session['formateur_id']):
|
|
|
|
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(local_session['formateur_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_recid': str(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'])
|
|
|
|
local_data['formateur'] = formateur_nom_prenom
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in local_session.keys()):
|
|
if local_session['presentiel']:
|
|
presentiel = local_session['presentiel']
|
|
local_data['presentiel'] = presentiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in local_session.keys()):
|
|
if local_session['distantiel']:
|
|
distantiel = local_session['distantiel']
|
|
local_data['distantiel'] = distantiel
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_session.keys()):
|
|
if local_session['adresse']:
|
|
adresse = local_session['adresse']
|
|
local_data['adresse'] = adresse
|
|
|
|
ville = ""
|
|
if ("ville" in local_session.keys()):
|
|
if local_session['ville']:
|
|
ville = local_session['ville']
|
|
local_data['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_session.keys()):
|
|
if local_session['code_postal']:
|
|
code_postal = local_session['code_postal']
|
|
local_data['code_postal'] = code_postal
|
|
|
|
|
|
|
|
local_data['prenom'] = retval['prenom']
|
|
local_data['nom'] = retval['nom']
|
|
local_data['email'] = retval['email']
|
|
local_data['telephone'] = retval['telephone']
|
|
local_data['date_inscription'] = str(retval['_id'].generation_time.strftime("%m/%d/%Y, %H:%M"))
|
|
|
|
eval_date = ""
|
|
if ("eval_date" in retval.keys()):
|
|
eval_date = retval['eval_date']
|
|
local_data['evaluation_date'] = str(eval_date)[0:10]
|
|
|
|
date_demande_eval = ""
|
|
if ("date_demande_eval" in retval.keys()):
|
|
date_demande_eval = retval['date_demande_eval']
|
|
local_data['date_demande_eval'] = str(date_demande_eval)[0:10]
|
|
|
|
|
|
|
|
eval_note = ""
|
|
if ("eval_note" in retval.keys()):
|
|
eval_note = retval['eval_note']
|
|
local_data['evaluation_globale'] = eval_note
|
|
|
|
eval_pedagogie = ""
|
|
if ("eval_pedagogie" in retval.keys()):
|
|
eval_pedagogie = retval['eval_pedagogie']
|
|
local_data['evaluation_pedagogie'] = eval_pedagogie
|
|
|
|
eval_eval = ""
|
|
if ("eval_eval" in retval.keys()):
|
|
eval_eval = retval['eval_eval']
|
|
local_data['evaluation_commentaire'] = mycommon.cleanhtml(str(eval_eval))
|
|
|
|
|
|
if ("inscription_validation_date" in retval.keys()):
|
|
if( retval['inscription_validation_date']):
|
|
local_data['inscription_validation_date'] = str(retval['inscription_validation_date'])[0:10]
|
|
|
|
|
|
RetObject.append(local_data)
|
|
|
|
|
|
"""
|
|
/!\ : Quand il n'y a pas encore de stagaire, alors le grid : RetObject : est vide car la boucle precedent est vide
|
|
Donc on retourne juste les infos de la session
|
|
"""
|
|
|
|
print(" ### len(RetObject) = ", len(RetObject) , " RetObject = ", RetObject )
|
|
if(len(RetObject) <= 0 ):
|
|
local_data = {}
|
|
local_data['titre_formation'] = local_formation['title']
|
|
local_data['debut_session'] = local_session['date_debut']
|
|
local_data['fin_session'] = local_session['date_fin']
|
|
|
|
local_formateur = ""
|
|
if ("formateur" in local_session.keys()):
|
|
if local_session['formateur']:
|
|
local_formateur = local_session['formateur']
|
|
local_data['formateur'] = local_formateur
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in local_session.keys()):
|
|
if local_session['presentiel']:
|
|
local_formateur = local_session['presentiel']
|
|
local_data['presentiel'] = presentiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in local_session.keys()):
|
|
if local_session['distantiel']:
|
|
distantiel = local_session['distantiel']
|
|
local_data['distantiel'] = distantiel
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_session.keys()):
|
|
if local_session['adresse']:
|
|
adresse = local_session['adresse']
|
|
local_data['adresse'] = adresse
|
|
|
|
ville = ""
|
|
if ("ville" in local_session.keys()):
|
|
if local_session['ville']:
|
|
ville = local_session['ville']
|
|
local_data['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_session.keys()):
|
|
if local_session['code_postal']:
|
|
code_postal = local_session['code_postal']
|
|
local_data['code_postal'] = code_postal
|
|
|
|
prix_session = ""
|
|
if ("prix_session" in local_session.keys()):
|
|
if local_session['prix_session']:
|
|
prix_session = local_session['prix_session']
|
|
local_data['prix_session'] = prix_session
|
|
|
|
nb_participant = ""
|
|
if ("nb_participant" in local_session.keys()):
|
|
if local_session['nb_participant']:
|
|
nb_participant = local_session['nb_participant']
|
|
local_data['nb_participants'] = nb_participant
|
|
|
|
local_data['nb_inscrit'] = "0"
|
|
|
|
RetObject.append(local_data)
|
|
|
|
# Expand the cursor and construct the DataFrame
|
|
df = pd.DataFrame(list(RetObject))
|
|
|
|
file_name_tmp = mycommon.create_token_urlsafe()
|
|
file_name = ''.join(char for char in file_name_tmp if char.isalnum())
|
|
|
|
#print("#### filename = "+str(file_name))
|
|
|
|
df.to_excel(MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx", index=False)
|
|
if os.path.exists(MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx"):
|
|
path = MYSY_GV.TEMPORARY_DIRECTORY+"/"+str(file_name)+".xlsx"
|
|
return True, send_file(path, as_attachment=True)
|
|
else:
|
|
return False, False
|
|
|
|
|
|
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'envoyer la confirmation d'inscription"
|
|
|
|
|
|
|
|
""" Import des inscriptions en masse
|
|
Avec l'import d'un fichier csv
|
|
"""
|
|
def AddStagiairetoClass_mass(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', 'session_id', 'class_internal_url']
|
|
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, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
'''
|
|
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', 'session_id', 'class_internal_url']
|
|
|
|
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']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token': str(diction['token'])})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
|
|
## Verification de l'existance de session et recuperation du "code_session"
|
|
session_count = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'class_internal_url': str(class_internal_url), 'valide': '1',
|
|
'_id': ObjectId(str(session_id)), 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if (session_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(session_id) + " : ' Cette session n'est pas valide ")
|
|
return False, " Code de la session de formation n'est pas valide "
|
|
|
|
if (session_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(session_id) + " : ' Cette session existe en double ")
|
|
return False, " Les données de la session de formation sont incohérentes "
|
|
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'class_internal_url': str(class_internal_url), 'valide': '1',
|
|
'_id': ObjectId(str(session_id)), 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if( "code_session" not in session_data.keys() ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Cette session de formation n'a pas de code_session ")
|
|
return False, " Cette session de formation n'a pas de code_session "
|
|
|
|
|
|
code_session = session_data['code_session']
|
|
|
|
# Verification de l'existance de la formation (class_internal_url)
|
|
tmp_count = MYSY_GV.dbname['myclass'].count_documents({'internal_url': str(class_internal_url), 'valide': '1',
|
|
'locked':'0', 'partner_owner_recid':str(partner_recid)})
|
|
|
|
# logging.info(" TMP = "+str(tmp))
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(class_internal_url) + " : ' Cette formation n'est pas valide ")
|
|
return False, " Cette formation n'est pas valide "
|
|
|
|
MyClass_Data = MYSY_GV.dbname['myclass'].find_one({'internal_url': str(class_internal_url), 'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(partner_recid)})
|
|
|
|
if( "external_code" not in MyClass_Data.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(class_internal_url) + " : ' Cette formation n'est pas valide (2)")
|
|
return False, " Cette formation n'est pas valide (2)"
|
|
|
|
MyClass_external_code = MyClass_Data['external_code']
|
|
|
|
|
|
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 31/08/23 : Controle de l'integrité du fichier avant import
|
|
"""
|
|
local_controle_status, local_controle_message = Controle_AddStagiairetoClass_mass(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 = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
|
'telephone', 'email', 'modefinancement','opco', 'status', 'prix', 'adresse', 'code_postal', 'ville',
|
|
'pays', 'client_rattachement_email', 'client_rattachement_nom', 'type_apprenant', 'civilite']
|
|
|
|
|
|
# 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)
|
|
for val in df.columns:
|
|
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 = ['prenom', 'nom', 'email', 'modefinancement', 'status', 'prix']
|
|
|
|
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)
|
|
"""
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
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['employeur'] = str(df['employeur'].values[n])
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['email'] = str(df['email'].values[n]).strip()
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]).strip() )):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email " + str(df['email'].values[n]).strip() + " est invalide")
|
|
return False, " l'adresse email -" + str(df['email'].values[n]).strip() + "- est invalide"
|
|
|
|
|
|
mydata['session_id'] = str(session_data['_id'])
|
|
mydata['token'] = str(my_token)
|
|
|
|
modefinancement = ""
|
|
if ("modefinancement" in df.keys()):
|
|
if (str(df['modefinancement'].values[n])):
|
|
modefinancement = str(df['modefinancement'].values[n])
|
|
mydata['modefinancement'] = modefinancement
|
|
|
|
formation_code_externe = ""
|
|
if ("formation_code_externe" in df.keys()):
|
|
if (str(df['formation_code_externe'].values[n])):
|
|
formation_code_externe = str(df['formation_code_externe'].values[n]).strip()
|
|
|
|
if( str(formation_code_externe).lower() != str(MyClass_external_code).lower()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Le code externe de la formation" + str(df['formation_code_externe'].values[n]) + " ne correspond pas la formation en cours")
|
|
return False, " Le code externe de la formation" + str(df['formation_code_externe'].values[n]) + " ne correspond pas la formation en cours"
|
|
|
|
local_code_session = ""
|
|
if ("code_session" in df.keys()):
|
|
if (str(df['code_session'].values[n])):
|
|
local_code_session = str(df['code_session'].values[n]).strip()
|
|
|
|
if (str(local_code_session).lower() != str(code_session).lower()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Le code session de la formation" + str(
|
|
df['code_session'].values[n]) + " ne correspond pas au code de la session en cours")
|
|
return False, " Le code externer de la formation" + str(
|
|
df['code_session'].values[n]) + " ne correspond pas au code de la session en cours"
|
|
|
|
opco = ""
|
|
if ("opco" in df.keys()):
|
|
if (str(df['opco'].values[n])):
|
|
opco = str(df['opco'].values[n])
|
|
mydata['opco'] = opco
|
|
|
|
# Verifier que le type d'apprenant est bien valide
|
|
type_apprenant = "0"
|
|
if ("type_apprenant" in df.keys()):
|
|
if (str(df['type_apprenant'].values[n])):
|
|
type_apprenant = str(df['type_apprenant'].values[n])
|
|
mydata['type_apprenant'] = type_apprenant
|
|
|
|
|
|
|
|
|
|
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( 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)
|
|
|
|
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])
|
|
|
|
if ("." in str(code_postal)):
|
|
# /!\ : l'utilisateur envoie un code poster au format entier, plutot que string.
|
|
code_postal = str(code_postal).split(".")[0]
|
|
elif ("." in str(code_postal)):
|
|
# /!\ : l'utilisateur envoie un code poster au format entier, plutot que string.
|
|
code_postal = str(code_postal).split(",")[0]
|
|
else:
|
|
code_postal = str(code_postal)
|
|
|
|
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
|
|
|
|
|
|
""""
|
|
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() and str(df['client_rattachement_nom'].values[n]) != "nan"):
|
|
if (str(df['client_rattachement_nom'].values[n])):
|
|
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_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) +". Plusieurs clients correspondent aux critère de nom :"+str(client_rattachement_nom)+" et email : "+str(client_rattachement_email))
|
|
return False, "Ligne : "+str(n) +". 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) +". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : "+str(n) +". 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'])
|
|
|
|
status = str(df['status'].values[n]).strip()
|
|
status = str(mycommon.tryInt(status))
|
|
|
|
if (str(status) != "0" and str(status) != "1" and str(status) != "2"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'status' de la ligne " + str(
|
|
n) + " est incorrecte. Valeurs acceptées : 0,1,2")
|
|
return False, " Le champ status de la ligne " + str(n) + " est incorrecte. Valeurs acceptées : 0,1,2"
|
|
|
|
mydata['status'] = str(df['status'].values[n]).strip()
|
|
if (status == "1"):
|
|
mydata['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
|
|
mydata['class_internal_url'] = str(class_internal_url)
|
|
|
|
|
|
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) + " est incorrecte.")
|
|
return False, " Le champ prix de la ligne " + str(n) + " est incorrecte. "
|
|
|
|
mydata['price'] = local_price
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
print( "#### clean_dict 02 ", clean_dict)
|
|
status, retval = AddStagiairetoClass(clean_dict)
|
|
|
|
if( status is False ):
|
|
return status, retval
|
|
|
|
print(str(total_rows)+" participants ont été inserés")
|
|
|
|
return True, str(total_rows)+" participants ont été inserés / 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 d'importer les participants en masse "
|
|
|
|
|
|
"""
|
|
Controle du fichier à importer avant import
|
|
"""
|
|
|
|
def Controle_AddStagiairetoClass_mass(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', 'session_id', 'class_internal_url']
|
|
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, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
'''
|
|
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', 'session_id', 'class_internal_url']
|
|
|
|
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']
|
|
|
|
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"
|
|
|
|
# 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"
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
# Verification de l'existance de la session
|
|
## Verification de l'existance de session et recuperation du "code_session"
|
|
session_count = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'class_internal_url': str(class_internal_url), 'valide': '1',
|
|
'_id': ObjectId(str(session_id)), 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if (session_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(session_id) + " : ' Cette session n'est pas valide ")
|
|
return False, " Code de la session de formation n'est pas valide "
|
|
|
|
if (session_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(session_id) + " : ' Cette session existe en double ")
|
|
return False, " Les données de la session de formation sont incohérentes "
|
|
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'class_internal_url': str(class_internal_url), 'valide': '1',
|
|
'_id': ObjectId(str(session_id)), 'partner_owner_recid': str(partner_recid)})
|
|
|
|
if ("code_session" not in session_data.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Cette session de formation n'a pas de code_session ")
|
|
return False, " Cette session de formation n'a pas de code_session "
|
|
|
|
code_session = session_data['code_session']
|
|
|
|
# Verification de l'existance de la formation (class_internal_url)
|
|
tmp_count = MYSY_GV.dbname['myclass'].count_documents({'internal_url': str(class_internal_url), 'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(partner_recid)})
|
|
|
|
# logging.info(" TMP = "+str(tmp))
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(class_internal_url) + " : ' Cette formation n'est pas valide ")
|
|
return False, " Cette formation n'est pas valide "
|
|
|
|
MyClass_Data = MYSY_GV.dbname['myclass'].find_one({'internal_url': str(class_internal_url), 'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(partner_recid)})
|
|
|
|
if ("external_code" not in MyClass_Data.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " -" + str(
|
|
class_internal_url) + " : ' Cette formation n'est pas valide (2)")
|
|
return False, " Cette formation n'est pas valide (2)"
|
|
|
|
MyClass_external_code = MyClass_Data['external_code']
|
|
|
|
|
|
# " Lecture du fichier "
|
|
# print(" Lecture du fichier : "+saved_file)
|
|
nb_line = 0
|
|
|
|
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 = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
|
'telephone', 'email', 'modefinancement', 'opco', 'status', 'prix', 'adresse', 'code_postal',
|
|
'ville',
|
|
'pays', 'client_rattachement_email', 'client_rattachement_nom', 'type_apprenant', 'civilite']
|
|
|
|
# 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)
|
|
for val in df.columns:
|
|
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 = ['prenom', 'nom', 'email', 'modefinancement', 'status', 'prix']
|
|
|
|
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)
|
|
"""
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
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['employeur'] = str(df['employeur'].values[n])
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['email'] = str(df['email'].values[n]).strip()
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]).strip() )):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email " + str(df['email'].values[n]).strip() + " est invalide")
|
|
return False, " l'adresse email -" + str(df['email'].values[n]).strip() + "- est invalide"
|
|
|
|
mydata['session_id'] = str(session_data['_id'])
|
|
mydata['token'] = str(my_token)
|
|
|
|
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 (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)
|
|
|
|
|
|
modefinancement = ""
|
|
if ("modefinancement" in df.keys()):
|
|
if (str(df['modefinancement'].values[n])):
|
|
modefinancement = str(df['modefinancement'].values[n])
|
|
mydata['modefinancement'] = modefinancement
|
|
|
|
formation_code_externe = ""
|
|
if ("formation_code_externe" in df.keys()):
|
|
if (str(df['formation_code_externe'].values[n])):
|
|
formation_code_externe = str(df['formation_code_externe'].values[n]).strip()
|
|
|
|
if (str(formation_code_externe).lower() != str(MyClass_external_code).lower()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Le code externe de la formation" + str(
|
|
df['formation_code_externe'].values[
|
|
n]) + " ne correspond pas la formation en cours")
|
|
return False, " Le code externe de la formation" + str(
|
|
df['formation_code_externe'].values[n]) + " ne correspond pas la formation en cours"
|
|
|
|
local_code_session = ""
|
|
if ("code_session" in df.keys()):
|
|
if (str(df['code_session'].values[n])):
|
|
local_code_session = str(df['code_session'].values[n]).strip()
|
|
|
|
if (str(local_code_session).lower() != str(code_session).lower()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Le code session de la formation" + str(
|
|
df['code_session'].values[n]) + " ne correspond pas au code de la session en cours")
|
|
return False, " Le code externer de la formation" + str(
|
|
df['code_session'].values[n]) + " ne correspond pas au code de la session en cours"
|
|
|
|
opco = ""
|
|
if ("opco" in df.keys()):
|
|
if (str(df['opco'].values[n])):
|
|
opco = str(df['opco'].values[n])
|
|
mydata['opco'] = opco
|
|
|
|
# Verifier que le type d'apprenant est bien valide
|
|
type_apprenant = "0"
|
|
if ("type_apprenant" in df.keys()):
|
|
if (str(df['type_apprenant'].values[n])):
|
|
type_apprenant = str(df['type_apprenant'].values[n])
|
|
mydata['type_apprenant'] = type_apprenant
|
|
|
|
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]).strip()
|
|
|
|
if ("." in str(code_postal)):
|
|
# /!\ : l'utilisateur envoie un code poster au format entier, plutot que string.
|
|
code_postal = str(code_postal).split(".")[0]
|
|
elif ("." in str(code_postal)):
|
|
# /!\ : l'utilisateur envoie un code poster au format entier, plutot que string.
|
|
code_postal = str(code_postal).split(",")[0]
|
|
else:
|
|
code_postal = str(code_postal)
|
|
|
|
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
|
|
|
|
""""
|
|
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])
|
|
|
|
client_rattachement_nom = ""
|
|
if ("client_rattachement_nom" in df.keys() and str(df['client_rattachement_nom'].values[n]) != "nan"):
|
|
if (str(df['client_rattachement_nom'].values[n])):
|
|
client_rattachement_nom = str(df['client_rattachement_nom'].values[n])
|
|
|
|
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_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) + ". Plusieurs clients correspondent aux critère de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : " + str(
|
|
n) + ". 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) + ". Aucun client ne repond aux critères de nom :" + str(
|
|
client_rattachement_nom) + " et email : " + str(client_rattachement_email))
|
|
return False, "Ligne : " + str(n) + ". 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'])
|
|
|
|
|
|
status = str(df['status'].values[n]).strip()
|
|
status = str(mycommon.tryInt(status))
|
|
|
|
|
|
if (str(status) != "0" and str(status) != "1" and str(status) != "2"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'status' de la ligne " + str(
|
|
n) + " est incorrecte. Valeurs acceptées : 0,1,2")
|
|
return False, " Le champ status de la ligne " + str(
|
|
n) + " est incorrecte. Valeurs acceptées : 0,1,2"
|
|
|
|
mydata['status'] = status
|
|
|
|
|
|
if (str(status).strip() == "1"):
|
|
mydata['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
mydata['class_internal_url'] = str(class_internal_url)
|
|
|
|
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) + " est incorrecte.")
|
|
return False, " Le champ prix de la ligne " + str(n) + " est incorrecte. "
|
|
|
|
mydata['price'] = local_price
|
|
|
|
## Verifier que le stagiaire n'est pas deja inscrit à cette formation.
|
|
qry_count = {'email': str(mydata['email']), 'session_id': str(session_id), 'partner_owner_recid':str(partner_recid) }
|
|
qry_count_result = MYSY_GV.dbname['inscription'].count_documents(qry_count)
|
|
|
|
if( qry_count_result > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne " + str(n) + " : L'adresse email "+str()+" est déjà inscrite à la session :"+str(code_session)+". ")
|
|
return False, " Ligne " + str(n) + " : L'adresse email "+str(mydata['email'])+" est déjà inscrite à la session de formation :"+str(code_session)+". "
|
|
|
|
|
|
|
|
return True, str(total_rows) + " participants lus dans le fichier excel"
|
|
|
|
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 "
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'importer un fichier excel pour les stagiaire de plusieurs session, plusieurs formations
|
|
/!\ : Controle session : on va utiliser les colonne : formation code externe et le code de la session
|
|
/!\ : controle du client : on va utiliser le mail et le nom du client pour voir si ca concorde.
|
|
|
|
update du 21/08/23 :
|
|
Pour eviter les imports partiels du fichier, on va créer une fonction qui va faire les controles.
|
|
Si cette fonction est ok, alors on lance la fonction d'import.
|
|
|
|
Elle fera a peu pret les meme controle qui existe dans la fonction d'import actuelle.
|
|
|
|
18/04/25 :
|
|
dans les arguments, 'session_id' sera fourni en option. Si cette dernière est fourni, alors il faudrait
|
|
obligatoirement s'assurer que le conteu du fichier excel correspond exclusivement a cette session
|
|
|
|
"""
|
|
def AddStagiairetoClass_mass_for_many_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', '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"
|
|
|
|
|
|
"""
|
|
Si le champ 'session_id' est fourni, alors il faut s'assurer que l'import ne se fait exclusivement
|
|
pour la session indiquée
|
|
"""
|
|
|
|
local_session_id = None
|
|
local_session_id_data = None
|
|
|
|
if( "session_id"in diction.keys() and diction['session_id']):
|
|
local_session_id = diction['session_id']
|
|
local_session_id_count = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(local_session_id)),
|
|
'valide':'1',
|
|
'partner_owner_recid':partner_recid})
|
|
|
|
if( local_session_id_count != 1):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " L'identifiant de la session de formation est invalide ")
|
|
return False, " L'identifiant de la session de formation est invalide"
|
|
|
|
local_session_id_data = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(local_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 21/08/23 : Controle de l'integrité du fichier
|
|
"""
|
|
local_controle_status, local_controle_message = Controle_AddStagiairetoClass_mass_for_many_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 = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
|
'telephone', 'email', 'modefinancement', 'opco', 'status', 'prix', 'adresse', 'code_postal',
|
|
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom','facture_client_rattachement_email',
|
|
'facture_client_rattachement_nom', 'civilite', 'type_apprenant']
|
|
|
|
|
|
# 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)
|
|
for val in df.columns:
|
|
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 = ['prenom', 'nom', 'email', 'modefinancement', 'status', 'prix']
|
|
|
|
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)
|
|
"""
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
|
|
"""
|
|
18/04/25 :
|
|
dans les arguments, 'session_id' sera fourni en option. Si cette dernière est fourni, alors il faudrait
|
|
obligatoirement s'assurer que le conteu du fichier excel correspond exclusivement a cette session
|
|
"""
|
|
if( local_session_id_data and "code_session" in local_session_id_data.keys() ):
|
|
if( str(local_session_id_data['code_session']).lower() != str(df['code_session'].values[n]).lower() ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ligne " + str(n + 2) + " : Le code session '"+str(df['code_session'].values[n]) +"' ne correspond pas à la session selectionnée : '"+str(local_session_id_data['code_session'])+"' ")
|
|
return False, " Ligne " + str(n + 2) + " : Le code session '"+str(df['code_session'].values[n]) +"' ne correspond pas à la session selectionnée : '"+str(local_session_id_data['code_session'])+"' "
|
|
|
|
|
|
mydata = {}
|
|
class_external_code = str(df['formation_code_externe'].values[n])
|
|
#mydata['code_session'] = str(df['code_session'].values[n])
|
|
mydata['prenom'] = str(df['prenom'].values[n]).strip()
|
|
mydata['nom'] = str(df['nom'].values[n]).strip()
|
|
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['employeur'] = str(df['employeur'].values[n]).strip()
|
|
mydata['telephone'] = str(df['telephone'].values[n]).strip()
|
|
mydata['email'] = str(df['email'].values[n]).strip().strip()
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]).strip() )):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email " + str(df['email'].values[n]).strip() + " est invalide")
|
|
return False, " l'adresse email -" + str(df['email'].values[n]).strip() + "- est invalide"
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
"""
|
|
Recuperation de l'internal url de la formation a partir de la cle
|
|
- formation code externe
|
|
- partner_owner_recid
|
|
"""
|
|
qry = {'external_code':str(class_external_code), 'valide':'1', 'locked':'0', 'partner_owner_recid':str(partner_recid)}
|
|
|
|
myclass_data_count = MYSY_GV.dbname['myclass'].count_documents({'external_code':str(class_external_code), 'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':str(partner_recid)})
|
|
|
|
if( myclass_data_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas .")
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas."
|
|
|
|
|
|
myclass_data = MYSY_GV.dbname['myclass'].find_one({'external_code':str(class_external_code), 'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':str(partner_recid)})
|
|
|
|
mysession_count_qry = {'class_internal_url': str(myclass_data['internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(partner_recid), 'code_session':str(df['code_session'].values[n]) }
|
|
|
|
|
|
|
|
mysession_count = MYSY_GV.dbname['session_formation'].count_documents(mysession_count_qry)
|
|
|
|
if( mysession_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas (2).")
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas (2)."
|
|
|
|
mysession_data = MYSY_GV.dbname['session_formation'].find_one(mysession_count_qry)
|
|
|
|
|
|
|
|
mydata['session_id'] = str(mysession_data['_id'])
|
|
mydata['class_internal_url'] = str(mysession_data['class_internal_url'])
|
|
"""
|
|
Recuperation de l''_id' de la session à partir de la clé
|
|
- formation code externe
|
|
- code_session
|
|
- partner_owner_recid
|
|
"""
|
|
|
|
"""
|
|
On verifie que le code de le session et le l'external class code correspondent.
|
|
En gros : que la formation en question a bien une session du meme code
|
|
"""
|
|
|
|
|
|
"""check_class_session_query = [{'$match': {'code_session':str(df['code_session'].values[n])}},
|
|
{'$lookup':
|
|
{
|
|
'from': 'myclass',
|
|
'localField': 'class_internal_url',
|
|
'foreignField': 'internal_url',
|
|
'pipeline': [{'$match': {'external_code':str(df['formation_code_externe'].values[n])}},
|
|
{'$project': {'title': 1, }}],
|
|
'as': 'myclass_collection'
|
|
}
|
|
}
|
|
]
|
|
|
|
print(" ##### myquery GetSessionFormation = " + str(check_class_session_query))
|
|
|
|
real_class_internal_url = ""
|
|
|
|
for check_class_session_retval in MYSY_GV.dbname['session_formation'].aggregate(check_class_session_query):
|
|
if ('myclass_collection' in check_class_session_retval.keys() and len(check_class_session_retval['myclass_collection']) > 0):
|
|
real_class_internal_url = check_class_session_retval['class_internal_url']
|
|
|
|
if( str(real_class_internal_url) == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n+2) + ": Le code externe de la formation et le code de la session ne correspondent pas .")
|
|
return False, "Ligne : " + str(n+2) + ": Le code externe de la formation et le code de la session ne correspondent pas."
|
|
"""
|
|
|
|
|
|
|
|
|
|
modefinancement = ""
|
|
if ("modefinancement" in df.keys()):
|
|
if (str(df['modefinancement'].values[n])):
|
|
modefinancement = str(df['modefinancement'].values[n]).strip()
|
|
mydata['modefinancement'] = modefinancement
|
|
|
|
|
|
opco = ""
|
|
if ("opco" in df.keys()):
|
|
if (str(df['opco'].values[n])):
|
|
opco = str(df['opco'].values[n]).strip()
|
|
mydata['opco'] = opco
|
|
|
|
adresse = ""
|
|
if ("adresse" in df.keys()):
|
|
if (str(df['adresse'].values[n])):
|
|
adresse = str(df['adresse'].values[n]).strip()
|
|
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]).strip()
|
|
mydata['code_postal'] = code_postal
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n]).strip()
|
|
mydata['ville'] = ville
|
|
|
|
pays = ""
|
|
if ("pays" in df.keys()):
|
|
if (str(df['pays'].values[n])):
|
|
pays = str(df['pays'].values[n]).strip()
|
|
mydata['pays'] = pays
|
|
|
|
|
|
""""
|
|
Gestion du client de rattachement/
|
|
Avec l'email et le nom, on va aller récupérer l'_id du client
|
|
"""
|
|
has_client_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_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'])
|
|
has_client_client = str(local_client_retval_data['_id'])
|
|
|
|
# /!\ : Par defaut, ont que le client de facturation = au client principale. comme ca
|
|
# Si il y un client de facturation plus bas, on l'ecrase
|
|
mydata['facture_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
|
|
|
|
|
|
"""
|
|
has_client_facture = ""
|
|
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_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'])
|
|
has_client_facture = str(local_client_retval_data['_id'])
|
|
|
|
"""
|
|
11/07/2024 - /!\ Si je n'ai pas de client facturé mais que j'ai un client (classique),
|
|
alors on fait : client_facturé = client_normal
|
|
"""
|
|
if( len(str(has_client_facture).strip()) <= 1 and len(str(has_client_client).strip()) > 3 ):
|
|
mydata['facture_client_rattachement_id'] = str(has_client_client)
|
|
|
|
|
|
"""
|
|
11/07/2024 - /!\ Si j'ai un client facturé, mais pas un client normal, alors on fait :
|
|
client_client = client_facture
|
|
"""
|
|
if (len(str(has_client_client).strip()) <= 1 and len(str(has_client_facture).strip()) > 3):
|
|
mydata['client_rattachement_id'] = str(has_client_facture)
|
|
|
|
|
|
mydata['status'] = str(df['status'].values[n]).strip()
|
|
if( str(mydata['status']) != "0" and str(mydata['status']) != "1" and str(mydata['status']) != "2"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'status' de la ligne " + str(n) + " est incorrecte. Valeurs acceptées : 0,1,2")
|
|
return False, " Le champ status de la ligne " + str(n) + " est incorrecte. Valeurs acceptées : 0,1,2"
|
|
|
|
|
|
if( str(df['status'].values[n]).strip() == "1"):
|
|
mydata['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
print( "#### clean_dict tt 01 ", clean_dict)
|
|
status, retval = AddStagiairetoClass(clean_dict)
|
|
|
|
if( status is False ):
|
|
return status, retval
|
|
|
|
print(str(total_rows)+" participants ont été inserés")
|
|
|
|
return True, str(total_rows)+" participants ont été inserées / 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))
|
|
return False, "Impossible d'importer les participants en masse "
|
|
|
|
|
|
|
|
"""
|
|
Fonction de controle du fichier
|
|
"""
|
|
def Controle_AddStagiairetoClass_mass_for_many_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','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 = ['formation_code_externe', 'code_session', 'prenom', 'nom', 'employeur',
|
|
'telephone', 'email', 'modefinancement', 'opco', 'status', 'prix', 'adresse', 'code_postal',
|
|
'ville', 'pays', 'client_rattachement_email', 'client_rattachement_nom',
|
|
'facture_client_rattachement_email', 'facture_client_rattachement_nom', 'civilite', 'type_apprenant']
|
|
|
|
|
|
# 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 = ['prenom', 'nom', 'email', 'modefinancement', 'status', 'prix']
|
|
|
|
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)
|
|
"""
|
|
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
class_external_code = str(df['formation_code_externe'].values[n])
|
|
#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['employeur'] = str(df['employeur'].values[n])
|
|
mydata['telephone'] = str(df['telephone'].values[n])
|
|
mydata['email'] = str(df['email'].values[n]).strip()
|
|
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]) + " l'adresse email " + str(mydata['email']) + " est invalide")
|
|
return False, " l'adresse email -" + str(mydata['email']) + "- est invalide"
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
"""
|
|
Recuperation de l'internal url de la formation a partir de la cle
|
|
- formation code externe
|
|
- partner_owner_recid
|
|
"""
|
|
qry = {'external_code':str(class_external_code), 'valide':'1', 'locked':'0', 'partner_owner_recid':str(partner_recid)}
|
|
|
|
myclass_data_count = MYSY_GV.dbname['myclass'].count_documents(qry)
|
|
#print(" ### myclass_data_count = ", myclass_data_count)
|
|
|
|
if( myclass_data_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas .")
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas."
|
|
|
|
|
|
myclass_data = MYSY_GV.dbname['myclass'].find_one({'external_code':str(class_external_code), 'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':str(partner_recid)})
|
|
|
|
mysession_count_qry = {'class_internal_url': str(myclass_data['internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(partner_recid), 'code_session':str(df['code_session'].values[n]) }
|
|
|
|
#print(" ### mysession_count_qry = ", mysession_count_qry)
|
|
|
|
mysession_count = MYSY_GV.dbname['session_formation'].count_documents(mysession_count_qry)
|
|
|
|
if( mysession_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas (2).")
|
|
return False, "Ligne : " + str(
|
|
n + 2) + ": Le code externe de la formation et le code de la session ne correspondent pas (2)."
|
|
|
|
mysession_data = MYSY_GV.dbname['session_formation'].find_one(mysession_count_qry)
|
|
|
|
|
|
|
|
mydata['session_id'] = str(mysession_data['_id'])
|
|
mydata['class_internal_url'] = str(mysession_data['class_internal_url'])
|
|
|
|
"""
|
|
Recuperation de l''_id' de la session à partir de la clé
|
|
- formation code externe
|
|
- code_session
|
|
- partner_owner_recid
|
|
"""
|
|
|
|
"""
|
|
On verifie que le code de le session et le l'external class code correspondent.
|
|
En gros : que la formation en question a bien une session du meme code
|
|
"""
|
|
|
|
modefinancement = ""
|
|
if ("modefinancement" in df.keys()):
|
|
if (str(df['modefinancement'].values[n])):
|
|
modefinancement = str(df['modefinancement'].values[n])
|
|
mydata['modefinancement'] = modefinancement
|
|
|
|
|
|
opco = ""
|
|
if ("opco" in df.keys()):
|
|
if (str(df['opco'].values[n])):
|
|
opco = str(df['opco'].values[n])
|
|
mydata['opco'] = opco
|
|
|
|
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( 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_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_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'])
|
|
|
|
|
|
mydata['status'] = str(df['status'].values[n]).strip()
|
|
if( str(mydata['status']) != "0" and str(mydata['status']) != "1" and str(mydata['status']) != "2"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ 'status' de la ligne " + str(n) + " est incorrecte. Valeurs acceptées : 0,1,2")
|
|
return False, " Le champ status de la ligne " + str(n) + " est incorrecte. Valeurs acceptées : 0,1,2"
|
|
|
|
|
|
if( str(df['status'].values[n]).strip() == "1"):
|
|
mydata['inscription_validation_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
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()
|
|
|
|
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
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
#print( "#### clean_dict ", clean_dict)
|
|
|
|
|
|
return True, str(total_rows)+" participants 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 participants a importer en masse "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'imprimer/telecharger la fichier d'un inscrit à une session.
|
|
Cette fonction va utiliser un template pour imprimer le modele
|
|
"""
|
|
def PrintAttendeeDetail_perSession(diction):
|
|
try:
|
|
field_list_obligatoire = ['session_id', 'token', 'attendee_email', 'internal_url']
|
|
|
|
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 d'imprimer la fiche detaillée"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
internal_url = ""
|
|
if ("internal_url" in diction.keys()):
|
|
if diction['internal_url']:
|
|
internal_url = diction['internal_url']
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
RetObject = []
|
|
# Recuperation des infos de la l'inscription
|
|
qry = {'session_id': str(diction['session_id']),'email': str(diction['attendee_email']),
|
|
'class_internal_url':str(diction['internal_url'])}
|
|
|
|
|
|
|
|
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
'class_internal_url':str(diction['internal_url'])})
|
|
my_retrun_dict = {}
|
|
|
|
my_retrun_dict['session_id'] = local_Insc_retval['session_id']
|
|
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['date_du']:
|
|
date_du = local_Insc_retval['date_du']
|
|
my_retrun_dict['date_du'] = str(date_du)[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['date_au']:
|
|
date_au = local_Insc_retval['date_au']
|
|
my_retrun_dict['date_au'] = str(date_au)[0:10]
|
|
|
|
ville = ""
|
|
if ("ville" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['ville']:
|
|
code_postal = local_Insc_retval['ville']
|
|
my_retrun_dict['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['code_postal']:
|
|
code_postal = local_Insc_retval['code_postal']
|
|
my_retrun_dict['code_postal'] = code_postal
|
|
|
|
|
|
my_adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['adresse']:
|
|
my_adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = my_adresse
|
|
|
|
my_nom = ""
|
|
if ("nom" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['nom']:
|
|
my_adresse = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = my_nom
|
|
|
|
my_prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['prenom']:
|
|
my_prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = my_prenom
|
|
|
|
my_employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['employeur']:
|
|
my_employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = my_employeur
|
|
|
|
my_telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['telephone']:
|
|
my_telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = my_telephone
|
|
|
|
my_email = ""
|
|
if ("email" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['email']:
|
|
my_email = local_Insc_retval['email']
|
|
my_retrun_dict['email'] = my_email
|
|
|
|
my_modefinancement = ""
|
|
if ("modefinancement" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['modefinancement']:
|
|
my_modefinancement = local_Insc_retval['modefinancement']
|
|
my_retrun_dict['modefinancement'] = my_modefinancement
|
|
|
|
my_opco = ""
|
|
if ("opco" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['opco']:
|
|
my_opco = local_Insc_retval['opco']
|
|
my_retrun_dict['opco'] = my_opco
|
|
|
|
my_class_internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['class_internal_url']:
|
|
my_class_internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['class_internal_url'] = my_class_internal_url
|
|
|
|
my_status = ""
|
|
if ("status" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['status']:
|
|
my_status = local_Insc_retval['status']
|
|
my_retrun_dict['status'] = my_status
|
|
|
|
my_price = ""
|
|
if ("price" in local_Insc_retval.keys()):
|
|
if local_Insc_retval['price']:
|
|
my_price = local_Insc_retval['price']
|
|
my_retrun_dict['price'] = my_price
|
|
|
|
|
|
if ("inscription_validation_date" in local_Insc_retval.keys()):
|
|
my_retrun_dict['inscription_validation_date'] = local_Insc_retval['inscription_validation_date']
|
|
|
|
if ("eval_eval" in local_Insc_retval.keys()):
|
|
my_retrun_dict['evaluation'] = local_Insc_retval['eval_eval']
|
|
|
|
if ("eval_note" in local_Insc_retval.keys()):
|
|
my_retrun_dict['note_eval'] = local_Insc_retval['eval_note']
|
|
|
|
if ("eval_date" in local_Insc_retval.keys()):
|
|
my_retrun_dict['date_eval'] = str(local_Insc_retval['eval_date'])[0:10]
|
|
|
|
v = local_Insc_retval['_id'].generation_time
|
|
my_retrun_dict['created_date'] = str(v.strftime("%d/%m/%Y"))
|
|
|
|
my_retrun_dict['date_impression'] = str(datetime.today().strftime("%d/%m/%Y"))
|
|
|
|
# Recuperation des infotrmations de la formation
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(local_Insc_retval['class_internal_url']),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
|
|
my_local_title = ""
|
|
if ("title" in local_formation.keys()):
|
|
if local_formation['title']:
|
|
my_retrun_dict['class_title'] = local_formation['title']
|
|
my_local_title = local_formation['title']
|
|
|
|
local_query = {'_id':ObjectId(str(local_Insc_retval['session_id'])), 'valide':'1',
|
|
'partner_owner_recid':str(partner_recid)}
|
|
|
|
print(" ### local_query = ", local_query)
|
|
|
|
# Recuperation du formation depuis la collection "session_formation"
|
|
tmp_val = MYSY_GV.dbname['session_formation'].find_one(local_query)
|
|
if( tmp_val is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossible d'imprimer la fiche detaillée : code session erronée ")
|
|
return False, " Impossible d'imprimer la fiche detaillée : code session erronée "
|
|
|
|
my_trainer = ""
|
|
if ("formateur_id" in tmp_val.keys()):
|
|
if tmp_val['formateur_id']:
|
|
|
|
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(tmp_val['formateur_id'])),
|
|
'valide': '1',
|
|
'locked': '1',
|
|
'partner_recid': str(partner_recid)})
|
|
|
|
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
|
formateur = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
|
|
|
|
|
|
my_trainer = formateur
|
|
my_retrun_dict['formateur_id'] = tmp_val['formateur_id']
|
|
|
|
if (my_trainer == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossible d'imprimer la fiche detaillée : Aucun formateur designé pour la session")
|
|
return False, " Impossible d'imprimer la fiche detaillée : Aucun formateur designé pour la session"
|
|
|
|
|
|
if ("distantiel" in tmp_val.keys()):
|
|
if tmp_val['distantiel']:
|
|
my_retrun_dict['distantiel'] = tmp_val['distantiel']
|
|
|
|
if ("presentiel" in tmp_val.keys()):
|
|
if tmp_val['presentiel']:
|
|
my_retrun_dict['presentiel'] = tmp_val['presentiel']
|
|
|
|
my_partner = ""
|
|
if ("institut_formation" in local_formation.keys()):
|
|
if local_formation['institut_formation']:
|
|
my_partner = local_formation['institut_formation']
|
|
my_retrun_dict['partner'] = my_partner
|
|
|
|
my_img_url = ""
|
|
if ("img_url" in local_formation.keys()):
|
|
if local_formation['img_url']:
|
|
my_img_url = local_formation['img_url']
|
|
my_retrun_dict['img_url'] = my_img_url
|
|
|
|
|
|
|
|
##############################
|
|
# Recuperation des fiches de presence
|
|
tab_presences = []
|
|
for val_tmp in MYSY_GV.dbname['emargement'].find({'session_id':str(local_Insc_retval['session_id']),
|
|
'email':str(local_Insc_retval['email'])}).sort([("date", pymongo.ASCENDING)]):
|
|
local_tmp = {}
|
|
local_tmp['email'] = val_tmp['email']
|
|
local_tmp['matin'] = val_tmp['matin']
|
|
local_tmp['apresmidi'] = val_tmp['apresmidi']
|
|
local_tmp['date'] = val_tmp['date']
|
|
|
|
tab_presences.append(local_tmp)
|
|
|
|
|
|
# Recuperation image logo du partenaire en base de donnée
|
|
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'partnair_account',
|
|
'related_collection_recid': str(my_partner_data['recid']), 'type_img':'logo'}
|
|
|
|
|
|
partner_media_logo = MYSY_GV.dbname['mysy_images'].find_one(qery_images)
|
|
|
|
is_partner_logo = True
|
|
is_partner_logo_img = ""
|
|
if( partner_media_logo is None or "img" not in partner_media_logo.keys()):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La partner n'a pas de logo, le logo par defaut sera utilisé")
|
|
|
|
is_partner_logo = False
|
|
else:
|
|
is_partner_logo_img = "data:image/png;base64," + str(partner_media_logo['img'])
|
|
|
|
if( is_partner_logo is False ):
|
|
# récupérer l'image logo par default
|
|
default_qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'partnair_account', 'type_img': 'logo_default'}
|
|
partner_media_logo = MYSY_GV.dbname['mysy_images'].find_one(default_qery_images)
|
|
|
|
is_partner_logo_img = "data:image/png;base64," + str(partner_media_logo['img'])
|
|
|
|
|
|
my_retrun_dict['default_logo_partner'] = is_partner_logo_img
|
|
|
|
#print(" ### my_retrun_dict =",my_retrun_dict)
|
|
|
|
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
|
TEMPLATE_FILE = "Template/fiche_detail_stagiaire_tpl.html"
|
|
template = templateEnv.get_template(TEMPLATE_FILE)
|
|
# This data can come from database query
|
|
body = {
|
|
"data": my_retrun_dict,
|
|
"presences": tab_presences
|
|
}
|
|
|
|
# print(" ### body = " + str(body))
|
|
|
|
sourceHtml = template.render(json_data=body["data"], presences=body["presences"])
|
|
mycode = str(datetime.now().timestamp()).replace(".", '').replace(',', '')
|
|
orig_file_name = "fichier_personnel_"+str(mycode)[:-3]+"pdf"
|
|
outputFilename = str(MYSY_GV.EMARGEMENT_DIRECTORY) + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
# print(" ### outputFilename = "+str(outputFilename))
|
|
if os.path.exists(outputFilename):
|
|
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
# return True on success and False on errors
|
|
print(pisaStatus.err, type(pisaStatus.err))
|
|
|
|
return True, " le fichier generé "
|
|
|
|
|
|
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'imprimer la fiche detaillée"
|
|
|
|
|
|
|
|
|
|
""" Creation d'un evaluation sur une formation
|
|
Les infos d'evaluation sont rattachées à la collection inscription.
|
|
|
|
eval_date :
|
|
eval_note :
|
|
eval_eval :
|
|
eval_pedagogie :
|
|
|
|
"""
|
|
def Evaluation_Class(diction):
|
|
try:
|
|
|
|
field_list_obligatoire = ['inscription_id', 'eval_note', 'eval_eval', 'eval_pedagogie', 'class_internal_url']
|
|
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"
|
|
|
|
|
|
|
|
note = str(diction['eval_note']).strip()
|
|
if( mycommon.IsFloat( note ) is False ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La note d'evaluation est incorrecte ")
|
|
return False, " La note d'evaluation est incorrecte "
|
|
|
|
mydata = {}
|
|
mydata['eval_date'] = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
mydata['eval_note'] = str(diction['eval_note']).strip()
|
|
mydata['eval_status'] = "1"
|
|
mydata['eval_eval'] = str(diction['eval_eval']).strip()
|
|
mydata['eval_pedagogie'] = str(diction['eval_pedagogie']).strip()
|
|
|
|
ret_val = MYSY_GV.dbname['inscription'].find_one_and_update({'_id': ObjectId(str(str(diction['inscription_id']).strip())),},
|
|
{"$set": mydata},
|
|
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 d'enregistrer l'evaluation ")
|
|
return False, " Impossible d'enregistrer l'evaluation "
|
|
|
|
|
|
# Declencer l'envoi de la notification de l'evaluation
|
|
email_mgt.EmailNotifEvaluation_Done(diction)
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = ""
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(diction['inscription_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Evaluation Formation "
|
|
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, " L'evaluation a bien été enregistré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 créer l'evaluation"
|
|
|
|
"""
|
|
Cette fonction verifie si un token d'evaluation est valide.
|
|
|
|
Un token est valide si :
|
|
token = ObjectId existe
|
|
internal_url et le objectId sont coherents (meme ligne dans la collection)
|
|
L'evaluation n'a pas deja ete faite.
|
|
|
|
"""
|
|
def MySyckeckEvaluationToken(diction):
|
|
try:
|
|
field_list_obligatoire = ['eval_token', 'class_internal_url']
|
|
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"
|
|
|
|
eval_token = ""
|
|
if ("eval_token" in diction.keys()):
|
|
if diction['eval_token']:
|
|
eval_token = diction['eval_token']
|
|
|
|
internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
internal_url = diction['class_internal_url']
|
|
|
|
#local_qry = {'class_internal_url':internal_url, '_id': ObjectId(eval_token), "eval_date":{"$exists":False} }
|
|
|
|
#print(" ### local_qry =",local_qry)
|
|
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'class_internal_url':internal_url,
|
|
'_id': ObjectId(eval_token), "eval_date":{"$exists":False} } )
|
|
|
|
if (tmp_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " "+str(tmp_count)+" est different de 1. impossible de faire l'evaluation")
|
|
return False, " Impossible de faire l'evaluation. Verifier les informations fournies"
|
|
|
|
|
|
return True, "Ok"
|
|
|
|
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 verifier la validé du token"
|
|
|
|
|
|
"""
|
|
Cette fonction envoie l'email de demande d'evaluation
|
|
"""
|
|
def SendTrainingEvaluationEmail(diction):
|
|
try:
|
|
field_list_obligatoire = ['session_id', 'token', 'attendee_email', 'class_internal_url']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = str(my_partner['recid'])
|
|
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
'class_internal_url': str(diction['class_internal_url'],),
|
|
'partner_owner_recid': str(partner_recid),
|
|
"eval_date": {"$exists": True}})
|
|
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Cette formation a déjà été évaluée")
|
|
return False, " Cette formation a déjà été évaluée"
|
|
|
|
|
|
RetObject = []
|
|
# Recuperation des infos de la formation
|
|
qry = {'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
'class_internal_url': str(diction['class_internal_url']),
|
|
'partner_owner_recid': str(partner_recid),
|
|
}
|
|
|
|
|
|
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
'class_internal_url': str(diction['class_internal_url']),
|
|
'partner_owner_recid': str(partner_recid),
|
|
})
|
|
|
|
my_retrun_dict = {}
|
|
|
|
print(' ##### local_Insc_retval = ', local_Insc_retval)
|
|
|
|
my_retrun_dict['token_eval'] = local_Insc_retval['_id']
|
|
if( "date_du" in local_Insc_retval.keys() ):
|
|
my_retrun_dict['date_du'] = str(local_Insc_retval['date_du'])[1:10]
|
|
else:
|
|
my_retrun_dict['date_du'] = ""
|
|
|
|
if ("date_au" in local_Insc_retval.keys() ):
|
|
my_retrun_dict['date_au'] = str(local_Insc_retval['date_au'])[0:10]
|
|
else:
|
|
my_retrun_dict['date_au'] = ""
|
|
|
|
my_retrun_dict['session_id'] = str(local_Insc_retval['_id'])
|
|
|
|
ville = ""
|
|
if ("ville" in local_Insc_retval.keys() and local_Insc_retval['ville']):
|
|
ville = local_Insc_retval['ville']
|
|
my_retrun_dict['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_Insc_retval.keys() and local_Insc_retval['code_postal']):
|
|
code_postal = local_Insc_retval['code_postal']
|
|
my_retrun_dict['code_postal'] = code_postal
|
|
|
|
internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys() and local_Insc_retval['class_internal_url']):
|
|
internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['internal_url'] = internal_url
|
|
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys() and local_Insc_retval['adresse']):
|
|
adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = adresse
|
|
|
|
nom = ""
|
|
if ("nom" in local_Insc_retval.keys() and local_Insc_retval['nom']):
|
|
nom = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = nom
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys() and local_Insc_retval['prenom']):
|
|
prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = prenom
|
|
|
|
employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys() and local_Insc_retval['employeur']):
|
|
employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = employeur
|
|
|
|
telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys() and local_Insc_retval['telephone']):
|
|
telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = telephone
|
|
|
|
|
|
my_retrun_dict['email'] = local_Insc_retval['email']
|
|
|
|
# Recuperation des infotrmations de la formation
|
|
print(" ### str(local_Insc_retval['class_internal_url']) = ",str(local_Insc_retval['class_internal_url']) )
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(local_Insc_retval['class_internal_url'])})
|
|
my_retrun_dict['title'] = local_formation['title']
|
|
|
|
# Recuperation des info de session
|
|
local_session_info = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1'})
|
|
|
|
|
|
if( local_session_info is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données de la session de formation")
|
|
return False, " Impossible de récupérer les données de la session de formation"
|
|
|
|
if ("code_session" in local_session_info.keys()):
|
|
if local_session_info['code_session']:
|
|
my_retrun_dict['code_session'] = local_session_info['code_session']
|
|
|
|
if ("distantiel" in local_session_info.keys()):
|
|
if local_session_info['distantiel']:
|
|
my_retrun_dict['distantiel'] = local_session_info['distantiel']
|
|
|
|
if ("presentiel" in local_session_info.keys()):
|
|
if local_session_info['presentiel']:
|
|
my_retrun_dict['presentiel'] = local_session_info['presentiel']
|
|
|
|
session_ondemande = ""
|
|
if ("session_ondemande" in local_session_info.keys()):
|
|
if local_session_info['session_ondemande']:
|
|
session_ondemande = local_session_info['session_ondemande']
|
|
|
|
my_retrun_dict['session_ondemande'] = session_ondemande
|
|
|
|
my_retrun_dict['partner_owner_recid'] = local_session_info['partner_owner_recid']
|
|
|
|
my_retrun_dict['token'] = str(diction['token'])
|
|
my_retrun_dict['session_id'] = str(diction['session_id'])
|
|
my_retrun_dict['inscription_id'] = str(local_Insc_retval['_id'])
|
|
|
|
# Envoi de l'email de notification au formateur
|
|
local_status, local_message = email_session.Evaluation_training_confirmation_mail(my_retrun_dict)
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(local_Insc_retval['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Demande Evaluation Formation "
|
|
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 local_status, str(local_message)
|
|
|
|
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 la demande d'evaluation"
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction envoie l'email de demande d'evaluation from tab_ids
|
|
"""
|
|
def SendTrainingEvaluationEmail_from_tab_ids(diction):
|
|
try:
|
|
field_list_obligatoire = ['session_id', 'token', 'tab_ids']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
my_inscription_ids = ""
|
|
if ("tab_ids" in diction.keys()):
|
|
if diction['tab_ids']:
|
|
my_inscription_ids = diction['tab_ids']
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = str(my_partner['recid'])
|
|
|
|
tab_my_inscription_ids = str(my_inscription_ids).split(",")
|
|
for my_inscription_id in tab_my_inscription_ids:
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
|
'_id':ObjectId(str(my_inscription_id)),
|
|
'partner_owner_recid': str(partner_recid),
|
|
"eval_date": {"$exists": True}})
|
|
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Cet apprenant a déjà évalué cette session")
|
|
return False, " Cet apprenant a déjà évalué cette session"
|
|
|
|
|
|
RetObject = []
|
|
# Recuperation des infos de la formation
|
|
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
|
'_id':ObjectId(str(my_inscription_id)),
|
|
'partner_owner_recid': str(partner_recid),
|
|
})
|
|
|
|
if(local_Insc_retval is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
|
return False, " L'identifiant de l'inscrit est invalide "
|
|
|
|
my_retrun_dict = {}
|
|
|
|
print(' ##### local_Insc_retval = ', local_Insc_retval)
|
|
|
|
my_retrun_dict['token_eval'] = local_Insc_retval['_id']
|
|
if( "date_du" in local_Insc_retval.keys() ):
|
|
my_retrun_dict['date_du'] = str(local_Insc_retval['date_du'])[1:10]
|
|
else:
|
|
my_retrun_dict['date_du'] = ""
|
|
|
|
if ("date_au" in local_Insc_retval.keys() ):
|
|
my_retrun_dict['date_au'] = str(local_Insc_retval['date_au'])[0:10]
|
|
else:
|
|
my_retrun_dict['date_au'] = ""
|
|
|
|
my_retrun_dict['session_id'] = str(local_Insc_retval['_id'])
|
|
|
|
ville = ""
|
|
if ("ville" in local_Insc_retval.keys() and local_Insc_retval['ville']):
|
|
ville = local_Insc_retval['ville']
|
|
my_retrun_dict['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_Insc_retval.keys() and local_Insc_retval['code_postal']):
|
|
code_postal = local_Insc_retval['code_postal']
|
|
my_retrun_dict['code_postal'] = code_postal
|
|
|
|
internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys() and local_Insc_retval['class_internal_url']):
|
|
internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['internal_url'] = internal_url
|
|
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys() and local_Insc_retval['adresse']):
|
|
adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = adresse
|
|
|
|
nom = ""
|
|
if ("nom" in local_Insc_retval.keys() and local_Insc_retval['nom']):
|
|
nom = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = nom
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys() and local_Insc_retval['prenom']):
|
|
prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = prenom
|
|
|
|
employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys() and local_Insc_retval['employeur']):
|
|
employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = employeur
|
|
|
|
telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys() and local_Insc_retval['telephone']):
|
|
telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = telephone
|
|
|
|
|
|
my_retrun_dict['email'] = local_Insc_retval['email']
|
|
|
|
# Recuperation des infotrmations de la formation
|
|
print(" ### str(local_Insc_retval['class_internal_url']) = ",str(local_Insc_retval['class_internal_url']) )
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(local_Insc_retval['class_internal_url'])})
|
|
my_retrun_dict['title'] = local_formation['title']
|
|
|
|
# Recuperation des info de session
|
|
local_session_info = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1'})
|
|
|
|
|
|
if( local_session_info is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données de la session de formation")
|
|
return False, " Impossible de récupérer les données de la session de formation"
|
|
|
|
if ("code_session" in local_session_info.keys()):
|
|
if local_session_info['code_session']:
|
|
my_retrun_dict['code_session'] = local_session_info['code_session']
|
|
|
|
if ("distantiel" in local_session_info.keys()):
|
|
if local_session_info['distantiel']:
|
|
my_retrun_dict['distantiel'] = local_session_info['distantiel']
|
|
|
|
if ("presentiel" in local_session_info.keys()):
|
|
if local_session_info['presentiel']:
|
|
my_retrun_dict['presentiel'] = local_session_info['presentiel']
|
|
|
|
session_ondemande = ""
|
|
if ("session_ondemande" in local_session_info.keys()):
|
|
if local_session_info['session_ondemande']:
|
|
session_ondemande = local_session_info['session_ondemande']
|
|
|
|
my_retrun_dict['session_ondemande'] = session_ondemande
|
|
|
|
my_retrun_dict['partner_owner_recid'] = local_session_info['partner_owner_recid']
|
|
|
|
my_retrun_dict['token'] = str(diction['token'])
|
|
my_retrun_dict['session_id'] = str(diction['session_id'])
|
|
my_retrun_dict['inscription_id'] = str(local_Insc_retval['_id'])
|
|
|
|
# Envoi de l'email de notification au formateur
|
|
local_status, local_message = email_session.Evaluation_training_confirmation_mail(my_retrun_dict)
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(local_Insc_retval['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = " Demande Evaluation Formation "
|
|
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 local_status, "Les demande d'évaluation ont été correctement envoyées "
|
|
|
|
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 la demande d'évaluation"
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction envoie le certificat d'un stagiaire
|
|
"""
|
|
def SendAttendeeCertification(diction):
|
|
try:
|
|
|
|
field_list_obligatoire = ['session_id', 'token', 'attendee_email', 'class_internal_url']
|
|
|
|
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"
|
|
|
|
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"
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
'class_internal_url': str(diction['class_internal_url']),
|
|
"certification_send_date": {"$exists": True}})
|
|
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Vous avez deja envoyé le certificat")
|
|
return False, " Vous avez deja envoyé le certificat"
|
|
|
|
# Recuperation du type/nom de la certifcation depuis la collecion "session_formation"
|
|
session_formation = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id'])),
|
|
'class_internal_url': str(
|
|
diction['class_internal_url']),
|
|
'valide': "1"})
|
|
|
|
if( session_formation['attestation_certif'] is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de trouver le modele d'attestation")
|
|
return False, " impossible de trouver le modele d'attestation"
|
|
|
|
date_fin_session = str(session_formation['date_fin'] )[0:10]
|
|
local_status = mycommon.CheckisDate(date_fin_session)
|
|
if( local_status is False ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " La date de fin de session de formation est incorrecte.")
|
|
return False, " La date de fin de session de formation est incorrecte."
|
|
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
"""
|
|
if (datetime.strptime(str(date_fin_session).strip(), '%d/%m/%Y') > datetime.strptime(str(mytoday).strip(), '%d/%m/%Y')):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Vous ne pouvez pas delivrer de certificat avant la date de fin de la session de formation ")
|
|
return False, " Vous ne pouvez pas delivrer de certificat avant la date de fin de la session de formation "
|
|
"""
|
|
print(" #### attestation_certif = ", str(session_formation['attestation_certif']))
|
|
attestation_certificat = MYSY_GV.dbname['attestation_certificat'].find_one({'nom': str(session_formation['attestation_certif']),
|
|
'valide': "1"})
|
|
|
|
if ( attestation_certificat is None or attestation_certificat['template_name'] is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucun type d'attestation/certificat trouvé 1")
|
|
return False, " Aucun type d'attestation/certificat trouvé "
|
|
|
|
my_retrun_dict = {}
|
|
|
|
my_retrun_dict['partner_recid'] = partner_recid
|
|
|
|
my_template = ""
|
|
if ("template_name" in attestation_certificat.keys() and attestation_certificat['template_name']):
|
|
my_template = attestation_certificat['template_name']
|
|
|
|
if( str(my_template).strip() == ""):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Aucun type d'attestation/certificat trouvé 2")
|
|
return False, " Aucun type d'attestation/certificat trouvé "
|
|
|
|
my_retrun_dict['attestation_tmpl'] = attestation_certificat['template_name']
|
|
|
|
# Recuperation des info de l'inscrit
|
|
local_qry = {'session_id': str(diction['session_id']),
|
|
'class_internal_url': str(
|
|
diction['class_internal_url']),
|
|
'email': str(diction['attendee_email'])}
|
|
|
|
print("### "+str(inspect.stack()[0][3]) + "local_qry = ", local_qry )
|
|
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
|
'class_internal_url': str(
|
|
diction['class_internal_url']),
|
|
'email': str(diction['attendee_email'])})
|
|
|
|
if (local_Insc_retval is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données de l'inscrit")
|
|
return False, " Impossible de récupérer les données de l'inscrit"
|
|
|
|
my_retrun_dict['date_du'] = local_Insc_retval['date_du']
|
|
my_retrun_dict['date_au'] = local_Insc_retval['date_au']
|
|
|
|
ville = ""
|
|
if ("ville" in local_Insc_retval.keys() and local_Insc_retval['ville']):
|
|
ville = local_Insc_retval['ville']
|
|
my_retrun_dict['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_Insc_retval.keys() and local_Insc_retval['code_postal']):
|
|
code_postal = local_Insc_retval['code_postal']
|
|
my_retrun_dict['code_postal'] = code_postal
|
|
|
|
internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys() and local_Insc_retval['class_internal_url']):
|
|
internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['code_postal'] = internal_url
|
|
|
|
|
|
my_retrun_dict['inscription_id'] = local_Insc_retval['_id']
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys() and local_Insc_retval['adresse']):
|
|
adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = adresse
|
|
|
|
nom = ""
|
|
if ("nom" in local_Insc_retval.keys() and local_Insc_retval['nom']):
|
|
nom = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = nom
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys() and local_Insc_retval['prenom']):
|
|
prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = prenom
|
|
|
|
employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys() and local_Insc_retval['employeur']):
|
|
employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = employeur
|
|
|
|
telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys() and local_Insc_retval['telephone']):
|
|
telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = telephone
|
|
|
|
formateur = ""
|
|
if ("formateur" in session_formation.keys() and session_formation['formateur']):
|
|
formateur = session_formation['formateur']
|
|
my_retrun_dict['formateur'] = formateur
|
|
|
|
presentiel = ""
|
|
if ("presentiel" in session_formation.keys() and session_formation['presentiel']):
|
|
presentiel = session_formation['presentiel']
|
|
my_retrun_dict['presentiel'] = presentiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in session_formation.keys() and session_formation['distantiel']):
|
|
distantiel = session_formation['distantiel']
|
|
my_retrun_dict['distantiel'] = distantiel
|
|
|
|
|
|
#my_retrun_dict['formateur'] = session_formation['formateur']
|
|
|
|
my_retrun_dict['email'] = local_Insc_retval['email']
|
|
|
|
# Recuperation des infotrmations de la formation
|
|
##print(" ## str(local_Insc_retval['class_internal_url']) = ", str(local_Insc_retval['class_internal_url']))
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(local_Insc_retval['class_internal_url'])})
|
|
my_retrun_dict['title'] = local_formation['title']
|
|
|
|
"""
|
|
field_list_obligatoire = ['partner_recid', 'session_id', 'class_internal_url', 'class_title' ,
|
|
'email_participant']
|
|
"""
|
|
attestation_dict = {}
|
|
attestation_dict['partner_recid'] = str(partner_recid)
|
|
attestation_dict['session_id'] = str(diction['session_id'])
|
|
attestation_dict['class_internal_url'] = str(local_Insc_retval['class_internal_url'])
|
|
attestation_dict['class_title'] = local_formation['title']
|
|
attestation_dict['email_participant'] = local_Insc_retval['email']
|
|
attestation_dict['attestation_tmpl'] = attestation_certificat['template_name']
|
|
|
|
print(" ### attestation_dict = ", attestation_dict)
|
|
|
|
# Envoi de l'email de notification au formateur
|
|
local_status, local_message = email_session.SendAttestion_to_attendee_by_email(attestation_dict)
|
|
|
|
return local_status, str(local_message)
|
|
|
|
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'attestation"
|
|
|
|
|
|
""" Cette fonction imprime l'attestation
|
|
"""
|
|
|
|
|
|
def PrintAttendeeCertification(diction):
|
|
try:
|
|
|
|
field_list_obligatoire = ['session_id', 'token', 'attendee_email', 'internal_url']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email']),
|
|
"certification_send": {"$exists": True}})
|
|
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Vous avez deja envoyé le certificat")
|
|
return False, " Vous avez deja envoyé le certificat"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_partner = MYSY_GV.dbname['partnair_account'].find_one({'recid': str(partner_recid),
|
|
'active': "1",
|
|
'locked':'0'})
|
|
|
|
if( local_partner is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données du partenaire")
|
|
return False, " Impossible de récupérer les données du partenaire "
|
|
|
|
my_retrun_dict = {}
|
|
|
|
partner_nom = ""
|
|
if ("nom" in local_partner.keys()):
|
|
partner_nom = local_partner['nom']
|
|
my_retrun_dict['partner'] = partner_nom
|
|
|
|
num_nda = ""
|
|
if ("num_nda" in local_partner.keys()):
|
|
num_nda = local_partner['num_nda']
|
|
my_retrun_dict['num_declation'] = num_nda
|
|
|
|
mysy_partner_adr_city = ""
|
|
if ("adr_city" in local_partner.keys()):
|
|
mysy_partner_adr_city = local_partner['adr_city']
|
|
my_retrun_dict['mysy_partner_adr_city'] = mysy_partner_adr_city
|
|
|
|
my_retrun_dict['cachet_signature'] = "https://img.mysy-training.com/perso/mysy_cachet.png"
|
|
ct = datetime.now()
|
|
ts = ct.timestamp()
|
|
date_jour = ct.strftime("%d/%m/%Y")
|
|
my_retrun_dict['date_jour'] = str(date_jour)
|
|
|
|
# Recuperation du type/nom de la certifcation depuis la collecion "session_formation"
|
|
session_formation = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': "1", 'class_internal_url':str(diction['internal_url'])})
|
|
|
|
if ("attestation_certif" not in session_formation.keys()):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de trouver le modele d'attestation")
|
|
return False, " impossible de trouver le modele d'attestation"
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in session_formation.keys()):
|
|
distantiel = session_formation['distantiel']
|
|
my_retrun_dict['distantiel'] = distantiel
|
|
|
|
distantiel = ""
|
|
if ("distantiel" in session_formation.keys()):
|
|
distantiel = session_formation['formateur']
|
|
my_retrun_dict['distantiel'] = distantiel
|
|
|
|
formateur = ""
|
|
if ("formateur" in session_formation.keys()):
|
|
formateur = session_formation['formateur']
|
|
my_retrun_dict['formateur'] = formateur
|
|
|
|
contenu_ftion = ""
|
|
if ("contenu_ftion" in session_formation.keys()):
|
|
contenu_ftion = str(session_formation['contenu_ftion']).replace('<p>', '').replace('</p>', '').replace("\r\n", '<br/>')
|
|
my_retrun_dict['contenu_ftion'] = contenu_ftion
|
|
|
|
|
|
# Recuperation des données de l'attestation
|
|
attestation_certificat = MYSY_GV.dbname['attestation_certificat'].find_one(
|
|
{'nom': str(session_formation['attestation_certif']),
|
|
'valide': "1"})
|
|
|
|
if( attestation_certificat is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de trouver le modele d'attestation (2)")
|
|
return False, " impossible de trouver le modele d'attestation (2)"
|
|
|
|
if ("template_name" not in attestation_certificat.keys()):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " impossible de trouver le modele d'attestation (3)")
|
|
return False, " impossible de trouver le modele d'attestation (3)"
|
|
|
|
|
|
|
|
my_retrun_dict['attestation_tmpl'] = attestation_certificat['template_name']
|
|
|
|
# Recuperation des info de l'inscrit
|
|
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
|
'email': str(diction['attendee_email'])})
|
|
|
|
if (local_Insc_retval is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données de l'inscrit")
|
|
return False, " Impossible de récupérer les données de l'inscrit"
|
|
|
|
my_retrun_dict['date_du'] = str(local_Insc_retval['date_du'])[0:10]
|
|
my_retrun_dict['date_au'] = str(local_Insc_retval['date_au'])[0:10]
|
|
|
|
ville = ""
|
|
if ("ville" in local_Insc_retval.keys()):
|
|
ville = local_Insc_retval['ville']
|
|
my_retrun_dict['ville'] = ville
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in local_Insc_retval.keys()):
|
|
code_postal = local_Insc_retval['code_postal']
|
|
my_retrun_dict['code_postal'] = code_postal
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys()):
|
|
class_internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['internal_url'] = class_internal_url
|
|
|
|
|
|
adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys()):
|
|
adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = adresse
|
|
|
|
nom = ""
|
|
if ("nom" in local_Insc_retval.keys()):
|
|
nom = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = nom
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys()):
|
|
prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = prenom
|
|
|
|
employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys()):
|
|
employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = employeur
|
|
|
|
telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys()):
|
|
telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = telephone
|
|
|
|
email = ""
|
|
if ("email" in local_Insc_retval.keys()):
|
|
email = local_Insc_retval['email']
|
|
my_retrun_dict['email'] = email
|
|
|
|
|
|
|
|
# Recuperation des infotrmations de la formation
|
|
#print(" ## str(local_Insc_retval['class_internal_url']) = ", str(local_Insc_retval['class_internal_url']))
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(local_Insc_retval['class_internal_url'])})
|
|
|
|
if( local_formation is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible de récupérer les données de la formation ")
|
|
return False, " Impossible de récupérer les données de la formation"
|
|
|
|
title = ""
|
|
if ("title" in local_formation.keys()):
|
|
title = local_formation['title']
|
|
my_retrun_dict['class_title'] = title
|
|
|
|
logo_url = ""
|
|
if ("img_url" in local_formation.keys()):
|
|
logo_url = local_formation['img_url']
|
|
my_retrun_dict['logo_url'] = logo_url
|
|
|
|
|
|
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
|
TEMPLATE_FILE = "Template/"+str(my_retrun_dict['attestation_tmpl'])+".html"
|
|
template = templateEnv.get_template(TEMPLATE_FILE)
|
|
# This data can come from database query
|
|
body = {
|
|
"data": my_retrun_dict,
|
|
|
|
}
|
|
|
|
print(" ### body = " + str(body))
|
|
|
|
sourceHtml = template.render(json_data=body["data"])
|
|
mycode = str(datetime.now().timestamp()).replace(".", '').replace(',', '')
|
|
orig_file_name = "Attestation_" + str(mycode)[:-3] + "pdf"
|
|
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
# print(" ### outputFilename = "+str(outputFilename))
|
|
if os.path.exists(outputFilename):
|
|
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
# return True on success and False on errors
|
|
print(pisaStatus.err, type(pisaStatus.err))
|
|
|
|
return True, " le fichier generé "
|
|
|
|
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'attestation"
|
|
|
|
|
|
"""
|
|
Cette fonction récupérer la liste des evaluations d'une session de formation
|
|
"""
|
|
def GetListEvaluation_Session(diction):
|
|
try:
|
|
field_list_obligatoire = ['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, " Les informations fournies sont incorrectes"
|
|
|
|
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"
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des evaluations")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
qry = {'session_id': str(diction['session_id']), 'partner_owner_recid':str(partner_recid)}
|
|
|
|
|
|
# Recuperation des infos de la formation
|
|
for local_Insc_retval in MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']), 'partner_owner_recid':str(partner_recid)}):
|
|
user = {}
|
|
user['id'] = str(val_tmp)
|
|
user['_id'] = str(local_Insc_retval['_id'])
|
|
val_tmp = val_tmp + 1
|
|
user['session_id'] = local_Insc_retval['session_id']
|
|
user['email'] = local_Insc_retval['email']
|
|
user['nom'] = local_Insc_retval['nom']
|
|
user['prenom'] = local_Insc_retval['prenom']
|
|
|
|
if ("eval_date" in local_Insc_retval.keys()):
|
|
user['eval_date'] = local_Insc_retval['eval_date']
|
|
else:
|
|
user['eval_date'] = "---"
|
|
|
|
|
|
if ("eval_eval" in local_Insc_retval.keys()):
|
|
user['eval_eval'] = local_Insc_retval['eval_eval']
|
|
else:
|
|
user['eval_eval'] = "---"
|
|
|
|
|
|
if ("eval_status" in local_Insc_retval.keys()):
|
|
user['eval_status'] = local_Insc_retval['eval_status']
|
|
else:
|
|
user['eval_status'] = ""
|
|
|
|
|
|
if ("eval_note" in local_Insc_retval.keys()):
|
|
user['eval_note'] = local_Insc_retval['eval_note']
|
|
else:
|
|
user['eval_note'] = "---"
|
|
|
|
|
|
if ("eval_pedagogie" in local_Insc_retval.keys()):
|
|
user['eval_pedagogie'] = local_Insc_retval['eval_pedagogie']
|
|
else:
|
|
user['eval_pedagogie'] = ""
|
|
|
|
|
|
if ("date_demande_eval" in local_Insc_retval.keys()):
|
|
user['date_demande_eval'] = local_Insc_retval['date_demande_eval']
|
|
else:
|
|
user['date_demande_eval'] = ""
|
|
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
print(" ### RetObject = ", RetObject)
|
|
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 récupérer la liste des evaluations"
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'annuler l'inscription à une formation.
|
|
# status -1 ==> Inscription annulée
|
|
"""
|
|
def CancelAttendeeInscription(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'class_internal_url', '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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token':str(diction['token'])})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
partner_recid = str(my_partner['recid'])
|
|
|
|
data_mail = {}
|
|
# 1 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(diction['class_internal_url'])})
|
|
data_mail['title'] = local_class[0]['title']
|
|
class_title = local_class[0]['title']
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'email': str(diction['email']),
|
|
'class_internal_url':str(diction['class_internal_url'])})
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_class_code']:
|
|
lms_class_code = local_inscription[0]['lms_class_code']
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_user_id']:
|
|
lms_user_id = local_inscription[0]['lms_user_id']
|
|
|
|
nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
nom = local_inscription[0]['nom']
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
prenom = local_inscription[0]['prenom']
|
|
|
|
email = ""
|
|
if ("email" in local_inscription[0].keys()):
|
|
if local_inscription[0]['email']:
|
|
email = local_inscription[0]['email']
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_du']:
|
|
date_du = str(local_inscription[0]['date_du'])[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_au']:
|
|
date_au = str(local_inscription[0]['date_au'])[0:10]
|
|
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])), 'class_internal_url': str(diction['class_internal_url']), 'valide':'1'})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les données de la session ")
|
|
return False, " Impossible de récupérer les données de la session "
|
|
|
|
# Annulation de l'inscription
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'session_id': str(diction['session_id']), 'email': str(diction['email']), 'class_internal_url':str(diction['class_internal_url'])},
|
|
{"$set": {'status':'-1', 'inscription_refuse_date':now, 'date_update':now}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if( ret_val2 is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'annuler l'inscription ")
|
|
return False, " Impossible d'annuler l'inscription "
|
|
|
|
"""
|
|
Verification s'il y a une inscription LMS, au quel cas, on l'annule aussi
|
|
"""
|
|
|
|
return_message = ""
|
|
|
|
if( lms_user_id.strip() != ""):
|
|
# Il a une inscription à une formation dans le LMS, il faut l'annuler
|
|
new_diction = {}
|
|
new_diction['token'] = str(diction['token'])
|
|
new_diction['user_lms_id'] = str(lms_user_id)
|
|
new_diction['course_code'] = str(lms_class_code)
|
|
|
|
local_status, local_message = mys_lms.Remove_User_From_LMS_Class(new_diction)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible de supprimer l'inscription dans le LMS pour "+str( diction['email']) )
|
|
return_message = "Impossible de supprimer l'inscription dans le LMS pour : "+str( diction['email'])
|
|
|
|
email_data = {}
|
|
email_data['nom'] = nom
|
|
email_data['prenom'] = prenom
|
|
email_data['email'] = email
|
|
email_data['date_du'] = date_du
|
|
email_data['date_au'] = date_au
|
|
email_data['title'] = class_title
|
|
email_data['partner_owner_recid'] = str(partner_recid)
|
|
|
|
|
|
local_status, local_message = email_session.incription_training_cancelled_mail(email_data)
|
|
if( local_status is False ):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " - WARNING : Impossible d'envoyer le mail de notification pour " + str(
|
|
diction['email']))
|
|
return_message = return_message + str(" Impossible d'envoyer le mail de notification pour : " + str(diction['email']))
|
|
|
|
if( return_message.strip() != ""):
|
|
return True, return_message
|
|
|
|
return True, "L'inscription a été correctement annulé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 d'annuler l'inscription"
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction refuse une inscription, met jour le motif de refus
|
|
et envoie un email au participants
|
|
"""
|
|
def RefuseAttendeeInscription_with_motif(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'inscription_id', 'motif']
|
|
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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token':str(diction['token'])})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
partner_recid = str(my_partner['recid'])
|
|
|
|
# 0 - Verifier de l'existance et de la validité de l'inscription (preinscription à refuser)
|
|
my_inscription_count = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
if( my_inscription_count <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'identifiant d'inscription est invalide")
|
|
return False, "L'identifiant d'inscription est invalide"
|
|
|
|
|
|
data_mail = {}
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'email': str(diction['email']),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_class_code']:
|
|
lms_class_code = local_inscription[0]['lms_class_code']
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_user_id']:
|
|
lms_user_id = local_inscription[0]['lms_user_id']
|
|
|
|
nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
nom = local_inscription[0]['nom']
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
prenom = local_inscription[0]['prenom']
|
|
|
|
email = ""
|
|
if ("email" in local_inscription[0].keys()):
|
|
if local_inscription[0]['email']:
|
|
email = local_inscription[0]['email']
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_du']:
|
|
date_du = str(local_inscription[0]['date_du'])[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_au']:
|
|
date_au = str(local_inscription[0]['date_au'])[0:10]
|
|
|
|
# 3 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(local_inscription[0]['class_internal_url']),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
data_mail['title'] = local_class[0]['title']
|
|
class_title = local_class[0]['title']
|
|
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(local_inscription[0]['session_id'])),
|
|
'valide':'1', 'partner_owner_recid':str(partner_recid)})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les données de la session ")
|
|
return False, " Impossible de récupérer les données de la session "
|
|
|
|
# Annulation de l'inscription
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId( str(diction['inscription_id'])), 'email': str(diction['email'])},
|
|
{"$set": {'status':'-1', 'inscription_refuse_date':now, 'date_update':now,
|
|
'comment':str(diction['motif'])}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if( ret_val2 is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'annuler l'inscription ")
|
|
return False, " Impossible d'annuler l'inscription "
|
|
|
|
"""
|
|
12/10/2024 - loguer les action dans l'historique général
|
|
|
|
"""
|
|
## Add to log history pour l'inscrit 'inscription'
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(mytoken)
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(local_inscription[0]['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = ""
|
|
|
|
if ("code_session" in local_session.keys()):
|
|
local_session_info = local_session_info + ", Code Session : " + local_session["code_session"]
|
|
|
|
history_event_dict['action_description'] = "Refus inscription à " + str(local_session_info)
|
|
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))
|
|
|
|
## Add to log history pour la session 'session_formation'
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(mytoken)
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(local_session['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = ""
|
|
if ("_id" in local_inscription[0].keys()):
|
|
local_inscrit_info = "_Id Inscrit : " + str(local_inscription[0]["_id"])
|
|
if ("email" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["email"]
|
|
|
|
if ("nom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["nom"]
|
|
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Refus inscription de " + str(local_inscrit_info)
|
|
|
|
# print(" ### laaaaaaaaa history_event_dict = ", history_event_dict)
|
|
|
|
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))
|
|
|
|
"""
|
|
Verification s'il y a une inscription LMS, au quel cas, on l'annule aussi
|
|
"""
|
|
|
|
return_message = ""
|
|
|
|
if( lms_user_id.strip() != ""):
|
|
# Il a une inscription à une formation dans le LMS, il faut l'annuler
|
|
new_diction = {}
|
|
new_diction['token'] = str(diction['token'])
|
|
new_diction['user_lms_id'] = str(lms_user_id)
|
|
new_diction['course_code'] = str(lms_class_code)
|
|
|
|
local_status, local_message = mys_lms.Remove_User_From_LMS_Class(new_diction)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible de supprimer l'inscription dans le LMS pour "+str( diction['email']) )
|
|
return_message = "Impossible de supprimer l'inscription dans le LMS pour : "+str( diction['email'])
|
|
|
|
email_data = {}
|
|
email_data['nom'] = nom
|
|
email_data['prenom'] = prenom
|
|
email_data['email'] = email
|
|
email_data['date_du'] = date_du
|
|
email_data['date_au'] = date_au
|
|
email_data['title'] = class_title
|
|
email_data['comment'] = str(diction['motif'])
|
|
email_data['partner_owner_recid'] = str(partner_recid)
|
|
|
|
|
|
local_status, local_message = email_session.incription_training_cancelled_mail(email_data)
|
|
if( local_status is False ):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " - WARNING : Impossible d'envoyer le mail de notification pour " + str(
|
|
diction['email']))
|
|
return_message = return_message + str(" Impossible d'envoyer le mail de notification pour : " + str(diction['email']))
|
|
|
|
if( return_message.strip() != ""):
|
|
return True, return_message
|
|
|
|
|
|
|
|
return True, "L'inscription a été correctement annulé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 d'annuler l'inscription"
|
|
|
|
|
|
"""
|
|
Cette fonction refuse les inscription en mase avec un motif
|
|
"""
|
|
|
|
"""
|
|
Cette fonction une liste d'inscrit à une session de formation
|
|
"""
|
|
def Refuse_List_AttendeeInscription_with_motif(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'list_inscription_id', 'motif']
|
|
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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
list_inscription_id = []
|
|
if ("list_inscription_id" in diction.keys()):
|
|
if diction['list_inscription_id']:
|
|
list_inscription_id = str(diction['list_inscription_id']).replace(",", ";").split(";")
|
|
|
|
for inscription_id in list_inscription_id:
|
|
"""
|
|
# Verification que l'inscription existe et qu'elle est valide et qu'elle est au statut : en cours (status =2) ou
|
|
preinscrit (status = 0) ou validé (status = 1)
|
|
"""
|
|
ret_val2_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid':str(my_partner['recid']),
|
|
},
|
|
)
|
|
|
|
if (ret_val2_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + "L'identifiant de l'inscription "+ str(inscription_id) +" n'est pas valide ")
|
|
return False, " L'identifiant de l'inscription "+ str(inscription_id) +" n'est pas valide "
|
|
|
|
inscription_id_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid': str(my_partner['recid']),
|
|
},
|
|
)
|
|
|
|
if( "status" not in inscription_id_data.keys() or inscription_id_data['status'] not in ['0', '2', '1']):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Toutes les inscriptions doivent être au statut : en cours ou preinscription ")
|
|
return False, " Toutes les inscriptions doivent être au statut : en cours ou preinscription "
|
|
|
|
|
|
# Verifier que la session de formation concernée est valide
|
|
is_valide_session = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(inscription_id_data['session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if (is_valide_session != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session de formation "+ str(inscription_id_data['session_id']) +" n'est pas valide ")
|
|
return False, " L'identifiant de la session de formation "+ str(inscription_id_data['session_id']) +" n'est pas valide "
|
|
|
|
|
|
|
|
# A present les controles sont ok sur la liste on peut valide la liste des inscription
|
|
warning_msg = ""
|
|
is_warning = ""
|
|
for inscription_id in list_inscription_id:
|
|
|
|
inscription_id_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid': str(my_partner['recid']),
|
|
'status':{'$in':['0', '1', '2']}
|
|
},
|
|
)
|
|
|
|
print(" ### inscription_id_data = ",inscription_id_data)
|
|
if( inscription_id_data ):
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['motif'] = diction['motif']
|
|
new_diction['inscription_id'] = str(inscription_id_data['_id'])
|
|
new_diction['email'] = str(inscription_id_data['email'])
|
|
|
|
#print(" ### new_diction = ",new_diction)
|
|
|
|
local_status, local_retval = RefuseAttendeeInscription_with_motif(new_diction)
|
|
if( local_status is False ):
|
|
is_warning = "1"
|
|
warning_msg = warning_msg + "\n"+str(local_retval)
|
|
|
|
if( is_warning == "1" ):
|
|
return True, str(warning_msg)
|
|
|
|
return True, "La liste des inscriptions a été refusé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 refuser la liste des inscriptions"
|
|
|
|
|
|
"""
|
|
26/05/2025 : Gestion Formation initiale
|
|
Si il s'agit d'une inscription à une formation initiale, alors
|
|
on créer le contenu des collection :
|
|
- inscription_liste_ue : Dans cette collection on les UE auxquelles l'apprenant est inscrit
|
|
- inscription_liste_ue_type_eval : Dans cette collection on a types d'evaluation que doit passer un apprenant sur une UE
|
|
==> Cela permet de gerer par exemple les personne qui s'inscrivent juste pour passer l'exemple final, ou juste les project
|
|
etc.
|
|
|
|
/!\ Pour determiner si une inscription concerne la formation initiale, on regarde si le compte utilisateur qui
|
|
valide l'inscription est un compte de 'formation initiale'
|
|
|
|
|
|
cette fonction prend en entrée :
|
|
- inscription_id
|
|
- class_id
|
|
|
|
|
|
"""
|
|
def Init_AcceptAttendeeInscription_For_Initial_Formation(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'inscription_id', 'class_id', 'tab_ue_ids']
|
|
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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
formation_initiale = "0"
|
|
if( "formation_initiale" in my_partner.keys() ):
|
|
formation_initiale = my_partner['formation_initiale']
|
|
|
|
if( formation_initiale != "1"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il ne s'agit pas d'un formation initiale ")
|
|
return True, " Il ne s'agit pas d'un formation initiale "
|
|
|
|
|
|
"""
|
|
Verifier que l'inscription est valide
|
|
"""
|
|
is_valide_inscription_count = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(diction['inscription_id']),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if( is_valide_inscription_count != 1) :
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
|
return False, " L'identifiant de l'inscrit est invalide "
|
|
|
|
|
|
"""
|
|
Verifier la validité de la formation et créer le contenu de la collection
|
|
"""
|
|
is_valide_class_count = MYSY_GV.dbname['myclass'].count_documents(
|
|
{'_id': ObjectId(diction['class_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked':'0'})
|
|
|
|
if (is_valide_class_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la formation est invalide ")
|
|
return False, " L'identifiant de la formation est invalide "
|
|
|
|
|
|
"""
|
|
Suppression des données existe dans les collections : inscription_liste_ue et inscription_liste_ue_type_eval
|
|
pour l'inscrit et la formation conernée
|
|
"""
|
|
|
|
clean_inscription_liste_ue = MYSY_GV.dbname['inscription_liste_ue'].delete_many({"partner_owner_recid": str(my_partner['recid']),
|
|
'class_id': str(diction['class_id']), 'inscription_id': str(diction['inscription_id']), })
|
|
|
|
clean_inscription_liste_ue_type_eval = MYSY_GV.dbname['inscription_liste_ue_type_evalution'].delete_many(
|
|
{"partner_owner_recid": str(my_partner['recid']),
|
|
'class_id': str(diction['class_id']), 'inscription_id': str(diction['inscription_id']), })
|
|
|
|
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)
|
|
|
|
"""
|
|
Recuperer les UE de la formation
|
|
"""
|
|
tab_class_ue_id = []
|
|
|
|
qry = {"partner_owner_recid": str(my_partner['recid']), 'valide': '1', 'locked': '0',
|
|
'_id': ObjectId(str(diction['class_id']))}
|
|
|
|
|
|
"""
|
|
Remplissage de la collection : inscription_liste_ue
|
|
"""
|
|
for New_retVal in MYSY_GV.dbname['myclass'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
|
if( "list_unite_enseignement" in New_retVal.keys() ):
|
|
for local_val in New_retVal['list_unite_enseignement'] :
|
|
|
|
if( "tab_ue_ids" not in diction.keys() ):
|
|
tab_class_ue_id.append(str(local_val['_id']))
|
|
|
|
new_data = {}
|
|
new_data['inscription_id'] = str(diction['inscription_id'])
|
|
new_data['class_id'] = str(diction['class_id'])
|
|
new_data['class_eu_id'] = str(local_val['_id'])
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
|
|
key_data = {}
|
|
key_data['inscription_id'] = str(diction['inscription_id'])
|
|
key_data['class_id'] = str(diction['class_id'])
|
|
key_data['class_eu_id'] = str(local_val['_id'])
|
|
key_data['valide'] = "1"
|
|
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
|
|
result = MYSY_GV.dbname['inscription_liste_ue'].find_one_and_update(
|
|
key_data,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de valider l'inscription pour la formation initiale (2) ")
|
|
return False, "Impossible de valider l'inscription pour la formation initiale (2) "
|
|
|
|
elif ("tab_ue_ids" in diction.keys() and str(local_val['_id']) in tab_ue_ids ):
|
|
print(" ### traitement inscription PARTIEL UEEE ", str(local_val['_id']))
|
|
|
|
tab_class_ue_id.append(str(local_val['_id']))
|
|
|
|
new_data = {}
|
|
new_data['inscription_id'] = str(diction['inscription_id'])
|
|
new_data['class_id'] = str(diction['class_id'])
|
|
new_data['class_eu_id'] = str(local_val['_id'])
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
key_data = {}
|
|
key_data['inscription_id'] = str(diction['inscription_id'])
|
|
key_data['class_id'] = str(diction['class_id'])
|
|
key_data['class_eu_id'] = str(local_val['_id'])
|
|
key_data['valide'] = "1"
|
|
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
result = MYSY_GV.dbname['inscription_liste_ue'].find_one_and_update(
|
|
key_data,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de valider l'inscription pour la formation initiale (2) ")
|
|
return False, "Impossible de valider l'inscription pour la formation initiale (2) "
|
|
|
|
|
|
"""
|
|
Remplissage de la collection : inscription_liste_ue_type_eval
|
|
"""
|
|
|
|
for val in MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].find({'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'class_id':str(diction['class_id'])}):
|
|
new_data = {}
|
|
new_data['inscription_id'] = str(diction['inscription_id'])
|
|
new_data['class_id'] = str(diction['class_id'])
|
|
new_data['class_eu_id'] = str(val['class_ue_id'])
|
|
new_data['type_evaluation_id'] = str(val['type_evaluation_id'])
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
key_data = {}
|
|
key_data['inscription_id'] = str(diction['inscription_id'])
|
|
key_data['class_id'] = str(diction['class_id'])
|
|
key_data['class_eu_id'] = str(local_val['_id'])
|
|
key_data['valide'] = "1"
|
|
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
result = MYSY_GV.dbname['inscription_liste_ue_type_evalution'].find_one_and_update(
|
|
key_data,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de valider l'inscription pour la formation initiale (2) ")
|
|
return False, "Impossible de valider l'inscription pour la formation initiale (2) "
|
|
|
|
|
|
return True, "L'inscription a été correctement validé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 valider l'inscription pour la formation initiale"
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour de la liste des evaluations et type d'evaluation
|
|
auxquels sont inscrit un apprenant
|
|
"""
|
|
|
|
|
|
def Update_AcceptAttendeeInscription_For_Initial_Formation(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'inscription_id', 'class_id', 'list_eu', 'list_eu_eval']
|
|
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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
formation_initiale = "0"
|
|
if ("formation_initiale" in my_partner.keys()):
|
|
formation_initiale = my_partner['formation_initiale']
|
|
|
|
if (formation_initiale != "1"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il ne s'agit pas d'un formation initiale ")
|
|
return True, " Il ne s'agit pas d'un formation initiale "
|
|
|
|
|
|
"""
|
|
Recuper la liste des UE
|
|
"""
|
|
list_eu_json = ast.literal_eval(diction['list_eu'])
|
|
|
|
"""
|
|
Recuper la liste des evaluations UE
|
|
"""
|
|
list_eu_eval_json = ast.literal_eval(diction['list_eu_eval'])
|
|
|
|
print(" ### list_eu_json = ", list_eu_json)
|
|
|
|
print(" ### list_eu_eval_json = ", list_eu_eval_json)
|
|
|
|
# Verifier que la nouvelle liste des UE est valide et appartient bien à la formation.
|
|
for local_val in list_eu_json:
|
|
is_ue_include_in_class_count = MYSY_GV.dbname['myclass'].count_documents({'valide':'1','locked':'0',
|
|
'partner_owner_recid':my_partner['recid'],
|
|
'list_unite_enseignement._id':str(local_val['_id']),
|
|
'_id':ObjectId(str(diction['class_id']))})
|
|
|
|
if( is_ue_include_in_class_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'UE "+str(local_val)+" n'est pas valide ")
|
|
return True, " L'identifiant de l'UE "+str(local_val['_id'])+" n'est pas valide "
|
|
|
|
is_ue_valide = MYSY_GV.dbname['unite_enseignement'].count_documents({'_id':ObjectId(str(local_val['_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':my_partner['recid']})
|
|
|
|
|
|
if( is_ue_valide != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'UE " + str(local_val) + " n'est pas valide (2) ")
|
|
return True, " L'identifiant de l'UE " + str(local_val['_id']) + " n'est pas valide (2)"
|
|
|
|
|
|
|
|
"""
|
|
Verifier que les types d'evaluations sont valides pour les ue
|
|
"""
|
|
for local_val in list_eu_eval_json:
|
|
|
|
is_evaluation_ok_for_class_and_ue = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].count_documents({'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': my_partner[ 'recid'],
|
|
'class_id': str(diction['class_id']),
|
|
'_id': ObjectId( str(local_val['_id']))})
|
|
|
|
if (is_evaluation_ok_for_class_and_ue != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du type d'evaluation " + str(local_val) + " n'est pas valide ")
|
|
return True, " L'identifiant du type d'evaluation " + str(local_val['_id']) + " n'est pas valide "
|
|
|
|
|
|
|
|
"""
|
|
Verifier que l'inscription est valide
|
|
"""
|
|
is_valide_inscription_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(diction['inscription_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_inscription_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
|
return False, " L'identifiant de l'inscrit est invalide "
|
|
|
|
"""
|
|
Verifier la validité de la formation et créer le contenu de la collection
|
|
"""
|
|
is_valide_class_count = MYSY_GV.dbname['myclass'].count_documents(
|
|
{'_id': ObjectId(diction['class_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_class_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la formation est invalide ")
|
|
return False, " L'identifiant de la formation est invalide "
|
|
|
|
"""
|
|
Suppression des données existe dans les collections : inscription_liste_ue et inscription_liste_ue_type_eval
|
|
pour l'inscrit et la formation conernée
|
|
"""
|
|
|
|
clean_inscription_liste_ue = MYSY_GV.dbname['inscription_liste_ue'].delete_many(
|
|
{"partner_owner_recid": str(my_partner['recid']),
|
|
'class_id': str(diction['class_id']), 'inscription_id': str(diction['inscription_id']), })
|
|
|
|
|
|
qry_del = {"partner_owner_recid": str(my_partner['recid']),
|
|
'class_id': str(diction['class_id']), 'inscription_id': str(diction['inscription_id']) }
|
|
|
|
#print(' qry_delete === ', qry_del)
|
|
|
|
clean_inscription_liste_ue_type_eval = MYSY_GV.dbname['inscription_liste_ue_type_evalution'].delete_many(qry_del)
|
|
|
|
#mycommon.myprint( " ela-Token - " + str(clean_inscription_liste_ue_type_eval.deleted_count) + " documents deleted. ")
|
|
|
|
"""
|
|
Recuperer les UE de la formation
|
|
"""
|
|
tab_class_ue_id = []
|
|
|
|
qry = {"partner_owner_recid": str(my_partner['recid']), 'valide': '1', 'locked': '0',
|
|
'_id': ObjectId(str(diction['class_id']))}
|
|
|
|
"""
|
|
Remplissage de la collection : inscription_liste_ue
|
|
"""
|
|
|
|
for New_retVal in list_eu_json:
|
|
|
|
tab_class_ue_id.append(str(local_val['_id']))
|
|
|
|
new_data = {}
|
|
new_data['inscription_id'] = str(diction['inscription_id'])
|
|
new_data['class_id'] = str(diction['class_id'])
|
|
new_data['class_eu_id'] = str(New_retVal['_id'])
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
key_data = {}
|
|
key_data['inscription_id'] = str(diction['inscription_id'])
|
|
key_data['class_id'] = str(diction['class_id'])
|
|
key_data['class_eu_id'] = str(New_retVal['_id'])
|
|
key_data['valide'] = "1"
|
|
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
result = MYSY_GV.dbname['inscription_liste_ue'].find_one_and_update(
|
|
key_data,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour la liste des UE de l'inscrit (2) ")
|
|
return False, "Impossible de mettre à jour la liste des UE de l'inscrit (2) "
|
|
|
|
"""
|
|
Remplissage de la collection : inscription_liste_ue_type_eval
|
|
"""
|
|
|
|
for val in list_eu_eval_json:
|
|
new_data = {}
|
|
new_data['inscription_id'] = str(diction['inscription_id'])
|
|
new_data['class_id'] = str(diction['class_id'])
|
|
new_data['class_eu_id'] = str(val['class_ue_id'])
|
|
new_data['type_evaluation_id'] = str(val['type_evaluation_id'])
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
key_data = {}
|
|
key_data['inscription_id'] = str(diction['inscription_id'])
|
|
key_data['class_id'] = str(diction['class_id'])
|
|
key_data['class_eu_id'] = str(local_val['_id'])
|
|
key_data['valide'] = "1"
|
|
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
result = MYSY_GV.dbname['inscription_liste_ue_type_evalution'].find_one_and_update(
|
|
key_data,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour les UE et Evaluations de l'apprenant (2) ")
|
|
return False, "Impossible de mettre à jour les UE et Evaluations de l'apprenant (2) "
|
|
|
|
return True, "La mise à jour a été correctement faite"
|
|
|
|
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 mettre à jour les UE et Evaluations de l'apprenant "
|
|
|
|
|
|
"""
|
|
Fontion de validation / acceptation d'une inscription
|
|
|
|
23/07/2024 :
|
|
A la validation, on regarde si l'inscription a un 'client_rattachement_id' alors on considère qu'il
|
|
s'agit d'une inscription pour un client, on met le champ 'entreprise' à '1', si non à '0'
|
|
|
|
"""
|
|
def AcceptAttendeeInscription(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'inscription_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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
# 0 - Verifier de l'existance et de la validité de l'inscription (preinscription à refuser)
|
|
my_inscription_count = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
if( my_inscription_count <= 0 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'identifiant d'inscription est invalide")
|
|
return False, "L'identifiant d'inscription est invalide"
|
|
|
|
|
|
data_mail = {}
|
|
|
|
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'email': str(diction['email']),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
entreprise = "0"
|
|
if ("client_rattachement_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['client_rattachement_id']:
|
|
entreprise = "1"
|
|
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_class_code']:
|
|
lms_class_code = local_inscription[0]['lms_class_code']
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_user_id']:
|
|
lms_user_id = local_inscription[0]['lms_user_id']
|
|
|
|
nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
nom = local_inscription[0]['nom']
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
prenom = local_inscription[0]['prenom']
|
|
|
|
email = ""
|
|
if ("email" in local_inscription[0].keys()):
|
|
if local_inscription[0]['email']:
|
|
email = local_inscription[0]['email']
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_du']:
|
|
date_du = str(local_inscription[0]['date_du'])[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_au']:
|
|
date_au = str(local_inscription[0]['date_au'])[0:10]
|
|
|
|
# 3 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(local_inscription[0]['class_internal_url']),
|
|
'partner_owner_recid':str(partner_recid)})
|
|
data_mail['title'] = local_class[0]['title']
|
|
class_title = local_class[0]['title']
|
|
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(local_inscription[0]['session_id'])),
|
|
'valide':'1', 'partner_owner_recid':str(partner_recid)})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les données de la session ")
|
|
return False, " Impossible de récupérer les données de la session "
|
|
|
|
lms_class_code = ""
|
|
if( "lms_class_code" in local_class[0].keys() ):
|
|
if(len(str(local_class[0]['lms_class_code'])) > 2 ):
|
|
lms_class_code = str(local_class[0]['lms_class_code'])
|
|
|
|
|
|
session_end_date = ""
|
|
if( "date_fin" in local_session.keys() ):
|
|
session_end_date = str(local_session['date_fin']).strip()[0:10]
|
|
|
|
""""
|
|
Inscription sur le LMS :
|
|
Si la formation associée à la session possede un code de formation lms 'lms_class_code'
|
|
|
|
Alors cela veut dire que c'est une formation qui est gérée avec le LMS de MYSY.
|
|
Donc l'inscription va generer :
|
|
1 - La creation du compte LMS participant
|
|
2 - L'inscription de l'utilisateur à la formation.
|
|
|
|
"""
|
|
return_message = " Inscription validée avec warning : "
|
|
is_warning_message = 0
|
|
|
|
if( str(lms_class_code) != ""):
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['lastname'] = nom
|
|
new_diction['firstname'] = prenom
|
|
new_diction['email'] = email
|
|
new_diction['password'] = secrets.token_urlsafe(6)
|
|
new_diction['locked'] = "0"
|
|
new_diction['username'] = email
|
|
new_diction['session_end_date'] = session_end_date
|
|
|
|
# 01/02/2025 : gestion date fin validité compte lms. Par defaut la session est active 30 jours apres la fin de la session
|
|
local_session_end_date = datetime.strptime(str(session_end_date).strip(), '%d/%m/%Y')
|
|
local_lms_access_end_date = local_session_end_date+timedelta(days=30)
|
|
local_lms_access_end_date_formated = str(local_lms_access_end_date.strftime("%d/%m/%Y"))
|
|
|
|
|
|
local_status, local_message, local_participant_lms_id = mys_lms.Create_MySy_LMS_Apprenant(new_diction)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " WARNING : le compte LSM n'a pas été correctement crée")
|
|
return_message = return_message + " - Le compte LSM n'a pas été correctement crée. \n"
|
|
is_warning_message = 1
|
|
else:
|
|
"""
|
|
Mettre à jour la collection "inscription" en ajoutant local_participant_lms_id et et le mot de passe
|
|
et la date d'expiration du compte LMS
|
|
"""
|
|
print(" ### Mise à jour 'inscription' pour inscription_line_id = ", str(diction['inscription_id']),
|
|
" local_participant_lms_id = ", local_participant_lms_id, " str(new_diction['password'] ",
|
|
str(new_diction['password']), " lms_account_expiration_date = ",local_lms_access_end_date_formated )
|
|
local_ret_val = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['inscription_id'])), 'partner_owner_recid':str(my_partner['recid'])},
|
|
{"$set": {'lms_user_id': str(local_participant_lms_id),
|
|
'lms_pwd': str(new_diction['password']),
|
|
'lms_class_code': str(lms_class_code),
|
|
'lms_account_expiration_date':str(local_lms_access_end_date_formated)}
|
|
},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if (local_ret_val and local_ret_val['_id']):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Le compte LMS du participant a été correctement mis à jour : local_ret_val['_id'] = " + str(
|
|
local_ret_val['_id']))
|
|
""""
|
|
A present, on va proceder à l'inscription à la formation
|
|
"""
|
|
print(" ### Debut de l'inscription à la formation dans le LMS ")
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['user_lms_id'] = local_participant_lms_id
|
|
new_diction['course_code'] = lms_class_code
|
|
|
|
local_status2, local_message2 = mys_lms.Add_User_To_LMS_Class(new_diction)
|
|
if (local_status2 is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : Impossbile de finaliser l'inscription dans le LMS")
|
|
return_message = return_message + " - Impossbile de finaliser l'inscription dans le LMS. "+str(local_message2)+" \n"
|
|
is_warning_message = 1
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " TOP, l'inscription dans le LMS a ete correctement faite")
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - WARNING : Impossible de mettre à jour le compte LMS ")
|
|
return_message = return_message + " - Impossible de mettre à jour le compte LMS. \n"
|
|
is_warning_message = 1
|
|
|
|
|
|
|
|
# date de validation de l'inscription
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId( str(diction['inscription_id'])), 'email': str(diction['email']), 'partner_owner_recid':str(my_partner['recid'])},
|
|
{"$set": {'status':'1', 'inscription_validation_date':now, 'date_update':now, 'entreprise':str(entreprise)
|
|
}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if( ret_val2 is None ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de valider l'inscription (1) ")
|
|
return False, " Impossible de valider l'inscription (2) "
|
|
|
|
"""
|
|
Verification s'il y a une inscription LMS, au quel cas, on l'annule aussi
|
|
"""
|
|
|
|
"""
|
|
26/02/2025 :
|
|
Si le paramettre, 'inscription_notification_email' de la collection 'base_partner_setup' est à 1,
|
|
alors on envoie un email de notification à l'apprenant
|
|
"""
|
|
local_insc_status, local_insc_retval = mycommon.Is_Partnair_Inscription_Notification({'token':diction['token']})
|
|
if( local_insc_status and str(local_insc_retval) == "1"):
|
|
email_data = {}
|
|
email_data['nom'] = nom
|
|
email_data['prenom'] = prenom
|
|
email_data['email'] = email
|
|
email_data['date_du'] = date_du
|
|
email_data['date_au'] = date_au
|
|
email_data['title'] = class_title
|
|
email_data['partner_owner_recid'] = str(partner_recid)
|
|
|
|
if( "code_session" in local_session.keys()):
|
|
email_data['code_session'] = local_session['code_session']
|
|
else:
|
|
email_data['code_session'] = ""
|
|
|
|
if ("date_debut" in local_session.keys()):
|
|
email_data['date_debut'] = local_session['date_debut']
|
|
else:
|
|
email_data['date_debut'] = ""
|
|
|
|
if ("distantiel" in local_session.keys()):
|
|
email_data['distantiel'] = local_session['distantiel']
|
|
else:
|
|
email_data['distantiel'] = ""
|
|
|
|
if ("presentiel" in local_session.keys()):
|
|
email_data['presentiel'] = local_session['presentiel']
|
|
else:
|
|
email_data['presentiel'] = ""
|
|
|
|
if ("session_ondemande" in local_session.keys()):
|
|
email_data['session_ondemande'] = local_session['session_ondemande']
|
|
else:
|
|
email_data['session_ondemande'] = ""
|
|
|
|
if ("adresse" in local_session.keys()):
|
|
email_data['adresse'] = local_session['adresse']
|
|
else:
|
|
email_data['adresse'] = ""
|
|
|
|
if ("code_postal" in local_session.keys()):
|
|
email_data['code_postal'] = local_session['code_postal']
|
|
else:
|
|
email_data['code_postal'] = ""
|
|
|
|
if ("ville" in local_session.keys()):
|
|
email_data['ville'] = local_session['ville']
|
|
else:
|
|
email_data['ville'] = ""
|
|
|
|
if ("pays" in local_session.keys()):
|
|
email_data['pays'] = local_session['pays']
|
|
else:
|
|
email_data['pays'] = ""
|
|
|
|
if ("formateur" in local_session.keys()):
|
|
email_data['formateur'] = local_session['formateur']
|
|
else:
|
|
email_data['formateur'] = ""
|
|
|
|
if ("ville" in local_session.keys()):
|
|
email_data['ville'] = local_session['ville']
|
|
else:
|
|
email_data['ville'] = ""
|
|
|
|
|
|
local_status, local_message = email_session.incription_training_confirmation_mail(email_data)
|
|
if( local_status is False ):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " - WARNING : Impossible d'envoyer le mail de notification pour " + str(
|
|
diction['email']))
|
|
return_message = return_message + str(" - Impossible d'envoyer le mail de notification pour : " + str(diction['email'])+" \n")
|
|
is_warning_message = 1
|
|
|
|
|
|
|
|
|
|
"""
|
|
A présent que l'inscription s'est bien passée, on va créer le dossier apprenant
|
|
"""
|
|
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId( str(diction['inscription_id'])),
|
|
'email': str(diction['email']),
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
new_apprenant_diction = {}
|
|
new_apprenant_diction['token'] = str(diction['token'])
|
|
new_apprenant_diction['nom'] = inscription_data['nom']
|
|
new_apprenant_diction['email'] = inscription_data['email']
|
|
new_apprenant_diction['prenom'] = inscription_data['prenom']
|
|
|
|
if( "civilite" in inscription_data.keys()):
|
|
new_apprenant_diction['civilite'] = str(inscription_data['civilite']).lower()
|
|
else:
|
|
new_apprenant_diction['civilite'] = ""
|
|
|
|
if (str(new_apprenant_diction['civilite']) not in MYSY_GV.CIVILITE):
|
|
new_apprenant_diction['civilite'] = "neutre"
|
|
|
|
if("telephone" in inscription_data.keys()):
|
|
new_apprenant_diction['telephone'] = inscription_data['telephone']
|
|
else:
|
|
new_apprenant_diction['telephone'] = ""
|
|
|
|
if ("employeur" in inscription_data.keys()):
|
|
new_apprenant_diction['employeur'] = inscription_data['employeur']
|
|
else:
|
|
new_apprenant_diction['employeur'] = ""
|
|
|
|
if("client_rattachement_id" in inscription_data.keys()):
|
|
new_apprenant_diction['client_rattachement_id'] = inscription_data['client_rattachement_id']
|
|
else:
|
|
new_apprenant_diction['client_rattachement_id'] = ""
|
|
|
|
|
|
if("adresse" in inscription_data.keys()):
|
|
new_apprenant_diction['adresse'] = inscription_data['adresse']
|
|
else:
|
|
new_apprenant_diction['adresse'] = ""
|
|
|
|
|
|
if("code_postal" in inscription_data.keys()):
|
|
new_apprenant_diction['code_postal'] = inscription_data['code_postal']
|
|
else:
|
|
new_apprenant_diction['code_postal'] = ""
|
|
|
|
if("ville" in inscription_data.keys()):
|
|
new_apprenant_diction['ville'] = inscription_data['ville']
|
|
else:
|
|
new_apprenant_diction['ville'] = ""
|
|
|
|
if("pays" in inscription_data.keys()):
|
|
new_apprenant_diction['pays'] = inscription_data['pays']
|
|
else:
|
|
new_apprenant_diction['pays'] = ""
|
|
|
|
if("tuteur1_nom" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_nom'] = inscription_data['tuteur1_nom']
|
|
else:
|
|
new_apprenant_diction['tuteur1_nom'] = ""
|
|
|
|
if("tuteur1_prenom" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_prenom'] = inscription_data['tuteur1_prenom']
|
|
else:
|
|
new_apprenant_diction['tuteur1_prenom'] = ""
|
|
|
|
if("tuteur1_email" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_email'] = inscription_data['tuteur1_email']
|
|
else:
|
|
new_apprenant_diction['tuteur1_email'] = ""
|
|
|
|
if("tuteur1_telephone" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_telephone'] = inscription_data['tuteur1_telephone']
|
|
else:
|
|
new_apprenant_diction['tuteur1_telephone'] = ""
|
|
|
|
if ("tuteur1_civilite" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_civilite'] = inscription_data['tuteur1_civilite']
|
|
else:
|
|
new_apprenant_diction['tuteur1_civilite'] = ""
|
|
|
|
if ("tuteur2_civilite" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_civilite'] = inscription_data['tuteur2_civilite']
|
|
else:
|
|
new_apprenant_diction['tuteur2_civilite'] = ""
|
|
|
|
|
|
if("tuteur2_nom" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_nom'] = inscription_data['tuteur2_nom']
|
|
else:
|
|
new_apprenant_diction['tuteur2_nom'] = ""
|
|
|
|
if("tuteur2_email" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_prenom'] = inscription_data['tuteur2_email']
|
|
else:
|
|
new_apprenant_diction['tuteur2_prenom'] = ""
|
|
|
|
|
|
if("tuteur2_email" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_email'] = inscription_data['tuteur2_email']
|
|
else:
|
|
new_apprenant_diction['tuteur2_email'] = ""
|
|
|
|
if ("tuteur2_telephone" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_telephone'] = inscription_data['tuteur2_telephone']
|
|
else:
|
|
new_apprenant_diction['tuteur2_telephone'] = ""
|
|
|
|
|
|
if ("opco" in inscription_data.keys()):
|
|
new_apprenant_diction['opco'] = inscription_data['opco']
|
|
else:
|
|
new_apprenant_diction['opco'] = ""
|
|
|
|
if ("tuteur1_adresse" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_adresse'] = inscription_data['tuteur1_adresse']
|
|
else:
|
|
new_apprenant_diction['tuteur1_adresse'] = ""
|
|
|
|
if ("tuteur1_cp" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_cp'] = inscription_data['tuteur1_cp']
|
|
else:
|
|
new_apprenant_diction['tuteur1_cp'] = ""
|
|
|
|
if ("tuteur1_ville" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_ville'] = inscription_data['tuteur1_ville']
|
|
else:
|
|
new_apprenant_diction['tuteur1_ville'] = ""
|
|
|
|
if ("tuteur1_pays" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_pays'] = inscription_data['tuteur1_pays']
|
|
else:
|
|
new_apprenant_diction['tuteur1_pays'] = ""
|
|
|
|
if ("tuteur1_include_com" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur1_include_com'] = inscription_data['tuteur1_include_com']
|
|
else:
|
|
new_apprenant_diction['tuteur1_include_com'] = "0"
|
|
|
|
if ("tuteur2_adresse" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_adresse'] = inscription_data['tuteur2_adresse']
|
|
else:
|
|
new_apprenant_diction['tuteur2_adresse'] = ""
|
|
|
|
if ("tuteur2_cp" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_cp'] = inscription_data['tuteur2_cp']
|
|
else:
|
|
new_apprenant_diction['tuteur2_cp'] = ""
|
|
|
|
if ("tuteur2_ville" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_ville'] = inscription_data['tuteur2_ville']
|
|
else:
|
|
new_apprenant_diction['tuteur2_ville'] = ""
|
|
|
|
|
|
if ("tuteur2_pays" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_pays'] = inscription_data['tuteur2_pays']
|
|
else:
|
|
new_apprenant_diction['tuteur2_pays'] = ""
|
|
|
|
if ("tuteur2_include_com" in inscription_data.keys()):
|
|
new_apprenant_diction['tuteur2_include_com'] = inscription_data['tuteur2_include_com']
|
|
else:
|
|
new_apprenant_diction['tuteur2_include_com'] = "0"
|
|
|
|
"""
|
|
# Si la personne de cette inscription existe deja dans la collection appenant, alors on fait une mise à jour.
|
|
En effet si l'apprenant avait deja suivi une formation, alors il a forcement un dossier.
|
|
a clé est toujours l'adresse email
|
|
"""
|
|
local_apprenant_id = ""
|
|
is_apprenant_existe_count = MYSY_GV.dbname['apprenant'].count_documents({'email':str(inscription_data['email']),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
|
|
|
|
if( is_apprenant_existe_count > 0 ):
|
|
# Il faut mettre à jour un dossier apprenant
|
|
is_apprenant_existe = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'email': str(inscription_data['email']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'}, {'_id':1})
|
|
|
|
new_apprenant_diction['_id'] = str(is_apprenant_existe['_id'])
|
|
local_apprenant_id = str(is_apprenant_existe['_id'])
|
|
|
|
if ("tab_ue_ids" in new_apprenant_diction.keys()):
|
|
del new_apprenant_diction['tab_ue_ids']
|
|
|
|
local_status, local_retval = apprenant_mgt.Update_Apprenant(new_apprenant_diction)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
else:
|
|
# Il faut créer un dossier apprenant
|
|
if ("tab_ue_ids" in new_apprenant_diction.keys()):
|
|
del new_apprenant_diction['tab_ue_ids']
|
|
|
|
local_status, local_retval = apprenant_mgt.Add_Apprenant(new_apprenant_diction)
|
|
if( local_status is False):
|
|
return local_status, local_retval
|
|
"""
|
|
recuperation de l'id du dossier qui vient d'etre créer
|
|
"""
|
|
apprenant_data = MYSY_GV.dbname['apprenant'].find_one({'email': str(inscription_data['email']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'_id': 1})
|
|
|
|
if (apprenant_data is None):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Impossible de récuperer l'identifiant du dossier créé ")
|
|
return False, " Impossible de récuperer l'identifiant du dossier créé "
|
|
|
|
local_apprenant_id = str(apprenant_data['_id'])
|
|
|
|
|
|
"""
|
|
Apres la creation du dossier on met à jour l'inscription en rajoutant l'apprenant_id
|
|
"""
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['inscription_id'])), 'email': str(diction['email']), 'partner_owner_recid':str(my_partner['recid'])},
|
|
{"$set": {'apprenant_id': str(local_apprenant_id), 'date_update':str(datetime.now()),
|
|
'update_by':str(my_partner['_id'])}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
"""
|
|
12/10/2024 - loguer les action dans l'historique général
|
|
|
|
"""
|
|
## Add to log history pour l'inscrit 'inscription'
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(mytoken)
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(diction['inscription_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = ""
|
|
|
|
if( "code_session" in local_session.keys() ):
|
|
local_session_info = local_session_info+ ", Code Session : "+local_session["code_session"]
|
|
|
|
history_event_dict['action_description'] = "Validation inscription à "+str(local_session_info)
|
|
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))
|
|
|
|
## Add to log history pour la session 'session_formation'
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = str(mytoken)
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(local_session['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = ""
|
|
if ("_id" in local_inscription[0].keys() ):
|
|
local_inscrit_info = "_Id Inscrit : " + str(local_inscription[0]["_id"])
|
|
if ("email" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["email"]
|
|
|
|
if ("nom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["nom"]
|
|
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Validation inscription de " + str(local_inscrit_info)
|
|
|
|
#print(" ### laaaaaaaaa history_event_dict = ", history_event_dict)
|
|
|
|
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))
|
|
|
|
|
|
|
|
"""
|
|
update du 30/01/2024 :
|
|
Apres la mise à jour de l'inscription avec l'apprenant_id,
|
|
loger une action dans la collection ==> courrier_template_tracking_history
|
|
"""
|
|
|
|
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(my_partner, "CONF_INSCRIPTION",
|
|
str(ret_val2['session_id']), 'inscription', str(diction['inscription_id']), "")
|
|
|
|
|
|
|
|
if (is_warning_message == 1):
|
|
return True, return_message
|
|
|
|
return True, "L'inscription a été correctement validé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 valider l'inscription"
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction accepte une liste d'inscrit à une session de formation
|
|
"""
|
|
def Accept_List_AttendeeInscription(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'list_inscription_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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
list_inscription_id = []
|
|
if ("list_inscription_id" in diction.keys()):
|
|
if diction['list_inscription_id']:
|
|
list_inscription_id = str(diction['list_inscription_id']).replace(",", ";").split(";")
|
|
|
|
for inscription_id in list_inscription_id:
|
|
# Verification que l'inscription existe et qu'elle est valide et qu'elle est au statut : en cours (status =2) ou preinscrit (status = 0)
|
|
ret_val2_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid':str(my_partner['recid']),
|
|
},
|
|
)
|
|
|
|
if (ret_val2_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + "L'identifiant de l'inscription "+ str(inscription_id) +" n'est pas valide ")
|
|
return False, " L'identifiant de l'inscription "+ str(inscription_id) +" n'est pas valide "
|
|
|
|
inscription_id_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid': str(my_partner['recid']),
|
|
},
|
|
)
|
|
|
|
if( "status" not in inscription_id_data.keys() or inscription_id_data['status'] not in ['0', '2', '1']):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Toutes les inscriptions doivent être au statut : en cours ou preinscription ")
|
|
return False, " Toutes les inscriptions doivent être au statut : en cours ou preinscription "
|
|
|
|
|
|
# Verifier que la session de formation concernée est valide
|
|
is_valide_session = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(inscription_id_data['session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if (is_valide_session != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session de formation "+ str(inscription_id_data['session_id']) +" n'est pas valide ")
|
|
return False, " L'identifiant de la session de formation "+ str(inscription_id_data['session_id']) +" n'est pas valide "
|
|
|
|
|
|
|
|
# A present les controles sont ok sur la liste on peut valide la liste des inscription
|
|
warning_msg = ""
|
|
is_warning = ""
|
|
for inscription_id in list_inscription_id:
|
|
|
|
inscription_id_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)), 'partner_owner_recid': str(my_partner['recid']),
|
|
'status':{'$in':['0', '2']}
|
|
},
|
|
)
|
|
|
|
print(" ### inscription_id_data = ",inscription_id_data)
|
|
if( inscription_id_data ):
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['inscription_id'] = str(inscription_id_data['_id'])
|
|
new_diction['email'] = str(inscription_id_data['email'])
|
|
|
|
#print(" ### new_diction = ",new_diction)
|
|
|
|
local_status, local_retval = AcceptAttendeeInscription(new_diction)
|
|
if( local_status is False ):
|
|
is_warning = "1"
|
|
warning_msg = warning_msg + "\n"+str(local_retval)
|
|
|
|
if( is_warning == "1" ):
|
|
return True, str(warning_msg)
|
|
|
|
return True, "La liste des inscriptions a été validé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 valider la liste des inscriptions"
|
|
|
|
|
|
"""
|
|
Cette fonction supprime un stagiaire.
|
|
/!\ : seuls les preinscrit, ou les inscription annulés (donc status : 0 ou -1)
|
|
"""
|
|
def DeleteAttendeeInscription(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'class_internal_url', '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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
|
return False, "Impossible de récupérer le recid du partenaire"
|
|
|
|
data_mail = {}
|
|
# 1 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(diction['class_internal_url'])})
|
|
data_mail['title'] = local_class[0]['title']
|
|
class_title = local_class[0]['title']
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'email': str(diction['email']), 'class_internal_url':str(diction['class_internal_url'])})
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_class_code']:
|
|
lms_class_code = local_inscription[0]['lms_class_code']
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_user_id']:
|
|
lms_user_id = local_inscription[0]['lms_user_id']
|
|
|
|
nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
nom = local_inscription[0]['nom']
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
prenom = local_inscription[0]['prenom']
|
|
|
|
email = ""
|
|
if ("email" in local_inscription[0].keys()):
|
|
if local_inscription[0]['email']:
|
|
email = local_inscription[0]['email']
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_du']:
|
|
date_du = str(local_inscription[0]['date_du'])[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_au']:
|
|
date_au = str(local_inscription[0]['date_au'])[0:10]
|
|
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])), 'class_internal_url': str(diction['class_internal_url']), 'valide':'1',})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les données de la session ")
|
|
return False, " Impossible de récupérer les données de la session "
|
|
|
|
|
|
# Verification que l'inscription existe et qu'elle est supprimable (donc status = 0 ou -1)
|
|
ret_val2_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'session_id': str(diction['session_id']), 'email': str(diction['email']), 'class_internal_url':str(diction['class_internal_url'])},
|
|
)
|
|
|
|
if( ret_val2_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer l'inscription. Il y a plusieurs inscription pour ce mail et cette formation")
|
|
return False, " Impossible de supprimer l'inscription (1)"
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one(
|
|
{'session_id': str(diction['session_id']), 'email': str(diction['email']),
|
|
'class_internal_url': str(diction['class_internal_url'])},
|
|
)
|
|
|
|
if( "status" in ret_val2.keys()):
|
|
if( str(ret_val2['status']) != "0" and str(ret_val2['status']) != "-1"):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Impossible de supprimer l'inscription. L'inscription doit être annulée ou à l'etat 'préinscrit' avant d'être supprimé")
|
|
return False, " - Impossible de supprimer l'inscription. L'inscription doit être annulée ou à l'etat 'préinscrit' avant d'être supprimé"
|
|
|
|
|
|
|
|
"""
|
|
## Add to log history
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
# Pour la collection inscription
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = mytoken
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(local_inscription[0]['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = "Id Inscrit : " + str(local_inscription[0]['_id'])
|
|
if ("email" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["email"]
|
|
|
|
if ("nom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["nom"]
|
|
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + local_inscription[0]["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Suppression de " + str(local_inscrit_info)
|
|
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))
|
|
|
|
detlete_retval = MYSY_GV.dbname['inscription'].delete_one(
|
|
{'session_id': str(diction['session_id']), 'email': str(diction['email']),
|
|
'class_internal_url': str(diction['class_internal_url'])},
|
|
)
|
|
|
|
|
|
return True, "L'inscription 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'inscription "
|
|
|
|
|
|
"""
|
|
Fonction de suppression d'une liste de stagiaires en partant de l'_id, ceci si
|
|
les conditions sont reunies.
|
|
/!\ : seuls les preinscrit, ou les inscription annulés (donc status : 0 ou -1)
|
|
"""
|
|
def Delete_List_AttendeeInscription(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'list_inscription_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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
|
return False, "Impossible de récupérer le recid du partenaire"
|
|
|
|
list_inscription_id = []
|
|
if ("list_inscription_id" in diction.keys()):
|
|
if diction['list_inscription_id']:
|
|
list_inscription_id = str(diction['list_inscription_id']).replace(",", ";").split(";")
|
|
|
|
data_mail = {}
|
|
|
|
for inscription_id in list_inscription_id :
|
|
# Verification que l'inscription existe et qu'elle est supprimable (donc status = 0 ou -1)
|
|
ret_val2_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(inscription_id)), },
|
|
)
|
|
|
|
if( ret_val2_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer l'inscription. Il y a plusieurs inscription pour ce mail et cette formation")
|
|
return False, " Impossible de supprimer l'inscription (1)"
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)),},
|
|
)
|
|
|
|
if( "status" in ret_val2.keys()):
|
|
if( str(ret_val2['status']) != "0" and str(ret_val2['status']) != "-1"):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " - Impossible de supprimer l'inscription de l'utilisateur "+str(ret_val2['email'])+" à la session "+str(ret_val2['session_id'])+". L'inscription doit être annulée ou à l'etat 'préinscrit' avant d'être supprimé")
|
|
return False, " Impossible de supprimer l'inscription de l'utilisateur "+str(ret_val2['email'])+" à la session "+str(ret_val2['session_id'])+". L'inscription doit être annulée ou à l'etat 'préinscrit' avant d'être supprimé"
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
for inscription_id in list_inscription_id:
|
|
|
|
ret_val2 = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(inscription_id)), },
|
|
)
|
|
|
|
"""
|
|
## Add to log history
|
|
"""
|
|
|
|
# Pour la collection inscription
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = mytoken
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(ret_val2['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = "Id Inscrit : " + str(ret_val2['_id'])
|
|
if ("email" in ret_val2.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + ret_val2["email"]
|
|
|
|
if ("nom" in ret_val2.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + ret_val2["nom"]
|
|
|
|
if ("prenom" in ret_val2.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + ret_val2["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Suppression de " + str(local_inscrit_info)
|
|
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))
|
|
|
|
## pour finir on fait la suppression
|
|
|
|
detlete_retval = MYSY_GV.dbname['inscription'].delete_one(
|
|
{'_id': ObjectId(str(inscription_id)),},
|
|
)
|
|
|
|
|
|
|
|
return True, "La liste des inscriptions 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 la liste des inscriptions "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction envoie l'email de connexion à la plateformation LMS
|
|
au participant
|
|
Cet email met en copie le responsable de la formation. ceci pour pouvoir renvoyer le mail au besoin
|
|
"""
|
|
def Send_LMS_Credentials_to_particpants(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'email', 'class_internal_url', '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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
|
return False, "Impossible de récupérer le recid du partenaire"
|
|
|
|
# 0 -Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
|
return False, " - impossible de récupérer les données du partenaire"
|
|
|
|
|
|
# Par defaut, lms_virtualhost_url = l'url racine.
|
|
lms_virtualhost_url = MYSY_GV.MYSY_LMS_URL
|
|
if ("lms_virtualhost_url" in my_partner.keys()):
|
|
if my_partner['lms_virtualhost_url']:
|
|
lms_virtualhost_url = my_partner['lms_virtualhost_url']
|
|
|
|
|
|
data_mail = {}
|
|
# 1 - Recuperation des données de la formation
|
|
local_class = MYSY_GV.dbname['myclass'].find({'internal_url': str(diction['class_internal_url'])})
|
|
data_mail['title'] = local_class[0]['title']
|
|
class_title = local_class[0]['title']
|
|
|
|
# 2 - Recuperation des données de l'inscription
|
|
local_inscription = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'email': str(diction['email'])})
|
|
lms_class_code = ""
|
|
if ("lms_class_code" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_class_code']:
|
|
lms_class_code = local_inscription[0]['lms_class_code']
|
|
|
|
lms_user_id = ""
|
|
if ("lms_user_id" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_user_id']:
|
|
lms_user_id = local_inscription[0]['lms_user_id']
|
|
|
|
lms_pwd = ""
|
|
if ("lms_pwd" in local_inscription[0].keys()):
|
|
if local_inscription[0]['lms_pwd']:
|
|
lms_pwd = local_inscription[0]['lms_pwd']
|
|
|
|
nom = ""
|
|
if ("nom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['nom']:
|
|
nom = local_inscription[0]['nom']
|
|
|
|
prenom = ""
|
|
if ("prenom" in local_inscription[0].keys()):
|
|
if local_inscription[0]['prenom']:
|
|
prenom = local_inscription[0]['prenom']
|
|
|
|
email = ""
|
|
if ("email" in local_inscription[0].keys()):
|
|
if local_inscription[0]['email']:
|
|
email = local_inscription[0]['email']
|
|
|
|
date_du = ""
|
|
if ("date_du" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_du']:
|
|
date_du = str(local_inscription[0]['date_du'])[0:10]
|
|
|
|
date_au = ""
|
|
if ("date_au" in local_inscription[0].keys()):
|
|
if local_inscription[0]['date_au']:
|
|
date_au = str(local_inscription[0]['date_au'])[0:10]
|
|
|
|
# Recuperation des données de la session
|
|
local_session = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'class_internal_url': str(diction['class_internal_url']), 'valide':'1',})
|
|
|
|
if (local_session is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les données de la session ")
|
|
return False, " Impossible de récupérer les données de la session "
|
|
|
|
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
return_message = ""
|
|
email_data = {}
|
|
email_data['nom'] = nom
|
|
email_data['prenom'] = prenom
|
|
email_data['email'] = email
|
|
email_data['date_du'] = date_du
|
|
email_data['date_au'] = date_au
|
|
email_data['title'] = class_title
|
|
|
|
email_data['login'] = email
|
|
email_data['pwd'] = lms_pwd
|
|
email_data['lms_url'] = str(lms_virtualhost_url)
|
|
email_data['course_owner_email'] = my_partner['email']
|
|
email_data['partner_recid'] = my_partner['recid']
|
|
email_data['token'] = str(mytoken)
|
|
email_data['inscription_id'] = str(local_inscription[0]['_id'])
|
|
email_data['session_code'] = str(local_session['code_session'])
|
|
|
|
|
|
#split_mail_tab = str(email).split('@')
|
|
#email_data['login'] = split_mail_tab[0]
|
|
|
|
|
|
local_status, local_message = email_session.LMS_Credential_Sending_mail(email_data)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " - WARNING : Impossible d'envoyer le mail de notification pour " + str(
|
|
diction['email']))
|
|
return_message = return_message + str(
|
|
" Impossible d'envoyer le mail de notification pour : " + str(diction['email']))
|
|
|
|
if (return_message.strip() != ""):
|
|
return True, return_message
|
|
|
|
|
|
return True, " Les informations de connexion ont été correctement envoyées"
|
|
|
|
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 les informations de connexion à la plateforme LMS"
|
|
|
|
"""
|
|
Cette fonction ajoute une image de profil d'un stagaire
|
|
"""
|
|
def Update_Stagiaire_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', 'class_internal_url', 'session_id', 'email' ]
|
|
|
|
|
|
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']
|
|
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
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
|
|
|
|
## Recuperation de l'"_id" du stagiaire -- Exceptionnement on va mettre dans "_id" dans le 'related_collection_recid'
|
|
local_retval = MYSY_GV.dbname['inscription'].find_one({'class_internal_url':str(class_internal_url),
|
|
'session_id':str(session_id), 'email':str(email) })
|
|
if( local_retval is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " : Le stagiaire "+str(email)+" n'est pas reconnu pour la session bb"+str(str(session_id)) )
|
|
return False, " Le stagiaire n'est pas reconnu "
|
|
|
|
|
|
"""
|
|
A present que le partenaire est mis à jour / créé, on va mettre à jour les image logo et image cachet s'il y en a
|
|
"""
|
|
if( file_img ):
|
|
recordimage_diction = {}
|
|
recordimage_diction['token'] = diction['token']
|
|
recordimage_diction['related_collection'] = "inscription"
|
|
recordimage_diction['type_img'] = "user"
|
|
recordimage_diction['related_collection_recid'] = str(local_retval['_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 du stagiaire 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 du stagiaire"
|
|
|
|
|
|
|
|
""" Recuperation de l'image d'un stagiaire
|
|
|
|
/!\ important : on prend le 'related_collection_recid' comme le '_id' de la collection inscription
|
|
"""
|
|
def getRecodedStagiaireImage_from_front(diction=None):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'class_internal_url', 'session_id', 'email']
|
|
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', 'class_internal_url', 'session_id', 'email']
|
|
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
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
|
|
## Recuperation de l'"_id" du stagiaire -- Exceptionnement on va mettre dans "_id" dans le 'related_collection_recid'
|
|
local_retval = MYSY_GV.dbname['inscription'].find_one({'class_internal_url': str(class_internal_url),
|
|
'session_id': str(session_id),
|
|
'email': str(email)})
|
|
if (local_retval is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " : Le stagiaire " + str(
|
|
email) + " n'est pas reconnu pour la session aa" + str(str(session_id)))
|
|
return False, " Le stagiaire n'est pas reconnu "
|
|
|
|
|
|
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'inscription',
|
|
'related_collection_recid': str(local_retval['_id'])}
|
|
|
|
#print(" ### qery_images = ", qery_images)
|
|
|
|
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 du stagiaire"
|
|
|
|
|
|
"""
|
|
Suppression d'un image d'un stagiaire
|
|
"""
|
|
def DeleteImage_Stagiaire_v2(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, " Impossible de se connecter"
|
|
|
|
'''
|
|
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, "Impossible de se connecter"
|
|
|
|
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 "
|
|
|
|
"""
|
|
Cette fonction récupérer la liste des stagiaire d'un partenaire.
|
|
On y ajoute la formation concernée
|
|
"""
|
|
def Get_Statgaire_List_Partner_with_filter(diction):
|
|
try:
|
|
field_list = ['token', 'class_internal_url', 'code_session', 'status', 'email', 'nom',
|
|
'class_title', 'code_session','client_nom', 'client_rattachement_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é, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
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
|
|
|
|
partner_recid = my_partner['recid']
|
|
|
|
|
|
"""
|
|
30/07/2024 - Pour la gestion du recyclage, recuperer les paramettres du partner dans la collection "base_partner_setup"
|
|
- recyclage_warning
|
|
- recyclage_warning_lead_time
|
|
"""
|
|
recyclage_warning = "0"
|
|
recyclage_warning_lead_time = "0"
|
|
partner_base_setup_recyclage_warning = MYSY_GV.dbname['base_partner_setup'].find_one({"config_name":'recyclage_warning',
|
|
'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':my_partner['recid']})
|
|
|
|
if( partner_base_setup_recyclage_warning and "config_value" in partner_base_setup_recyclage_warning.keys() ):
|
|
recyclage_warning = partner_base_setup_recyclage_warning['config_value']
|
|
|
|
|
|
if( recyclage_warning == "1"):
|
|
partner_base_setup_recyclage_warning_lead_time = MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{"config_name": 'recyclage_warning_lead_time',
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': my_partner['recid']})
|
|
|
|
if (partner_base_setup_recyclage_warning_lead_time and "config_value" in partner_base_setup_recyclage_warning_lead_time.keys()):
|
|
recyclage_warning_lead_time = str(mycommon.tryInt(str(partner_base_setup_recyclage_warning_lead_time['config_value'])))
|
|
|
|
|
|
|
|
|
|
#print(" #### recyclage_warning = ", str(recyclage_warning), " ### recyclage_warning_lead_time = ", str(recyclage_warning_lead_time))
|
|
|
|
|
|
|
|
|
|
"""
|
|
Etape 1 : si on a le champ 'code session' saisie par l'utilisateur,
|
|
alors on va commencer par aller cherche toutes les session avec un regex de la valeur saisie filter sur le partner_recid
|
|
|
|
"""
|
|
filt_session_id = {}
|
|
list_session_id = []
|
|
if ("code_session" in diction.keys()):
|
|
filt_code_session = {'code_session': {'$regex': str(diction['code_session']), "$options": "i"}}
|
|
|
|
"""
|
|
qry_list_session_id = { { '$and' :[ {'code_session': {'$regex': str(diction['code_session']), "$options": "i"}},
|
|
{'partner_owner_recid': str(partner_recid)} ]}, {'_id':1}}
|
|
"""
|
|
|
|
qry_list_session_id = {"$and": [{'code_session': {'$regex': str(diction['code_session']), "$options": "i"}},
|
|
{'partner_owner_recid': str(partner_recid)}]}
|
|
|
|
#print(" ### qry_list_session_id aa = ", qry_list_session_id)
|
|
list_session_id_count = MYSY_GV.dbname['session_formation'].count_documents(qry_list_session_id)
|
|
|
|
if( list_session_id_count <= 0 ):
|
|
# Aucune session
|
|
return True, []
|
|
|
|
for val in MYSY_GV.dbname['session_formation'].find(qry_list_session_id):
|
|
list_session_id.append(str(val['_id']))
|
|
|
|
#print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
|
filt_session_id = {'session_id': {'$in': list_session_id, }}
|
|
|
|
|
|
#print(" ### filt_session_id zzzzzzzzz = ", filt_session_id)
|
|
|
|
filt_class_title = {}
|
|
if ("class_title" in diction.keys()):
|
|
filt_class_title = {'title': {'$regex': str(diction['class_title']), "$options": "i"}}
|
|
|
|
filt_class_internal_url = {}
|
|
if ("class_internal_url" in diction.keys()):
|
|
filt_class_internal_url = {
|
|
'class_internal_url': {'$regex': str(diction['class_internal_url']), "$options": "i"}}
|
|
|
|
filt_email = {}
|
|
if ("email" in diction.keys()):
|
|
filt_email = {'email': {'$regex': str(diction['email']), "$options": "i"}}
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_class_partner_recid = {'partner_owner_recid': str(partner_recid)}
|
|
|
|
filt_client_rattachement_id = {}
|
|
if ("client_rattachement_id" in diction.keys()):
|
|
filt_client_rattachement_id = {'client_rattachement_id': str(diction['client_rattachement_id'])}
|
|
|
|
"""
|
|
filt_session_id = {}
|
|
if ("session_id" in diction.keys()):
|
|
filt_session_id = {'session_id': str(diction['session_id'])}
|
|
"""
|
|
#print(" ### filt_session_id 0222 zzzzzzzzz = ", filt_session_id)
|
|
# -----
|
|
|
|
filt_client_nom = {}
|
|
sub_filt_client_nom = {}
|
|
Lists_partner_client_id = []
|
|
if ("client_nom" in diction.keys()):
|
|
sub_filt_client_nom = {'nom': {'$regex': str(diction['client_nom']), "$options": "i"},
|
|
'partner_recid': str(partner_recid), 'valide': '1', 'locked': '0'}
|
|
# Recuperation des '_id' des clients dont le nom match en regexp
|
|
# print(" ### sub_filt_client_nom = ", sub_filt_client_nom)
|
|
for List_Client_Data in MYSY_GV.dbname['partner_client'].find(sub_filt_client_nom, {'_id': 1}):
|
|
Lists_partner_client_id.append(str(List_Client_Data['_id']))
|
|
|
|
filt_client_nom = {'client_rattachement_id': {'$in': Lists_partner_client_id, }}
|
|
# print(' ### filt_client_nom = ', filt_client_nom)
|
|
|
|
|
|
#----
|
|
|
|
|
|
query = [{'$match':{ '$and' : [ filt_class_internal_url, filt_session_id, filt_email, filt_nom, filt_client_nom, filt_client_rattachement_id,
|
|
filt_session_id, {'partner_owner_recid':str(partner_recid)}] } },
|
|
{'$sort': {'_id': -1}},
|
|
{'$lookup':
|
|
{
|
|
'from': 'myclass',
|
|
'localField': 'class_internal_url',
|
|
'foreignField': 'internal_url',
|
|
'pipeline': [{'$match':{ '$and' : [ filt_class_title, filt_class_partner_recid] } }, {'$project': {'title': 1, 'domaine': 1,
|
|
'duration': 1,
|
|
'duration_unit': 1,
|
|
'_id':1,
|
|
'recyclage_delai':1,
|
|
'recyclage_periodicite':1,
|
|
'recyclage_alert':1}}],
|
|
'as': 'myclass_collection'
|
|
}
|
|
},
|
|
{'$lookup':
|
|
{
|
|
'from': 'apprenant',
|
|
"let": {'apprenant_id': "$apprenant_id", 'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [{'$match':
|
|
{'$expr': {'$and': [
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$_id", {'$convert': {
|
|
'input': "$$apprenant_id",
|
|
'to': "objectId",
|
|
'onError': {'error': 'true'},
|
|
'onNull': {'isnull': 'true'}
|
|
}}]},
|
|
|
|
]}}},
|
|
], 'as': 'apprenant_collection'}}
|
|
]
|
|
|
|
print("#### Get_Statgaire_List_Partner_with_filter laa 01 : query = ", query)
|
|
RetObject = []
|
|
cpt = 0
|
|
for retVal in MYSY_GV.dbname['inscription'].aggregate(query):
|
|
val = {}
|
|
if ('myclass_collection' in retVal.keys() and len(retVal['myclass_collection']) > 0):
|
|
|
|
val['id'] = str(cpt)
|
|
cpt = cpt + 1
|
|
val['_id'] = retVal['_id']
|
|
val['session_id'] = retVal['session_id']
|
|
val['class_internal_url'] = retVal['class_internal_url']
|
|
val['nom'] = retVal['nom']
|
|
val['partner_owner_recid'] = retVal['partner_owner_recid']
|
|
val['prenom'] = retVal['prenom']
|
|
|
|
val['email'] = retVal['email']
|
|
|
|
if ("civilite" in retVal.keys()):
|
|
val['civilite'] = str(retVal['civilite']).lower()
|
|
else:
|
|
val['civilite'] = ""
|
|
|
|
if (str(val['civilite']) not in MYSY_GV.CIVILITE):
|
|
val['civilite'] = "neutre"
|
|
|
|
|
|
if( "modefinancement" in retVal.keys()):
|
|
val['modefinancement'] = retVal['modefinancement']
|
|
else:
|
|
val['modefinancement'] = ""
|
|
|
|
if ("opco" in retVal.keys()):
|
|
val['opco'] = retVal['opco']
|
|
else:
|
|
val['opco'] = ""
|
|
|
|
|
|
if ("employeur" in retVal.keys()):
|
|
val['employeur'] = retVal['employeur']
|
|
else:
|
|
val['employeur'] = ""
|
|
|
|
if ("telephone" in retVal.keys()):
|
|
val['telephone'] = retVal['telephone']
|
|
else:
|
|
val['telephone'] = ""
|
|
|
|
if ("date_naissance" in retVal.keys()):
|
|
val['date_naissance'] = retVal['date_naissance']
|
|
else:
|
|
val['date_naissance'] = ""
|
|
|
|
if ("adresse" in retVal.keys()):
|
|
val['adresse'] = retVal['adresse']
|
|
else:
|
|
val['adresse'] = ""
|
|
|
|
if ("code_postal" in retVal.keys()):
|
|
val['code_postal'] = retVal['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("ville" in retVal.keys()):
|
|
val['ville'] = retVal['ville']
|
|
else:
|
|
val['ville'] = ""
|
|
|
|
|
|
if ("pays" in retVal.keys()):
|
|
val['pays'] = retVal['pays']
|
|
else:
|
|
val['pays'] = ""
|
|
|
|
|
|
val['status'] = retVal['status']
|
|
|
|
val['class_id'] = str(retVal['myclass_collection'][0]['_id'])
|
|
val['title'] = retVal['myclass_collection'][0]['title']
|
|
if("domaine" in retVal['myclass_collection'][0].keys() ):
|
|
val['domaine'] = retVal['myclass_collection'][0]['domaine']
|
|
else:
|
|
val['domaine'] = ""
|
|
|
|
|
|
# Recuperation des informations de la session
|
|
local_qry = {'_id':ObjectId(retVal['session_id']), 'valide':'1'}
|
|
|
|
#print(" #### local_qry zzz = ", local_qry)
|
|
|
|
count_session = MYSY_GV.dbname['session_formation'].count_documents(local_qry)
|
|
|
|
|
|
client_rattachement_id = ""
|
|
client_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
#print(" ### retVal = ", retVal )
|
|
if( "client_rattachement_id" in retVal.keys()):
|
|
if( retVal['client_rattachement_id'] and str(retVal['client_rattachement_id'] ) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId( retVal['client_rattachement_id']),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( client_retval is not None):
|
|
client_rattachement_id= client_retval['_id']
|
|
client_rattachement_nom = client_retval['nom']
|
|
|
|
val['client_rattachement_id'] = client_rattachement_id
|
|
val['client_rattachement_nom'] = client_rattachement_nom
|
|
|
|
if ("facture_client_rattachement_id" in retVal.keys()):
|
|
val['facture_client_rattachement_id'] = retVal['facture_client_rattachement_id']
|
|
else:
|
|
val['facture_client_rattachement_id'] = ""
|
|
|
|
# ----
|
|
|
|
invoiced = ""
|
|
if ("invoiced" in retVal.keys()):
|
|
invoiced = retVal['invoiced']
|
|
val['invoiced'] = invoiced
|
|
|
|
invoiced_ref = ""
|
|
if ("invoiced_ref" in retVal.keys()):
|
|
invoiced_ref = retVal['invoiced_ref']
|
|
val['invoiced_ref'] = invoiced_ref
|
|
|
|
invoiced_date = ""
|
|
if ("invoiced_date" in retVal.keys()):
|
|
invoiced_date = str(retVal['invoiced_date'])[0:10]
|
|
val['invoiced_date'] = invoiced_date
|
|
|
|
|
|
financeur_rattachement_id = ""
|
|
financeur_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
# print(" ### retVal = ", retVal )
|
|
if ("financeur_rattachement_id" in retVal.keys()):
|
|
if (retVal['financeur_rattachement_id'] and str(retVal['financeur_rattachement_id']) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(retVal['financeur_rattachement_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (client_retval is not None):
|
|
financeur_rattachement_id = client_retval['_id']
|
|
financeur_rattachement_nom = client_retval['nom']
|
|
|
|
val['financeur_rattachement_id'] = financeur_rattachement_id
|
|
val['financeur_rattachement_nom'] = financeur_rattachement_nom
|
|
|
|
if(count_session != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Impossible de récupérer la liste des stagiaires, Il y a une incohérence sur la session : " + str(
|
|
retVal['session_id']))
|
|
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes. Il y a une incohérence sur la session : " + str(
|
|
retVal['session_id'])
|
|
|
|
|
|
#qry2 = {'class_internal_url':str(retVal['class_internal_url']), 'code_session':str(retVal['session_id']), 'valide':'1'}
|
|
#print(" ### qry 2 =", qry2)
|
|
session_retval = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(retVal['session_id'])), 'valide':'1'})
|
|
|
|
if ("code_session" in session_retval.keys()):
|
|
val['code_session'] = str(session_retval['code_session'])
|
|
else:
|
|
val['code_session'] = ""
|
|
|
|
|
|
if ("date_debut" in session_retval.keys()):
|
|
val['date_du'] = str(session_retval['date_debut'])[0:10]
|
|
else:
|
|
val['date_du'] = ""
|
|
|
|
if ("date_fin" in session_retval.keys()):
|
|
val['date_au'] = str(session_retval['date_fin'])[0:10]
|
|
else:
|
|
val['date_au'] = ""
|
|
|
|
if ("code_postal" in session_retval.keys()):
|
|
val['code_postal'] = session_retval['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("prix_session" in session_retval.keys()):
|
|
val['price'] = session_retval['prix_session']
|
|
else:
|
|
val['price'] = ""
|
|
|
|
if ("presentiel" in session_retval.keys()):
|
|
val['presentiel'] = session_retval['presentiel']
|
|
else:
|
|
val['presentiel'] = "0"
|
|
|
|
if ("distantiel" in session_retval.keys()):
|
|
val['distantiel'] = session_retval['distantiel']
|
|
else:
|
|
val['distantiel'] = "0"
|
|
|
|
if ("session_ondemande" in session_retval.keys()):
|
|
val['session_ondemande'] = session_retval['session_ondemande']
|
|
else:
|
|
val['session_ondemande'] = "0"
|
|
|
|
"""
|
|
Gestion du recyclage d'un apprenant si la formation a laquelle il a participer
|
|
necessite un recyclage.
|
|
On ne fait ce controle que sur l'inscription 'recyclage_managed' != "1" ou est
|
|
"""
|
|
val['class_recyclage_delai'] = ""
|
|
val['class_recyclage_periodicite'] = ""
|
|
val['class_recyclage_alert'] = ""
|
|
val['nb_jour_avant_recyclage'] = ""
|
|
val['warning_recyclage'] = "0"
|
|
|
|
|
|
if(retVal['status'] == "1" and ("recyclage_managed" not in retVal.keys() or retVal['recyclage_managed'] != "1") ):
|
|
|
|
if ("recyclage_delai" in retVal['myclass_collection'][0].keys()):
|
|
val['class_recyclage_delai'] = retVal['myclass_collection'][0]['recyclage_delai']
|
|
|
|
|
|
if ("recyclage_periodicite" in retVal['myclass_collection'][0].keys()):
|
|
val['class_recyclage_periodicite'] = retVal['myclass_collection'][0]['recyclage_periodicite']
|
|
|
|
if ("recyclage_alert" in retVal['myclass_collection'][0].keys()):
|
|
val['class_recyclage_alert'] = retVal['myclass_collection'][0]['recyclage_alert']
|
|
|
|
|
|
|
|
if (str(val['class_recyclage_delai']) != "" and str(val['class_recyclage_periodicite']) != "" and str(val['class_recyclage_alert']) != "" ):
|
|
session_date_debut = str(session_retval['date_debut'])[0:10]
|
|
session_date_debut_datetime = datetime.strptime(str(session_date_debut).strip(), '%d/%m/%Y')
|
|
if (str(val['class_recyclage_periodicite']) == "mois"):
|
|
class_recyclage_delai_int = mycommon.tryInt(str(val['class_recyclage_delai']))
|
|
session_date_debut_datetime = session_date_debut_datetime + relativedelta( months=+class_recyclage_delai_int)
|
|
|
|
elif (str(val['class_recyclage_periodicite']) == "annee"):
|
|
class_recyclage_delai_int = mycommon.tryInt(str(val['class_recyclage_delai']))
|
|
session_date_debut_datetime = session_date_debut_datetime + relativedelta( years=+class_recyclage_delai_int)
|
|
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
mytoday_datetime = datetime.strptime(str(mytoday).strip(), '%d/%m/%Y')
|
|
|
|
local_delta = session_date_debut_datetime - mytoday_datetime
|
|
val['nb_jour_avant_recyclage'] = str(local_delta.days)
|
|
|
|
|
|
if( local_delta.days < mycommon.tryInt(str(val['class_recyclage_alert'])) ):
|
|
val['warning_recyclage'] = "1"
|
|
|
|
|
|
|
|
"""
|
|
/!\ : 28/12/2023 - update
|
|
S'il y a de la data dans la collection 'apprenant_collection' cela veut dire qu'il y a un dossier apprenant,
|
|
alors on va plutot retourner les info qui sont dans cette collection
|
|
|
|
/!\ 31/07/2024 - annulation de la recheche de l'apprenant
|
|
if ('apprenant_collection' in retVal.keys() and len( retVal['apprenant_collection']) > 0):
|
|
if ("civilite" in retVal['apprenant_collection'][0].keys()):
|
|
val['civilite'] = str(retVal['apprenant_collection'][0]['civilite']).lower()
|
|
else:
|
|
val['civilite'] = ""
|
|
|
|
if (str(val['civilite']) not in MYSY_GV.CIVILITE):
|
|
val['civilite'] = "neutre"
|
|
|
|
local_nom = ""
|
|
if ("nom" in retVal['apprenant_collection'][0].keys()):
|
|
local_nom = retVal['apprenant_collection'][0]['nom']
|
|
val['nom'] = local_nom
|
|
|
|
local_prenom = ""
|
|
if ("prenom" in retVal['apprenant_collection'][0].keys()):
|
|
local_prenom = retVal['apprenant_collection'][0]['prenom']
|
|
val['prenom'] = local_prenom
|
|
|
|
if ("date_naissance" in retVal['apprenant_collection'][0].keys()):
|
|
val['date_naissance'] = retVal['apprenant_collection'][0]['date_naissance']
|
|
else:
|
|
val['date_naissance'] = ""
|
|
|
|
if ("adresse" in retVal['apprenant_collection'][0].keys()):
|
|
val['adresse'] = retVal['apprenant_collection'][0]['adresse']
|
|
else:
|
|
val['adresse'] = ""
|
|
|
|
if ("code_postal" in retVal['apprenant_collection'][0].keys()):
|
|
val['code_postal'] = retVal['apprenant_collection'][0]['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("ville" in retVal['apprenant_collection'][0].keys()):
|
|
val['ville'] = retVal['apprenant_collection'][0]['ville']
|
|
else:
|
|
val['ville'] = ""
|
|
|
|
if ("pays" in retVal['apprenant_collection'][0].keys()):
|
|
val['pays'] = retVal['apprenant_collection'][0]['pays']
|
|
else:
|
|
val['pays'] = ""
|
|
|
|
|
|
|
|
local_employeur = ""
|
|
if ("employeur" in retVal['apprenant_collection'][0].keys()):
|
|
local_employeur = retVal['apprenant_collection'][0]['employeur']
|
|
val['employeur'] = local_employeur
|
|
|
|
local_telephone = ""
|
|
if ("telephone" in retVal['apprenant_collection'][0].keys()):
|
|
local_telephone = retVal['apprenant_collection'][0]['telephone']
|
|
val['telephone'] = local_telephone
|
|
|
|
local_email = ""
|
|
if ("email" in retVal['apprenant_collection'][0].keys()):
|
|
local_email = retVal['apprenant_collection'][0]['email']
|
|
val['email'] = local_email
|
|
|
|
local_adresse = ""
|
|
if ("adresse" in retVal['apprenant_collection'][0].keys()):
|
|
local_adresse = retVal['apprenant_collection'][0]['adresse']
|
|
val['adresse'] = local_adresse
|
|
|
|
if ("ville" in retVal['apprenant_collection'][0].keys()):
|
|
val['ville'] = retVal['apprenant_collection'][0]['ville']
|
|
else:
|
|
val['ville'] = ""
|
|
|
|
if ("code_postal" in retVal['apprenant_collection'][0].keys()):
|
|
val['code_postal'] = retVal['apprenant_collection'][0]['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("pays" in retVal['apprenant_collection'][0].keys()):
|
|
val['pays'] = retVal['apprenant_collection'][0]['pays']
|
|
else:
|
|
val['pays'] = ""
|
|
|
|
"""
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(val))
|
|
|
|
#print(" ### RetObject = ", str(RetObject))
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des stagiaires"
|
|
|
|
|
|
|
|
"""
|
|
Gestion du recyclage :
|
|
Cette fonction permet d'acquiter la gestion du recyclage d'une inscription
|
|
Ex : l'inscrit ne souhaite plus le repasser, donc on met 'recyclage_managed' à '0'
|
|
ou le cas la personne s'est bien reinscrite, donc plus besoin de traiter les donnees de recyclage
|
|
|
|
"""
|
|
def Inscription_Recyclage_Management_Done(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
field_list_obligatoire = ['token', 'tab_inscriptions_ids']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
tab_inscriptions_ids = ""
|
|
if ("tab_inscriptions_ids" in diction.keys()):
|
|
if diction['tab_inscriptions_ids']:
|
|
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
|
|
|
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
|
|
|
tab_inscriptions_ids_splited_obj = []
|
|
for tmp in tab_inscriptions_ids_splited :
|
|
tab_inscriptions_ids_splited_obj.append(ObjectId(str(tmp)))
|
|
|
|
print(" ### tab_inscriptions_ids_splited_obj = ", tab_inscriptions_ids_splited_obj)
|
|
|
|
"""
|
|
Verifier que les inscriptions sont valides
|
|
"""
|
|
for inscription in tab_inscriptions_ids_splited_obj:
|
|
print({'_id':inscription, 'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
is_valide_inscription_count = MYSY_GV.dbname['inscription'].count_documents({'_id':inscription, 'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_inscription_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription "+str(inscription)+" est invalide ")
|
|
return False, " L'identifiant de l'inscription "+str(inscription)+" est invalide "
|
|
|
|
|
|
|
|
for inscription in tab_inscriptions_ids_splited_obj:
|
|
new_data = {}
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['recyclage_managed'] = "1"
|
|
|
|
ret_val = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': inscription, 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
|
|
return True, " La mise à jour à é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) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de faire la mise à jour "
|
|
|
|
"""
|
|
Cette fonction prend '_id' d'une ligne et retour les information de l'inscription associé.
|
|
|
|
Un controle sera fait avec le partner_recid
|
|
"""
|
|
|
|
def GetAttendeeDetail_perSession_from_line_id(diction):
|
|
try:
|
|
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, " Impossible de récupérer les informations detaillées"
|
|
|
|
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"
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
RetObject = []
|
|
|
|
qry_filter = {'_id':ObjectId(str(diction['_id'])),'partner_owner_recid':str(partner_recid),}
|
|
|
|
|
|
pipe_qry = ([{'$match':qry_filter},
|
|
{'$lookup':
|
|
{
|
|
'from': 'session_formation',
|
|
'let': {'session_id': "$session_id", 'class_internal_url': '$class_internal_url', 'partner_owner_recid':'$partner_owner_recid'},
|
|
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
{'$eq': ['$_id', { '$toObjectId': '$$session_id' }]},
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
|
|
],
|
|
'as': 'inscription_collection'
|
|
}
|
|
},
|
|
{'$lookup': {'from': 'apprenant', 'let': {'apprenant_id': '$apprenant_id',
|
|
'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [{'$match': {'$expr': {'$and': [{'$eq': ['$valide', '1']},
|
|
{'$eq': ['$_id', {'$convert': {
|
|
'input': '$$apprenant_id',
|
|
'to': 'objectId',
|
|
'onError': {'error': 'true'},
|
|
'onNull': {
|
|
'isnull': 'true'}}}]}]}}}],
|
|
'as': 'apprenant_collection'}}
|
|
|
|
])
|
|
|
|
|
|
print(" ### GetAttendeeDetail_perSession_from_line_id ici pipe_qry = ",pipe_qry)
|
|
# Recuperation des infos de la formation
|
|
"""local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id':str(diction['session_id']),
|
|
'email':str(diction['attendee_email']),
|
|
'class_internal_url':str(diction['internal_url']),})
|
|
"""
|
|
|
|
|
|
for local_Insc_retval in MYSY_GV.dbname['inscription'].aggregate(pipe_qry) :
|
|
|
|
#print(" ### local_Insc_retval laa== ", local_Insc_retval)
|
|
|
|
if( local_Insc_retval is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le recid du partenaire (2)")
|
|
return False, " Les informations d'identifier la session (2) "
|
|
|
|
if ('inscription_collection' in local_Insc_retval.keys() and len(local_Insc_retval['inscription_collection']) > 0):
|
|
my_retrun_dict = {}
|
|
|
|
if ("session_id" in local_Insc_retval.keys()):
|
|
my_retrun_dict['session_id'] = local_Insc_retval['session_id']
|
|
|
|
if ("apprenant_id" in local_Insc_retval.keys()):
|
|
my_retrun_dict['apprenant_id'] = local_Insc_retval['apprenant_id']
|
|
else:
|
|
my_retrun_dict['apprenant_id'] = ""
|
|
|
|
if ("tuteur1_civilite" not in local_Insc_retval.keys()):
|
|
my_retrun_dict['tuteur1_civilite'] = ""
|
|
elif (local_Insc_retval['tuteur1_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
my_retrun_dict['tuteur1_civilite'] = ""
|
|
else:
|
|
my_retrun_dict['tuteur1_civilite'] = local_Insc_retval['tuteur1_civilite']
|
|
|
|
if ("tuteur2_civilite" not in local_Insc_retval.keys()):
|
|
my_retrun_dict['tuteur2_civilite'] = ""
|
|
elif (local_Insc_retval['tuteur2_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
my_retrun_dict['tuteur2_civilite'] = ""
|
|
else:
|
|
my_retrun_dict['tuteur2_civilite'] = local_Insc_retval['tuteur2_civilite']
|
|
|
|
|
|
if ("code_session" in local_Insc_retval['inscription_collection'][0].keys()):
|
|
my_retrun_dict['code_session'] = str(local_Insc_retval['inscription_collection'][0]['code_session'])
|
|
|
|
if ("date_debut" in local_Insc_retval['inscription_collection'][0].keys()):
|
|
my_retrun_dict['date_du'] = str(local_Insc_retval['inscription_collection'][0]['date_debut'])[0:10]
|
|
|
|
if ("date_fin" in local_Insc_retval['inscription_collection'][0].keys()):
|
|
my_retrun_dict['date_au'] = str(local_Insc_retval['inscription_collection'][0]['date_fin'])[0:10]
|
|
|
|
if ("ville" in local_Insc_retval.keys()):
|
|
my_retrun_dict['ville'] = local_Insc_retval['ville']
|
|
|
|
if ("code_postal" in local_Insc_retval.keys()):
|
|
my_retrun_dict['code_postal'] = local_Insc_retval['code_postal']
|
|
|
|
if ("certification_send_date" in local_Insc_retval.keys()):
|
|
if (str(local_Insc_retval['certification_send_date'])):
|
|
my_retrun_dict['certification_send_date'] = str(local_Insc_retval['certification_send_date'])[0:10]
|
|
|
|
local_adresse = ""
|
|
if ("adresse" in local_Insc_retval.keys()):
|
|
local_adresse = local_Insc_retval['adresse']
|
|
my_retrun_dict['adresse'] = local_adresse
|
|
|
|
local_nom = ""
|
|
if ("nom" in local_Insc_retval.keys()):
|
|
local_nom = local_Insc_retval['nom']
|
|
my_retrun_dict['nom'] = local_nom
|
|
|
|
local_prenom = ""
|
|
if ("prenom" in local_Insc_retval.keys()):
|
|
local_prenom = local_Insc_retval['prenom']
|
|
my_retrun_dict['prenom'] = local_prenom
|
|
|
|
local_civilite = ""
|
|
if ("civilite" in local_Insc_retval.keys()):
|
|
local_civilite = local_Insc_retval['civilite']
|
|
|
|
if (local_civilite not in MYSY_GV.CIVILITE):
|
|
local_civilite = "neutre"
|
|
|
|
|
|
my_retrun_dict['civilite'] = str(local_civilite).lower()
|
|
|
|
|
|
local_employeur = ""
|
|
if ("employeur" in local_Insc_retval.keys()):
|
|
local_employeur = local_Insc_retval['employeur']
|
|
my_retrun_dict['employeur'] = local_employeur
|
|
|
|
local_telephone = ""
|
|
if ("telephone" in local_Insc_retval.keys()):
|
|
local_telephone = local_Insc_retval['telephone']
|
|
my_retrun_dict['telephone'] = local_telephone
|
|
|
|
local_email = ""
|
|
if ("email" in local_Insc_retval.keys()):
|
|
local_email = local_Insc_retval['email']
|
|
my_retrun_dict['email'] = local_email
|
|
|
|
local_modefinancement = ""
|
|
if ("modefinancement" in local_Insc_retval.keys()):
|
|
local_modefinancement = local_Insc_retval['modefinancement']
|
|
my_retrun_dict['modefinancement'] = local_modefinancement
|
|
|
|
local_opco = ""
|
|
if ("opco" in local_Insc_retval.keys()):
|
|
local_opco = local_Insc_retval['opco']
|
|
my_retrun_dict['opco'] = local_opco
|
|
|
|
local_class_internal_url = ""
|
|
if ("class_internal_url" in local_Insc_retval.keys()):
|
|
local_class_internal_url = local_Insc_retval['class_internal_url']
|
|
my_retrun_dict['class_internal_url'] = local_class_internal_url
|
|
|
|
local_status = ""
|
|
if ("status" in local_Insc_retval.keys()):
|
|
local_status = local_Insc_retval['status']
|
|
my_retrun_dict['status'] = local_status
|
|
|
|
local_price = ""
|
|
if ("price" in local_Insc_retval.keys()):
|
|
local_price = local_Insc_retval['price']
|
|
my_retrun_dict['price'] = local_price
|
|
|
|
local_inscription_validation_date = ""
|
|
if ("inscription_validation_date" in local_Insc_retval.keys()):
|
|
local_inscription_validation_date = local_Insc_retval['inscription_validation_date']
|
|
my_retrun_dict['inscription_validation_date'] = local_inscription_validation_date
|
|
|
|
if ("eval_eval" in local_Insc_retval.keys()):
|
|
if (str(local_Insc_retval['eval_eval'])):
|
|
my_retrun_dict['eval_eval'] = local_Insc_retval['eval_eval']
|
|
|
|
if ("eval_note" in local_Insc_retval.keys()):
|
|
if (str(local_Insc_retval['eval_note'])):
|
|
my_retrun_dict['eval_note'] = local_Insc_retval['eval_note']
|
|
|
|
if ("eval_pedagogie" in local_Insc_retval.keys()):
|
|
if (str(local_Insc_retval['eval_pedagogie'])):
|
|
my_retrun_dict['eval_pedagogie'] = local_Insc_retval['eval_pedagogie']
|
|
|
|
if ("eval_date" in local_Insc_retval.keys()):
|
|
if (str(local_Insc_retval['eval_date'])):
|
|
my_retrun_dict['eval_date'] = str(local_Insc_retval['eval_date'])[0:10]
|
|
|
|
client_rattachement_id = ""
|
|
client_rattachement_nom = ""
|
|
if ("client_rattachement_id" in local_Insc_retval.keys()):
|
|
if( local_Insc_retval['client_rattachement_id'] and str(local_Insc_retval['client_rattachement_id']) != 'undefined' ):
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one({'_id': ObjectId(str(local_Insc_retval['client_rattachement_id'])),
|
|
'valide': '1', 'locked': '0'}, {'_id':1, 'nom':1})
|
|
|
|
if( local_client_retval_data is not None):
|
|
client_rattachement_id = local_client_retval_data['_id']
|
|
client_rattachement_nom = local_client_retval_data['nom']
|
|
|
|
my_retrun_dict['client_rattachement_id'] = client_rattachement_id
|
|
my_retrun_dict['client_rattachement_nom'] = client_rattachement_nom
|
|
|
|
# ----
|
|
financeur_rattachement_id = ""
|
|
financeur_rattachement_nom = ""
|
|
if ("financeur_rattachement_id" in local_Insc_retval.keys()):
|
|
if (local_Insc_retval['financeur_rattachement_id'] and str(
|
|
local_Insc_retval['financeur_rattachement_id']) != 'undefined'):
|
|
local_client_retval_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(local_Insc_retval['financeur_rattachement_id'])),
|
|
'valide': '1', 'locked': '0'}, {'_id': 1, 'nom': 1})
|
|
|
|
if (local_client_retval_data is not None):
|
|
financeur_rattachement_id = local_client_retval_data['_id']
|
|
financeur_rattachement_nom = local_client_retval_data['nom']
|
|
|
|
my_retrun_dict['financeur_rattachement_id'] = financeur_rattachement_id
|
|
my_retrun_dict['financeur_rattachement_nom'] = financeur_rattachement_nom
|
|
|
|
if ("facture_client_rattachement_id" in local_Insc_retval.keys()):
|
|
my_retrun_dict['facture_client_rattachement_id'] = local_Insc_retval[
|
|
'facture_client_rattachement_id']
|
|
else:
|
|
my_retrun_dict['facture_client_rattachement_id'] = ""
|
|
|
|
v = local_Insc_retval['_id'].generation_time
|
|
my_retrun_dict['created_date'] = str(v.strftime("%d/%m/%Y"))
|
|
|
|
# Recuperation des informations de la formation
|
|
local_formation = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(local_Insc_retval['class_internal_url'])})
|
|
|
|
if local_formation is None or local_formation['_id'] is None:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer les informations de la formation ")
|
|
return False, " Impossible de récupérer les informations de la formation"
|
|
|
|
|
|
|
|
my_retrun_dict['class_title'] = local_formation['title']
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(my_retrun_dict))
|
|
|
|
|
|
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 récupérer les informations detaillées"
|
|
|
|
|
|
"""
|
|
Mise à jour des tuteurs
|
|
"""
|
|
|
|
def UpdateStagiairetoClass_Tuteurs(diction):
|
|
try:
|
|
|
|
return_message = ""
|
|
field_list = ['token', '_id',
|
|
'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', 'tuteur1_civilite',
|
|
'tuteur2_civilite'
|
|
]
|
|
|
|
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é, Creation partenaire annulée")
|
|
return False, "Impossible de mettre à jour stagiaire. Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Impossible de mettre à jour stagiaire, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
query_key = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = str(diction['token']).strip()
|
|
# query_key['token'] = diction['token']
|
|
|
|
|
|
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'])+"' est invalide ")
|
|
return False, "L'adresse email '"+str(diction['tuteur1_email'])+"' est invalide"
|
|
|
|
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']) + "' est invalide ")
|
|
return False, "L'adresse email '" + str(diction['tuteur2_email']) + "' est invalide"
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token': mytoken})
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
data_update = diction
|
|
|
|
my_id = str(diction['_id'])
|
|
del data_update['token']
|
|
del data_update['_id']
|
|
data_update['date_update'] = str(datetime.now())
|
|
data_update['update_by'] = str(my_partner['_id'])
|
|
|
|
|
|
|
|
if ("tuteur1_civilite" in data_update.keys() ):
|
|
if (data_update['tuteur1_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
data_update['tuteur1_civilite'] = ""
|
|
|
|
|
|
|
|
if ("tuteur2_civilite" in data_update.keys() ):
|
|
if (data_update['tuteur2_civilite'] not in MYSY_GV.CIVILITE):
|
|
# la civilité n'est pas une de celle autorisée, alors je renvoie vide
|
|
data_update['tuteur2_civilite'] = ""
|
|
|
|
result = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id':ObjectId(str(my_id)),
|
|
'partner_owner_recid':str(my_partner['recid'])},
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le tuteur (2) ")
|
|
return False, " Impossible de mettre à jour le tuteur (2) "
|
|
|
|
return True, " Le tuteur 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 tuteur "
|
|
|
|
|
|
"""
|
|
Cette fonction recupere les differentes types de convention de stagiaire
|
|
|
|
On accepte plusieurs vesions du meme doc
|
|
"""
|
|
def Get_List_Conventions_Stagiaire(diction):
|
|
try:
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 = 0
|
|
|
|
"""
|
|
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'CONVENTION_STAGIAIRE'
|
|
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
|
2 - On va sortir les conventions par defaut de MySy.
|
|
|
|
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
|
"""
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'ref_interne':'CONVENTION_STAGIAIRE',
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
|
if( val_tmp == 0 ):
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': 'default'}):
|
|
user = retval
|
|
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 la liste des conventions"
|
|
|
|
|
|
"""
|
|
Cette fonction recupere les differentes types de convention de stagiaire avec des option comme :
|
|
- ref_interne
|
|
- nom
|
|
- type_doc
|
|
|
|
On accepte plusieurs versions du meme doc
|
|
"""
|
|
|
|
def Get_List_Conventions_Stagiaire_With_Filter(diction):
|
|
try:
|
|
|
|
field_list = ['token', 'ref_interne','nom', 'type_doc', 'courrier_template_type_document_ref_interne' ]
|
|
|
|
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 autorisé"
|
|
|
|
|
|
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
|
|
# Recuperation des option de filter
|
|
filt_type_doc = {}
|
|
if ("type_doc" in diction.keys()):
|
|
filt_type_doc = {'type_doc': str(diction['type_doc'])}
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': str(diction['nom'])}
|
|
|
|
filt_ref_interne = {}
|
|
if ("ref_interne" in diction.keys()):
|
|
filt_ref_interne = {'ref_interne': str(diction['ref_interne'])}
|
|
|
|
filt_courrier_template_type_document_ref_interne = {}
|
|
if ("courrier_template_type_document_ref_interne" in diction.keys()):
|
|
filt_courrier_template_type_document_ref_interne = {'courrier_template_type_document_ref_interne': str(diction['courrier_template_type_document_ref_interne'])}
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
"""
|
|
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'CONVENTION_STAGIAIRE'
|
|
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
|
2 - On va sortir les conventions par defaut de MySy.
|
|
|
|
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
|
"""
|
|
|
|
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}, filt_courrier_template_type_document_ref_interne, filt_type_doc, filt_nom, filt_ref_interne ]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
|
if (val_tmp == 0):
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': 'default'}, filt_courrier_template_type_document_ref_interne, filt_type_doc, filt_nom, filt_ref_interne ]}):
|
|
user = retval
|
|
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 la liste des conventions"
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction recupere les differentes types de conVOCAtion de stagiaire avec des option comme :
|
|
- ref_interne
|
|
- nom
|
|
- type_doc
|
|
|
|
On accepte plusieurs versions du meme doc
|
|
"""
|
|
|
|
def Get_List_Convocations_Stagiaire_With_Filter(diction):
|
|
try:
|
|
|
|
field_list = ['token', 'ref_interne','nom', 'type_doc', 'courrier_template_type_document_ref_interne' ]
|
|
|
|
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 autorisé"
|
|
|
|
|
|
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
|
|
# Recuperation des option de filter
|
|
filt_type_doc = {}
|
|
if ("type_doc" in diction.keys()):
|
|
filt_type_doc = {'type_doc': str(diction['type_doc'])}
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': str(diction['nom'])}
|
|
|
|
filt_ref_interne = {}
|
|
if ("ref_interne" in diction.keys()):
|
|
filt_ref_interne = {'ref_interne': str(diction['ref_interne'])}
|
|
|
|
filt_courrier_template_type_document_ref_interne = {}
|
|
if ("courrier_template_type_document_ref_interne" in diction.keys()):
|
|
filt_courrier_template_type_document_ref_interne = {'courrier_template_type_document_ref_interne': str(diction['courrier_template_type_document_ref_interne'])}
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
"""
|
|
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'CONVENTION_STAGIAIRE'
|
|
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
|
2 - On va sortir les conventions par defaut de MySy.
|
|
|
|
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
|
"""
|
|
|
|
qry = {'$and': [{'ref_interne': 'CONVOCATION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}, filt_courrier_template_type_document_ref_interne,
|
|
filt_type_doc, filt_nom, filt_ref_interne ]}
|
|
|
|
|
|
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'CONVOCATION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}, filt_courrier_template_type_document_ref_interne,
|
|
filt_type_doc, filt_nom, filt_ref_interne ]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
|
if (val_tmp == 0):
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'CONVOCATION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': 'default'}, filt_courrier_template_type_document_ref_interne, filt_type_doc, filt_nom, filt_ref_interne ]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
#print(" ### Get_List_Convocations_Stagiaire_With_Filter RetObject = ", RetObject)
|
|
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 convocations"
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction recupere les differentes modele de courrier d'emargement
|
|
de stagiaire avec des option comme :
|
|
- ref_interne
|
|
- nom
|
|
- type_doc
|
|
|
|
On accepte plusieurs versions du meme doc
|
|
"""
|
|
|
|
def Get_List_Emargement_With_Filter(diction):
|
|
try:
|
|
|
|
field_list = ['token', 'type_doc' ]
|
|
|
|
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 autorisé"
|
|
|
|
|
|
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
|
|
# Recuperation des option de filter
|
|
filt_type_doc = {}
|
|
if ("type_doc" in diction.keys()):
|
|
filt_type_doc = {'type_doc': str(diction['type_doc'])}
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
"""
|
|
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'EMARGEMENT'
|
|
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
|
2 - On va sortir les conventions par defaut de MySy.
|
|
|
|
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
|
"""
|
|
|
|
qry = {'$and': [{'ref_interne': 'EMARGEMENT',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
filt_type_doc ]}
|
|
|
|
|
|
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'EMARGEMENT',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
filt_type_doc ]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
|
if (val_tmp == 0):
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'EMARGEMENT',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': 'default'}, filt_type_doc]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
#print(" ### Get_List_Convocations_Stagiaire_With_Filter RetObject = ", RetObject)
|
|
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 emargements"
|
|
|
|
|
|
|
|
"""
|
|
Recuperatin des convention SEULEMENT Individuelles
|
|
"""
|
|
|
|
|
|
def Get_List_Conventions_Stagiaire_Individuelles(diction):
|
|
try:
|
|
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, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 = 0
|
|
|
|
"""
|
|
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'CONVENTION_STAGIAIRE'
|
|
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
|
2 - On va sortir les conventions par defaut de MySy.
|
|
|
|
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
|
"""
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({"$or": [
|
|
{
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'edit_by_client':'0',
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
},
|
|
{
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'edit_by_client': {'$exists': False},
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
|
|
}
|
|
]}):
|
|
user = retval
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
|
if (val_tmp == 0):
|
|
for retval in MYSY_GV.dbname['courrier_template'].find({"$or": [
|
|
{'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'edit_by_client': '0',
|
|
'partner_owner_recid': 'default'},
|
|
{'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'edit_by_client': {'$exists': False},
|
|
'partner_owner_recid': 'default'
|
|
}]}):
|
|
user = retval
|
|
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 la liste des conventions"
|
|
|
|
|
|
"""
|
|
Cette fonction envoie une convention de stage par email
|
|
elle prend :
|
|
- courrier_template_id
|
|
- inscription_id.
|
|
|
|
Dans le cas ou l'utilisateur a modifier l'email du destinataire ou il a donné une
|
|
adresse email de test, on accepte en non obligatoire
|
|
- email_test
|
|
- email_production
|
|
|
|
/!\ : Regle de gestion :
|
|
|
|
1) Si le modele de courrier est 'edit_by_client', alors le mail est envoyé au contact de communication
|
|
du client rattaché au stagiaire.
|
|
|
|
Si le stagiaire n'a pas de client rattacher, le système retourne un message d'erreur.
|
|
|
|
2) Règle d'utilisation des emails destinantaire
|
|
Si 'email_test' est rempli, on envoie l'email de test si non
|
|
Si 'email_production' on prend cette liste d'adresse si non
|
|
On va chercher les adresse de communication par defaut de l'apprenant
|
|
|
|
"""
|
|
def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|
try:
|
|
|
|
field_list_obligatoire = [ 'token', 'inscription_id', 'courrier_template_id', 'email_test', 'email_production' ]
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
"""
|
|
20/03/2024 : Creation du E-Document à signer
|
|
On verifier si le partenaire dispose de l'option "signature_digital" dans la collection base_partner_setup
|
|
|
|
ET SI DEPUIS LE FRONT, L'UTILISATEUR DECIDE DE L'UTILISER
|
|
"""
|
|
is_partner_digital_signature = ""
|
|
if ("request_digital_signature" in diction.keys() and diction['request_digital_signature'] == "1"):
|
|
|
|
is_signature_digital_count = MYSY_GV.dbname['base_partner_setup'].count_documents(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'signature_digital',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'config_value': '1'})
|
|
if (is_signature_digital_count == 1):
|
|
is_partner_digital_signature = "1"
|
|
|
|
# Verifier que le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1"
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'status':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_inscription_valide != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
|
|
# Traitement de l'eventuel fichier joint
|
|
tab_files_to_attache_to_mail = []
|
|
|
|
for saved_file in tab_files :
|
|
|
|
"""
|
|
status, saved_file = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
|
if (status is False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible de récupérer correctement le fichier à importer"
|
|
"""
|
|
|
|
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition', 'attachment; filename="{0}"' .format(os.path.basename(saved_file)))
|
|
|
|
new_node = {"attached_file":file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
|
|
|
|
|
|
# Verification de la validité des adresses email_recu
|
|
"""
|
|
/!\ : Si l'email de test est repli, alors on considere que c'est un test, on ne prend pas en compte l'email de email_production.
|
|
Ceci pour forcer les utilisateur à ne remplir que l'email de prod s'il veulent l'envoyer en prod.
|
|
|
|
Si l'adresse email_prodution = "defaul", cela veut dire qu'on envoie la convention à :
|
|
- l'adresse email du stagiaire et ses tuteurs (si les tuteurs on cochés la case 'inclu com'
|
|
|
|
"""
|
|
|
|
|
|
send_in_production = 0
|
|
|
|
tab_emails_destinataire = []
|
|
|
|
|
|
if( "email_test" in diction.keys() and diction['email_test']):
|
|
send_in_production = 0
|
|
tab_email_test = str(diction['email_test']).replace(";",",").split(",")
|
|
for email in tab_email_test:
|
|
email = email.strip()
|
|
if( mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email "+str(email)+" est invalide ")
|
|
return False, " L'adresse email "+str(email)+" est invalide "
|
|
tab_emails_destinataire = tab_email_test
|
|
|
|
elif ( "email_production" in diction.keys() and diction['email_production']):
|
|
send_in_production = 1
|
|
if( str(diction['email_production']) != "default") :
|
|
tab_email_prod = str(diction['email_production']).replace(";", ",").split(",")
|
|
for email in tab_email_prod:
|
|
email = email.strip()
|
|
if (mycommon.isEmailValide(str(email)) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email '" + str(email) + "' est invalide ")
|
|
return False, " L'adresse email " + str(email) + " est invalide "
|
|
tab_emails_destinataire = tab_email_prod
|
|
else:
|
|
send_in_production = 1
|
|
# On va chercher les adresse email de communication du
|
|
local_dict = {'token':str(diction['token']), '_id':str(diction['inscription_id'])}
|
|
|
|
local_status, tab_apprenant_contact = Get_Statgiaire_Communication_Contact(local_dict)
|
|
if( local_status is False ):
|
|
return local_status, tab_apprenant_contact
|
|
|
|
tmp_tab = []
|
|
#print(" ### tab_apprenant_contact = ", tab_apprenant_contact)
|
|
|
|
for tmp in tab_apprenant_contact :
|
|
if("email" in tmp.keys() ):
|
|
tab_emails_destinataire.append((tmp['email']))
|
|
|
|
|
|
|
|
if(len(tab_emails_destinataire) <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Aucune adresse email n'a été fourni. ")
|
|
return False, " Aucune adresse email n'a été fourni. "
|
|
|
|
|
|
#print(" ### tab_emails_destinataire = ", tab_emails_destinataire)
|
|
|
|
# Verifier que le 'courrier_template_id' est valide
|
|
# Ici le template doit etre un email
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents({'_id':ObjectId(str(diction['courrier_template_id'])),
|
|
'valide':'1',
|
|
'type_doc': 'email',
|
|
'locked':'0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if( is_courrier_template_id_valide != 1 ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
|
|
|
|
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
|
|
# Recuperation des eventuelles pièces jointes du modèle que courrier
|
|
local_dic = {}
|
|
local_dic['token'] = str(diction['token'])
|
|
local_dic['object_owner_collection'] = "courrier_template"
|
|
local_dic['object_owner_id'] = str(courrier_template_data['_id'])
|
|
|
|
|
|
local_status, local_retval = attached_file_mgt.Get_List_object_owner_collection_Stored_Files(local_dic)
|
|
if( local_status is False ):
|
|
return local_status, local_retval
|
|
|
|
#print(" ### file stocké = ", local_retval)
|
|
|
|
# Recuperation des fichiers attachés au modele de courrier, s'il y en a
|
|
for file in local_retval:
|
|
local_JSON = ast.literal_eval(file)
|
|
|
|
saved_file = local_JSON['full_path']
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(saved_file)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
# Recuperation des données du stagaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
|
|
# Verifier si le modele de courrier est 'edit_by_client', au quel cas on verifie que l'apprenant est bien lié à un client
|
|
if ("edit_by_client" in courrier_template_data.keys() and str(courrier_template_data['edit_by_client']) == "1"):
|
|
stagiaire_client_id = ""
|
|
if( "client_rattachement_id" in inscription_data.keys() ):
|
|
stagiaire_client_id = str(inscription_data['client_rattachement_id'])
|
|
|
|
if( str(stagiaire_client_id).strip() == "" ):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible d'envoyer un document édité par client à un stagiaire qui n'est pas rattaché à un client. L'email de l'apprenant est "+str(inscription_data['email'])+" ")
|
|
return False, " Impossible d'envoyer un document édité par client à un stagiaire qui n'est pas rattaché à un client. L'email de l'apprenant est "+str(inscription_data['email'])+" "
|
|
|
|
|
|
|
|
tab_participant = []
|
|
tab_participant.append(inscription_data['_id'])
|
|
|
|
#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'])})
|
|
|
|
tab_session = []
|
|
tab_session.append(session_data['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
tab_apprenant = []
|
|
if ("apprenant_id" in inscription_data.keys() and inscription_data['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(inscription_data['apprenant_id'])))
|
|
|
|
|
|
# Recuperation du titre de la formation
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url': str(session_data['class_internal_url']),'valide': '1',
|
|
'partner_owner_recid':str(my_partner['recid']), 'locked':'0'})
|
|
|
|
tab_class = []
|
|
tab_class.append(class_data['_id'])
|
|
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = []
|
|
new_diction['list_apprenant_id'] = tab_apprenant
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
|
|
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
|
|
if ("joint_pdf" in courrier_template_data.keys() and str(courrier_template_data['joint_pdf']) == "1"):
|
|
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
|
|
"""
|
|
1 - Creation du PDF
|
|
"""
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
"""
|
|
new_model_courrier_with_code_tag = str(
|
|
sourceHtml) + " <p style='width: 300px; text-align: right;'> Signature Client <br/> <img style='height:150px; width:150px' src='{{ params.mysy_manual_signature_img }}'> </p> <br/> " \
|
|
" <p style='width: 300px; text-align: center;'> <img style='height:150px; width:150px;' src='{{ params.mysy_qrcode_securite }}'> </p> "
|
|
"""
|
|
new_model_courrier_with_code_tag = " <div style='width: 100%'> <div style = 'width: 100%; text-align: center;' >" \
|
|
" <img style = 'height:60px; width:60px;' src = '{{ params.mysy_qrcode_securite }}' > <br/>" \
|
|
" <nav style = 'font-size: 10px; font-style: italic;' > Sécurisé par MySy Training Technology </nav>" \
|
|
" <br/> </div> </div>" + \
|
|
str(sourceHtml) + " <div style='width: 100%'> <div style = 'width: 100%; text-align: center;' >" \
|
|
" Signature Client <br/> <img style = 'height:100px; width:100px' " \
|
|
" src = '{{ params.mysy_manual_signature_img }}' > <br/> " \
|
|
" </div> </div>"
|
|
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
# Attachement du fichier joint
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
|
|
## Creation du mail au format email
|
|
corps_mail_Template = jinja2.Template(str(courrier_template_data['corps_mail']))
|
|
|
|
sourceHtml = corps_mail_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
"""
|
|
20/03/2024 : la convention pdf a été créée.
|
|
Si le partenaire a l'option de signature digitale, alors on créé le e-document
|
|
"""
|
|
if (is_partner_digital_signature == "1"):
|
|
new_e_document_diction = {}
|
|
new_e_document_diction['token'] = diction['token']
|
|
new_e_document_diction['file_name'] = outputFilename
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
new_e_document_diction['email_destinataire'] = str(toaddrs)
|
|
new_e_document_diction['source_document'] = new_model_courrier_with_code_tag
|
|
|
|
new_e_document_diction['related_collection'] = "inscription"
|
|
new_e_document_diction['related_collection_id'] = str(inscription_data['_id'])
|
|
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-2:]
|
|
|
|
cononic_name = "Convention_" + str(todays_date) + "_" + str(ts)
|
|
new_e_document_diction['file_cononical_name'] = cononic_name
|
|
new_e_document_diction['type'] = "convention"
|
|
|
|
print(" ### 022 new_e_document_diction = ", new_e_document_diction)
|
|
|
|
local_status_e_doc, local_retval_e_doc = E_Sign_Document.Create_E_Document(new_e_document_diction)
|
|
|
|
if (local_status_e_doc is False):
|
|
return local_status_e_doc, local_retval_e_doc
|
|
|
|
"""
|
|
Apres la creation du document electronique, on envoie la demande de validation
|
|
/!\ on envoie le mail à chaque destinataire
|
|
"""
|
|
|
|
for email in tab_emails_destinataire:
|
|
print(" ### traitement du mail : ", email)
|
|
new_send_e_document_diction = {}
|
|
new_send_e_document_diction['token'] = diction['token']
|
|
new_send_e_document_diction['e_doc_id'] = str(local_retval_e_doc)
|
|
new_send_e_document_diction['user_email'] = str(email)
|
|
|
|
local_status_send_e_doc, local_send_retval_e_doc = E_Sign_Document.Sent_E_Document_Signature_Request(
|
|
new_send_e_document_diction)
|
|
if (local_status_send_e_doc is False):
|
|
return local_status_send_e_doc, local_send_retval_e_doc
|
|
|
|
else:
|
|
# Il s'agit d'une simple email
|
|
|
|
## Creation du mail au format email
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
|
|
"""
|
|
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
|
"""
|
|
partner_own_smtp_value = "0"
|
|
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'partner_smtp',
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
|
partner_own_smtp_value = partner_own_smtp['config_value']
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user_pwd',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_server',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_from_name',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_port',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
else:
|
|
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
#msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
# Attacher l'eventuelle pièces jointes
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
|
|
|
else:
|
|
msg.attach(html_mime)
|
|
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
#msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
|
|
|
val = smtpserver.send_message(msg)
|
|
smtpserver.close()
|
|
print(" Email envoyé " + str(val))
|
|
|
|
"""
|
|
25/01/2024 : pour loger une action dans la collection ==> courrier_template_tracking_history
|
|
"""
|
|
local_status, local_retval = module_editique.Editic_Log_History_Action(my_partner, courrier_template_data,
|
|
str(diction['session_id']),
|
|
"inscription",
|
|
str(diction['inscription_id']))
|
|
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
|
|
# L'action n'est loggué pour les envois reels (en prod)
|
|
if( send_in_production == 1):
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(diction['inscription_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = ""
|
|
if ("code_session" in session_data.keys()):
|
|
local_session_info = local_session_info + ", " + session_data["code_session"]
|
|
else:
|
|
local_session_info = "Id Session : " + str(session_data['_id'])
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : "+str(tab_emails_destinataire)+" pour la session "+str(local_session_info)
|
|
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))
|
|
|
|
# Pour la session
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(session_data['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = "Id Inscrit : " + str(inscription_data['_id'])
|
|
if ("email" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["email"]
|
|
|
|
if ("nom" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["nom"]
|
|
|
|
if ("prenom" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["prenom"]
|
|
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire)+" Pour l'inscrit "+str(local_inscrit_info)
|
|
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, "L'email a été correctement envoyé "
|
|
|
|
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'envoyer la convention par email "
|
|
|
|
|
|
"""
|
|
Comme la fonction plus haut (Sent_Convention_Stagiaire_By_Email) cette fonction est un clone
|
|
qui envoie uniquement et exclusivement les conventions individuelles.
|
|
|
|
Je les ai separé vu la complexité de la fonction et eviter des effets de bors/
|
|
|
|
"""
|
|
|
|
|
|
def Sent_Convention_Individuelle_Stagiaire_By_Email(tab_files, Folder, diction):
|
|
try:
|
|
|
|
field_list_obligatoire = ['token', 'inscription_id', 'courrier_template_id', 'email_test', 'email_production']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1" et qu'il n'est rattaché à aucun client
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'$or': [
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id': ''},
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id': {'$exists': False}
|
|
}]})
|
|
|
|
if (is_inscription_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
# Recuperation des données du stagaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
# Recupérer la liste des participants concernés
|
|
tab_participant = []
|
|
tab_participant.append(inscription_data['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
tab_apprenant = []
|
|
if ("apprenant_id" in inscription_data.keys() and inscription_data['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(inscription_data['apprenant_id'])))
|
|
|
|
|
|
# Traitement de l'eventuel fichier joint
|
|
tab_files_to_attache_to_mail = []
|
|
|
|
# Sauvegarde des fichiers joints depuis le front
|
|
tab_saved_file_full_path = []
|
|
for file in tab_files:
|
|
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
|
if (status is False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible de récupérer correctement le fichier à importer"
|
|
|
|
tab_saved_file_full_path.append(saved_file_full_path)
|
|
|
|
for saved_file in tab_saved_file_full_path:
|
|
"""
|
|
status, saved_file = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
|
if (status is False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible de récupérer correctement le fichier à importer"
|
|
"""
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(saved_file)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
# Verification de la validité des adresses email_recu
|
|
"""
|
|
/!\ : Si l'email de test est repli, alors on considere que c'est un test, on ne prend pas en compte l'email de email_production.
|
|
Ceci pour forcer les utilisateur à ne remplir que l'email de prod s'il veulent l'envoyer en prod.
|
|
|
|
Si l'adresse email_prodution = "defaul", cela veut dire qu'on envoie la convention à :
|
|
- l'adresse email du stagiaire et ses tuteurs (si les tuteurs on cochés la case 'inclu com'
|
|
|
|
"""
|
|
|
|
send_in_production = 0
|
|
|
|
tab_emails_destinataire = []
|
|
|
|
if ("email_test" in diction.keys() and diction['email_test']):
|
|
send_in_production = 0
|
|
tab_email_test = str(diction['email_test']).replace(";", ",").split(",")
|
|
for email in tab_email_test:
|
|
email = email.strip()
|
|
if (mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email " + str(email) + " est invalide ")
|
|
return False, " L'adresse email " + str(email) + " est invalide "
|
|
tab_emails_destinataire = tab_email_test
|
|
|
|
elif ("email_production" in diction.keys() and diction['email_production']):
|
|
send_in_production = 1
|
|
if (str(diction['email_production']) != "default"):
|
|
tab_email_prod = str(diction['email_production']).replace(";", ",").split(",")
|
|
for email in tab_email_prod:
|
|
email = email.strip()
|
|
if (mycommon.isEmailValide(str(email)) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email '" + str(email) + "' est invalide ")
|
|
return False, " L'adresse email " + str(email) + " est invalide "
|
|
tab_emails_destinataire = tab_email_prod
|
|
else:
|
|
send_in_production = 1
|
|
# On va chercher les adresse email de communication du
|
|
local_dict = {'token': str(diction['token']), '_id': str(diction['inscription_id'])}
|
|
|
|
local_status, tab_apprenant_contact = Get_Statgiaire_Communication_Contact(local_dict)
|
|
if (local_status is False):
|
|
return local_status, tab_apprenant_contact
|
|
|
|
tmp_tab = []
|
|
# print(" ### tab_apprenant_contact = ", tab_apprenant_contact)
|
|
|
|
for tmp in tab_apprenant_contact:
|
|
if ("email" in tmp.keys()):
|
|
tab_emails_destinataire.append((tmp['email']))
|
|
|
|
if (len(tab_emails_destinataire) <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Aucune adresse email n'a été fourni. ")
|
|
return False, " Aucune adresse email n'a été fourni. "
|
|
|
|
# print(" ### tab_emails_destinataire = ", tab_emails_destinataire)
|
|
|
|
# Verifier que le 'courrier_template_id' est valide
|
|
# Ici le template doit etre un email
|
|
courrier_template_data = None
|
|
if (str(diction['courrier_template_id']) == "default_mail"):
|
|
"""
|
|
# Verifier qu'il y a bien un modele de courrier de convention individuelle par defaut
|
|
- ref_interne = CONVENTION_STAGIAIRE
|
|
- default_version = 1
|
|
- edit_by_client = '0' ou n'existe pas
|
|
- type_doc = email
|
|
"""
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Aucun modèle de courrier PDF par defaut pour les conventions individuelles ")
|
|
return False, " Aucun modèle de courrier PDF par defaut pour les conventions individuelles "
|
|
|
|
# Recupération des données du modèle de document
|
|
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
else:
|
|
# Verifier que le 'courrier_template_id' est valide. il doit etre de type PDF
|
|
qry = {'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'email',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (courrier_template_data is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossile d'identifier le modèle de courrier ")
|
|
return False, " Impossile d'identifier le modèle de courrier "
|
|
|
|
|
|
|
|
# Recuperation des eventuelles pièces jointes du modèle que courrier
|
|
local_dic = {}
|
|
local_dic['token'] = str(diction['token'])
|
|
local_dic['object_owner_collection'] = "courrier_template"
|
|
local_dic['object_owner_id'] = str(courrier_template_data['_id'])
|
|
|
|
local_status, local_retval = attached_file_mgt.Get_List_object_owner_collection_Stored_Files(local_dic)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
# print(" ### file stocké = ", local_retval)
|
|
|
|
# Recuperation des fichiers attachés au modele de courrier, s'il y en a
|
|
for file in local_retval:
|
|
local_JSON = ast.literal_eval(file)
|
|
|
|
saved_file = local_JSON['full_path']
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(saved_file)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
|
|
|
|
# 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'])})
|
|
|
|
tab_session = []
|
|
tab_session.append(session_data['_id'])
|
|
|
|
# Recuperation du titre de la formation
|
|
class_data = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']), 'locked': '0'})
|
|
|
|
tab_class = []
|
|
tab_class.append(class_data['_id'])
|
|
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = []
|
|
new_diction['list_apprenant_id'] = tab_apprenant
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
|
|
if ("joint_pdf" in courrier_template_data.keys() and str(courrier_template_data['joint_pdf']) == "1"):
|
|
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
|
|
"""
|
|
1 - Creation du PDF
|
|
"""
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
# Attachement du fichier joint
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
## Creation du mail au format email
|
|
|
|
corps_mail_Template = jinja2.Template(str(courrier_template_data['corps_mail']))
|
|
|
|
sourceHtml = corps_mail_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
else:
|
|
# Il s'agit d'une simple email
|
|
|
|
## Creation du mail au format email
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
"""
|
|
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
|
"""
|
|
partner_own_smtp_value = "0"
|
|
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'partner_smtp',
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
|
partner_own_smtp_value = partner_own_smtp['config_value']
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user_pwd',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_server',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_from_name',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_port',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
else:
|
|
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
# msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
# Attacher l'eventuelle pièces jointes
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
|
|
|
else:
|
|
msg.attach(html_mime)
|
|
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
# msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
|
|
|
val = smtpserver.send_message(msg)
|
|
smtpserver.close()
|
|
print(" Email envoyé " + str(val))
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
|
|
# L'action n'est loggué pour les envois reels (en prod)
|
|
if (send_in_production == 1):
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(diction['inscription_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = ""
|
|
if ("code_session" in session_data.keys()):
|
|
local_session_info = local_session_info + ", " + session_data["code_session"]
|
|
else:
|
|
local_session_info = "Id Session : " + str(session_data['_id'])
|
|
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire) + " pour la session " + str(local_session_info)
|
|
|
|
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))
|
|
|
|
# Pour la session
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(session_data['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = "Id Inscrit : " + str(inscription_data['_id'])
|
|
if ("email" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["email"]
|
|
|
|
if ("nom" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["nom"]
|
|
|
|
if ("prenom" in inscription_data.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription_data["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire) + " Pour l'inscrit " + str(local_inscrit_info)
|
|
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, "L'email a été correctement envoyé "
|
|
|
|
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'envoyer la convention par email "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction envoie les convention en masse
|
|
Dans cette fonction, les adresse emails de destination sont recuperé dans la fonction.
|
|
Ce n'est l'utilisateur qui envoie le fonction
|
|
"""
|
|
|
|
|
|
def Sent_Convention_Stagiaire_By_Email_mass(tab_files, Folder, diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'tab_inscription_id', 'courrier_template_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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 le 'courrier_template_id' est valide
|
|
# Ici le template doit etre un email
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'type_doc': 'email',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
|
|
tab_new_diction = []
|
|
tab_inscription_id = str(diction['tab_inscription_id']).split(",")
|
|
for inscription_id in tab_inscription_id:
|
|
# Verifier que le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1"
|
|
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(inscription_id)),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_inscription_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
# Récuperation des emails de communication de cette inscription
|
|
local_status, local_list_mail = Get_Stagiaire_Communication_List_Email({'token':diction['token'], 'inscription_id':str(inscription_id)})
|
|
if( local_status is False ):
|
|
return local_status, local_list_mail
|
|
|
|
|
|
tab_liste_mail = []
|
|
liste_mail_string = ""
|
|
for email in local_list_mail:
|
|
email_JSON = ast.literal_eval(email)
|
|
if( 'email' in email_JSON.keys() ):
|
|
tab_liste_mail.append(email_JSON['email'])
|
|
|
|
liste_mail_string = ', '.join(tab_liste_mail)
|
|
|
|
new_node = {}
|
|
new_node['token'] = str(diction['token'])
|
|
new_node['inscription_id'] = str(inscription_id)
|
|
new_node['courrier_template_id'] = str(diction['courrier_template_id'])
|
|
new_node['email_production'] = str(liste_mail_string)
|
|
new_node['email_test'] = ""
|
|
|
|
tab_new_diction.append(new_node)
|
|
|
|
nb_convocation_send = 0
|
|
warning_msg = " WARNING : Convocation(s) envoyée(s) avec les erreurs suivantes : \n : "
|
|
is_warning_msg = False
|
|
for new_diction in tab_new_diction:
|
|
local_status, local_retval = Sent_Convention_Stagiaire_By_Email(tab_files, Folder, new_diction)
|
|
if( local_status is False):
|
|
warning_msg = warning_msg + " Impossible d'envoyer les convocation à l'apprenant avec ayant la liste de communication : "+str(new_diction['email_production']) +" \n "
|
|
is_warning_msg = True
|
|
else:
|
|
nb_convocation_send = nb_convocation_send + 1
|
|
|
|
if( is_warning_msg ):
|
|
return True, str(warning_msg)
|
|
else:
|
|
return True, str(nb_convocation_send)+" convocation(s) envoyée(s) "
|
|
|
|
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'envoyer la convention par email "
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Creation d'un fichie zip de pdf
|
|
"""
|
|
|
|
def Download_zip_PDF():
|
|
try:
|
|
|
|
files = ['./temp_direct/pdf1.pdf', './temp_direct/pdf3.pdf', './temp_direct/pdf3.pdf']
|
|
|
|
# Create a ZipFile Object
|
|
with ZipFile('./temp_direct/mysy.zip', 'w') as zip_object:
|
|
# Adding files that need to be zipped
|
|
zip_object.write('./temp_direct/pdf1.pdf')
|
|
zip_object.write('./temp_direct/pdf3.pdf')
|
|
zip_object.write('./temp_direct/pdf3.pdf')
|
|
|
|
# Check to see if the zip file is created
|
|
if os.path.exists('./temp_direct/mysy.zip'):
|
|
print("ZIP file created")
|
|
else:
|
|
print("ZIP file not created")
|
|
|
|
if os.path.exists("./temp_direct/mysy.zip"):
|
|
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file("./temp_direct/mysy.zip", as_attachment=True)
|
|
|
|
return False, " Impossible de générer le fichier PDF (2) "
|
|
|
|
|
|
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 générer le fichier PDF (2) "
|
|
|
|
"""
|
|
Impression de la convocation en mode PDF
|
|
"""
|
|
|
|
def Download_Convention_Stagiaire_PDF(diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'inscription_id', 'courrier_template_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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1"
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_inscription_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
|
|
courrier_template_data = None
|
|
if( str(diction['courrier_template_id']) == "default_pdf"):
|
|
"""
|
|
# Verifier qu'il y a bien un modele de courrier de convention individuelle par defaut
|
|
- ref_interne = CONVENTION_STAGIAIRE
|
|
- default_version = 1
|
|
- edit_by_client = '0' ou n'existe pas
|
|
- type_doc = pdf
|
|
"""
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Aucun modèle de courrier PDF par defaut pour les conventions individuelles ")
|
|
return False, " Aucun modèle de courrier PDF par defaut pour les conventions individuelles "
|
|
|
|
# Recupération des données du modèle de document
|
|
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
else:
|
|
# Verifier que le 'courrier_template_id' est valide. il doit etre de type PDF
|
|
qry = {'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if( courrier_template_data is None ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossile d'identifier le modèle de courrier ")
|
|
return False, " Impossile d'identifier le modèle de courrier "
|
|
|
|
# Recuperation des données du stagaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'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
|
|
|
|
|
|
# Recuperations des info de la session de formation
|
|
tab_session = []
|
|
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'])})
|
|
|
|
tab_session.append(session_data['_id'])
|
|
|
|
|
|
# Recupérer la liste des participant pour une eventuelle à afficher pour les conventions d'entreprise
|
|
tab_participant = []
|
|
tab_apprenant = []
|
|
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, '_id':1}).sort([("nom", pymongo.DESCENDING)])
|
|
|
|
for val in list_participants_session:
|
|
tab_participant.append(val['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
|
|
if ("apprenant_id" in val.keys() and val['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(val['apprenant_id'])))
|
|
|
|
|
|
# Recuperation du titre de la formation
|
|
class_data = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']), 'locked': '0'})
|
|
|
|
tab_class = []
|
|
tab_class.append(class_data['_id'])
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
convention_dictionnary_data = {}
|
|
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = []
|
|
new_diction['list_apprenant_id'] = tab_apprenant
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
|
|
#print(" ### convention_dictionnary_data = ", convention_dictionnary_data)
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
json_formatted_str = json.dumps(body, indent=2)
|
|
|
|
print(json_formatted_str)
|
|
|
|
## Creation du PDF
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
if os.path.exists(outputFilename):
|
|
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
return False, " Impossible de générer le fichier PDF (2) "
|
|
|
|
|
|
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 générer le fichier PDF (2) "
|
|
|
|
|
|
"""
|
|
Impression d'une convention individuelle en pdf
|
|
"""
|
|
def Download_Convention_Individuelle_Stagiaire_PDF(diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'inscription_id', 'courrier_template_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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1" et qu'il n'est pas rattaché à un client
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents({'$or':[
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id':''},
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id': {'$exists': False}
|
|
}]} )
|
|
|
|
|
|
|
|
if (is_inscription_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
|
|
courrier_template_data = None
|
|
if( str(diction['courrier_template_id']) == "default_pdf"):
|
|
"""
|
|
# Verifier qu'il y a bien un modele de courrier de convention individuelle par defaut
|
|
- ref_interne = CONVENTION_STAGIAIRE
|
|
- default_version = 1
|
|
- edit_by_client = '0' ou n'existe pas
|
|
- type_doc = pdf
|
|
"""
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][
|
|
3]) + " Aucun modèle de courrier PDF par defaut pour les conventions individuelles ")
|
|
return False, " Aucun modèle de courrier PDF par defaut pour les conventions individuelles "
|
|
|
|
# Recupération des données du modèle de document
|
|
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one({"$or": [
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': '0'
|
|
},
|
|
{'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'ref_interne': 'CONVENTION_STAGIAIRE',
|
|
'default_version': '1',
|
|
'edit_by_client': {'$exists': False}
|
|
}
|
|
]})
|
|
|
|
else:
|
|
# Verifier que le 'courrier_template_id' est valide. il doit etre de type PDF
|
|
qry = {'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if( courrier_template_data is None ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossile d'identifier le modèle de courrier ")
|
|
return False, " Impossile d'identifier le modèle de courrier "
|
|
|
|
# Recuperation des données du stagaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
tab_participant = []
|
|
tab_participant.append(inscription_data['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
tab_apprenant = []
|
|
if ("apprenant_id" in inscription_data.keys() and inscription_data['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(inscription_data['apprenant_id'])))
|
|
|
|
# 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
|
|
|
|
|
|
# Recuperations des info de la session de formation
|
|
tab_session = []
|
|
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'])})
|
|
|
|
tab_session.append(session_data['_id'])
|
|
|
|
|
|
# Recuperation du titre de la formation
|
|
class_data = MYSY_GV.dbname['myclass'].find_one(
|
|
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']), 'locked': '0'})
|
|
|
|
tab_class = []
|
|
tab_class.append(class_data['_id'])
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
convention_dictionnary_data = {}
|
|
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = []
|
|
new_diction['list_apprenant_id'] = tab_apprenant
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
|
|
#print(" ### convention_dictionnary_data = ", convention_dictionnary_data)
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
json_formatted_str = json.dumps(body, indent=2)
|
|
|
|
#print(json_formatted_str)
|
|
|
|
## Creation du PDF
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
if os.path.exists(outputFilename):
|
|
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
return False, " Impossible de générer le fichier PDF (2) "
|
|
|
|
|
|
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 générer le fichier PDF (2) "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Pour les statgiaires rattaché à un client, edite les convetions pour le client
|
|
donc avec la liste des participants
|
|
"""
|
|
def Download_Convention_Stagiaire_PDF_By_Partner_client(diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'courrier_template_id', 'partner_client_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 la liste des arguments ")
|
|
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 la session est valide
|
|
is_session_id_valide = MYSY_GV.dbname['session_formation'].count_documents({'_id':ObjectId(str(diction['session_id'])),
|
|
'valide':'1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_session_id_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide "
|
|
|
|
|
|
|
|
# Verifier que ce client a bien des inscriptions valide pour cette session
|
|
is_valide_inscription_pr_client = MYSY_GV.dbname['inscription'].count_documents({'client_rattachement_id':str(diction['partner_client_id']),
|
|
'session_id':str(diction['session_id']),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'status':'1'})
|
|
|
|
|
|
if (is_valide_inscription_pr_client <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Aucune inscription valide pour ce client pour cette session ")
|
|
return False, " Aucune inscription valide pour ce client pour cette session "
|
|
|
|
partner_client_id_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_recid':str(my_partner['recid'])})
|
|
|
|
tab_client = []
|
|
tab_client.append(partner_client_id_data['_id'])
|
|
|
|
# Verifier que le 'courrier_template_id' est valide. il doit etre de type PDF
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'type_doc': 'pdf',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
# Recuperations des info de la session de formation
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])), 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])}, {'_id':1, 'class_internal_url':1})
|
|
|
|
|
|
tab_session = [session_data['_id']]
|
|
print(" tab_session = ", tab_session)
|
|
|
|
tab_apprenant = []
|
|
tab_participant = []
|
|
# Recupérer la liste des participant pour une eventuelle à afficher pour les conventions d'entreprise
|
|
for participant in MYSY_GV.dbname['inscription'].find({'session_id':str(session_data['_id']), 'status':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])},
|
|
{'_id':1}):
|
|
tab_participant.append(participant['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
|
|
if ("apprenant_id" in participant.keys() and participant['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(participant['apprenant_id'])))
|
|
|
|
|
|
print(" tab_participant = ", tab_participant)
|
|
|
|
|
|
# Recuperation du titre de la formation
|
|
tab_class = []
|
|
for class_data in MYSY_GV.dbname['myclass'].find(
|
|
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']), 'locked': '0'}, {'_id':1}):
|
|
tab_class.append(class_data['_id'])
|
|
|
|
|
|
print(" tab_class = ", tab_class)
|
|
|
|
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = tab_client
|
|
new_diction['list_apprenant_id'] = tab_apprenant
|
|
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if( local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
|
|
print(" ### convention_dictionnary_data = ")
|
|
|
|
#json_object = ast.literal_eval(convention_dictionnary_data)
|
|
|
|
json_formatted_str = json.dumps(convention_dictionnary_data, indent=2)
|
|
|
|
print(json_formatted_str)
|
|
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
## Creation du PDF
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
if os.path.exists(outputFilename):
|
|
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
return False, " Impossible de générer le fichier PDF (2) "
|
|
|
|
|
|
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 générer le fichier PDF (2) "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Envoie par email pour les stagiaires rattachés à un client
|
|
|
|
important :
|
|
si le champ 'email_test' est rempli, alors il s'agit d'un email de test.
|
|
donc on n'envoie pas l'email à l'adresss de prod ou contact du client
|
|
"""
|
|
def Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files_name_full_path, Folder, diction):
|
|
try:
|
|
|
|
field_list_obligatoire = ['token', 'courrier_template_id', 'email_test', 'email_production', 'partner_client_id', 'session_id',
|
|
'request_digital_signature']
|
|
|
|
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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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
|
|
|
|
"""
|
|
20/03/2024 : Creation du E-Document à signer
|
|
On verifier si le partenaire dispose de l'option "signature_digital" dans la collection base_partner_setup
|
|
|
|
ET SI DEPUIS LE FRONT, L'UTILISATEUR DECIDE DE L'UTILISER
|
|
"""
|
|
is_partner_digital_signature = ""
|
|
if( "request_digital_signature" in diction.keys() and diction['request_digital_signature'] == "1"):
|
|
|
|
is_signature_digital_count = MYSY_GV.dbname['base_partner_setup'].count_documents(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'signature_digital',
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'config_value': '1'})
|
|
if (is_signature_digital_count == 1):
|
|
is_partner_digital_signature = "1"
|
|
|
|
# Verifier que la session est valide
|
|
is_session_id_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_session_id_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide "
|
|
|
|
# Verifier que ce client a bien des inscriptions valide pour cette session
|
|
is_valide_inscription_pr_client = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'client_rattachement_id': str(diction['partner_client_id']),
|
|
'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'status': '1'})
|
|
|
|
if (is_valide_inscription_pr_client <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Aucune inscription valide pour ce client pour cette session ")
|
|
return False, " Aucune inscription valide pour ce client pour cette session "
|
|
|
|
partner_client_id_data = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(str(diction['partner_client_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
# Traitement de l'eventuel fichier joint
|
|
tab_files_to_attache_to_mail = []
|
|
|
|
for file_name_full_path in tab_files_name_full_path:
|
|
"""status, saved_file = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
|
if (status is False):
|
|
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
|
return False, "Impossible de récupérer correctement le fichier à importer"
|
|
"""
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(file_name_full_path, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(file_name_full_path)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
# Verification de la validité des adresses email_recu
|
|
"""
|
|
/!\ : Si l'email de test est repli, alors on considere que c'est un test, on ne prend pas en compte l'email de email_production.
|
|
Ceci pour forcer les utilisateur à ne remplir que l'email de prod s'il veulent l'envoyer en prod.
|
|
|
|
Si l'adresse email_prodution = "defaul", cela veut dire qu'on envoie la convention à :
|
|
- l'adresse email du stagiaire et ses tuteurs (si les tuteurs on cochés la case 'inclu com'
|
|
|
|
"""
|
|
|
|
send_in_production = 0
|
|
|
|
tab_emails_destinataire = []
|
|
if ("email_test" in diction.keys() and diction['email_test']):
|
|
tab_email_test = str(diction['email_test']).replace(";", ",").split(",")
|
|
for email in tab_email_test:
|
|
email = email.strip()
|
|
if (mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email " + str(email) + " est invalide ")
|
|
return False, " L'adresse email " + str(email) + " est invalide "
|
|
tab_emails_destinataire = tab_email_test
|
|
|
|
elif ("email_production" in diction.keys() and diction['email_production']):
|
|
send_in_production = 1
|
|
if (str(diction['email_production']) != "default"):
|
|
tab_email_prod = str(diction['email_production']).replace(";", ",").split(",")
|
|
for email in tab_email_prod:
|
|
email = email.strip()
|
|
if (mycommon.isEmailValide(str(email)) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'adresse email '" + str(email) + "' est invalide ")
|
|
return False, " L'adresse email " + str(email) + " est invalide "
|
|
tab_emails_destinataire = tab_email_prod
|
|
else:
|
|
tab_email_prod = "default"
|
|
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Aucune adresse email n'a été fourni. ")
|
|
return False, " Aucune adresse email n'a été fourni. "
|
|
|
|
|
|
#print(" ## laaa : tab_emails_destinataire lalala = ", tab_emails_destinataire)
|
|
|
|
# Verifier que le 'courrier_template_id' est valide
|
|
# Ici le template doit etre un email
|
|
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
|
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
|
'valide': '1',
|
|
'type_doc': 'email',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
if (is_courrier_template_id_valide != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant du modèle de courrier est invalide ")
|
|
return False, " L'identifiant du modèle de courrier est invalide "
|
|
|
|
# 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'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
# Recuperation des eventuelles pièces jointes du modèle que courrier
|
|
local_dic = {}
|
|
local_dic['token'] = str(diction['token'])
|
|
local_dic['object_owner_collection'] = "courrier_template"
|
|
local_dic['object_owner_id'] = str(courrier_template_data['_id'])
|
|
|
|
local_status, local_retval = attached_file_mgt.Get_List_object_owner_collection_Stored_Files(local_dic)
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
# print(" ### file stocké = ", local_retval)
|
|
|
|
# Recuperation des fichiers attachés au modele de courrier, s'il y en a
|
|
|
|
for file in local_retval:
|
|
local_JSON = ast.literal_eval(file)
|
|
|
|
saved_file = local_JSON['full_path']
|
|
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(saved_file, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(saved_file)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
# Recuperation des données du stagiaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id':str(diction['partner_client_id'])})
|
|
tab_apprenant = []
|
|
tab_participant = []
|
|
for val in inscription_data:
|
|
tab_participant.append(val['_id'])
|
|
|
|
"""
|
|
update du 30/01/2024
|
|
si le participant à un apprenant_id, alors on recupere la valeur de l'apprenant id. On doit travailler sur cette dernier.
|
|
En general, avant d'envoyer une convocation ou convention, l'inscription est validée et donc le dossier apprenant existe.
|
|
Du coup si tout se passe bien, dans cette fonction, on travaillera tjrs avec l'apprenant_id
|
|
"""
|
|
|
|
if ("apprenant_id" in val.keys() and val['apprenant_id']):
|
|
tab_apprenant.append(ObjectId(str(val['apprenant_id'])))
|
|
|
|
|
|
#print(" ### tab_participant = ", tab_participant)
|
|
|
|
# Recuperations des info de la session de formation
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id']))})
|
|
|
|
tab_session = []
|
|
tab_session.append(session_data['_id'])
|
|
|
|
|
|
# Recuperation du titre de la formation
|
|
class_data = MYSY_GV.dbname['myclass'].find({'internal_url': str(session_data['class_internal_url']),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'locked': '0'})
|
|
|
|
tab_class = []
|
|
for val in class_data:
|
|
tab_class.append(val['_id'])
|
|
|
|
# Recuperer les données du client
|
|
client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(diction['partner_client_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_recid': str(my_partner['recid']),
|
|
})
|
|
|
|
|
|
tab_client = []
|
|
tab_client.append(client_data['_id'])
|
|
|
|
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = tab_participant
|
|
new_diction['list_session_id'] = tab_session
|
|
new_diction['list_class_id'] = tab_class
|
|
new_diction['list_client_id'] = tab_client
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
convention_dictionnary_data = local_retval
|
|
|
|
|
|
## Creation du PDF
|
|
|
|
body = {
|
|
"params": convention_dictionnary_data,
|
|
}
|
|
|
|
# ---
|
|
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
|
|
if ("joint_pdf" in courrier_template_data.keys() and str(courrier_template_data['joint_pdf']) == "1"):
|
|
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
|
|
"""
|
|
1 - Creation du PDF
|
|
"""
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
"""
|
|
new_model_courrier_with_code_tag = str(sourceHtml) + " <p style='width: 300px; text-align: right;'> Signature Client <br/> <img style='height:150px; width:150px' src='{{ params.mysy_manual_signature_img }}'> </p> <br/> " \
|
|
" <p style='width: 300px; text-align: center;'> <img style='height:150px; width:150px;' src='{{ params.mysy_qrcode_securite }}'> </p> "
|
|
"""
|
|
new_model_courrier_with_code_tag = " <div style='width: 100%'> <div style = 'width: 100%; text-align: center;' >" \
|
|
" <img style = 'height:60px; width:60px;' src = '{{ params.mysy_qrcode_securite }}' > <br/>" \
|
|
" <nav style = 'font-size: 10px; font-style: italic;' > Sécurisé par MySy Training Technology </nav>" \
|
|
" <br/> </div> </div>" + \
|
|
str(sourceHtml)+ " <div style='width: 100%'> <div style = 'width: 100%; text-align: center;' >" \
|
|
" Signature Client <br/> <img style = 'height:100px; width:100px' " \
|
|
" src = '{{ params.mysy_manual_signature_img }}' > <br/> " \
|
|
" </div> </div>"
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Convention_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
# open output file for writing (truncated binary)
|
|
resultFile = open(outputFilename, "w+b")
|
|
|
|
# convert HTML to PDF
|
|
pisaStatus = pisa.CreatePDF(
|
|
src=sourceHtml, # the HTML to convert
|
|
dest=resultFile) # file handle to receive result
|
|
|
|
# close output file
|
|
resultFile.close()
|
|
|
|
# Attachement du fichier joint
|
|
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
|
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
|
|
|
encoders.encode_base64(file_to_attache_to_mail)
|
|
file_to_attache_to_mail.add_header('Content-Disposition',
|
|
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
|
|
|
new_node = {"attached_file": file_to_attache_to_mail}
|
|
tab_files_to_attache_to_mail.append(new_node)
|
|
|
|
## Creation du mail au format email
|
|
|
|
corps_mail_Template = jinja2.Template(str(courrier_template_data['corps_mail']))
|
|
|
|
sourceHtml = corps_mail_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
"""
|
|
20/03/2024 : la convention pdf a été créée.
|
|
Si le partenaire a l'option de signature digitale, alors on créé le e-document
|
|
"""
|
|
if( is_partner_digital_signature == "1"):
|
|
new_e_document_diction = {}
|
|
new_e_document_diction['token'] = diction['token']
|
|
new_e_document_diction['file_name'] = outputFilename
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
new_e_document_diction['email_destinataire'] = str(toaddrs)
|
|
new_e_document_diction['source_document'] = new_model_courrier_with_code_tag
|
|
|
|
new_e_document_diction['related_collection'] = "partner_client"
|
|
new_e_document_diction['related_collection_id'] = str(client_data['_id'])
|
|
|
|
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-2:]
|
|
|
|
cononic_name = "Convention_" + str(todays_date) + "_" + str(ts)
|
|
new_e_document_diction['file_cononical_name'] = cononic_name
|
|
new_e_document_diction['type'] = "convention"
|
|
|
|
#print(" ### 011 new_e_document_diction = ", new_e_document_diction)
|
|
local_status_e_doc, local_retval_e_doc = E_Sign_Document.Create_E_Document(new_e_document_diction)
|
|
|
|
if(local_status_e_doc is False ):
|
|
return local_status_e_doc, local_retval_e_doc
|
|
|
|
"""
|
|
Apres la creation du document electronique, on envoie la demande de validation
|
|
/!\ on envoie le mail à chaque destinataire
|
|
"""
|
|
|
|
for email in tab_emails_destinataire :
|
|
#print(" ### traitement du mail : ", email)
|
|
new_send_e_document_diction = {}
|
|
new_send_e_document_diction['token'] = diction['token']
|
|
new_send_e_document_diction['e_doc_id'] = str(local_retval_e_doc)
|
|
new_send_e_document_diction['user_email'] = str(email)
|
|
|
|
|
|
local_status_send_e_doc, local_send_retval_e_doc = E_Sign_Document.Sent_E_Document_Signature_Request(new_send_e_document_diction)
|
|
if( local_status_send_e_doc is False ):
|
|
return local_status_send_e_doc, local_send_retval_e_doc
|
|
|
|
|
|
else:
|
|
# Il s'agit d'une simple email
|
|
|
|
## Creation du mail au format email
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
# ---
|
|
|
|
"""
|
|
## Creation du PDF
|
|
|
|
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
|
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
"""
|
|
"""
|
|
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
|
"""
|
|
partner_own_smtp_value = "0"
|
|
partner_own_smtp = MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'partner_smtp',
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (partner_own_smtp and "config_value" in partner_own_smtp.keys()):
|
|
partner_own_smtp_value = partner_own_smtp['config_value']
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
partner_SMTP_COUNT_password = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user_pwd',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_smtpsrv = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_server',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_user = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_user',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_From_User = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_from_name',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
partner_SMTP_COUNT_port = str(MYSY_GV.dbname['base_partner_setup'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'config_name': 'smtp_count_port',
|
|
'valide': '1',
|
|
'locked': '0'}, {'config_value': 1})['config_value'])
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
else:
|
|
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
# msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
# Attacher l'eventuelle pièces jointes
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
|
|
|
else:
|
|
msg.attach(html_mime)
|
|
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = courrier_template_data['sujet']
|
|
# msg['to'] = "billardman01@hotmail.com"
|
|
toaddrs = ",".join(tab_emails_destinataire)
|
|
msg['to'] = str(toaddrs)
|
|
|
|
for myfile in tab_files_to_attache_to_mail:
|
|
msg.attach(myfile['attached_file'])
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
|
|
|
val = smtpserver.send_message(msg)
|
|
smtpserver.close()
|
|
print(" Email envoyé " + str(val))
|
|
|
|
|
|
"""
|
|
25/01/2024 : pour loger une action dans la collection ==> courrier_template_tracking_history
|
|
"""
|
|
# Recuperation des données du stagiaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id': str(
|
|
diction['partner_client_id'])})
|
|
|
|
for inscription in inscription_data:
|
|
|
|
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
|
my_partner, "CONVENTION_STAGIAIRE_ENTREPRISE", str(diction['session_id']), 'inscription',
|
|
str(inscription['_id']), str(courrier_template_data['_id']))
|
|
|
|
#print(" local_status = ", local_status)
|
|
|
|
|
|
"""
|
|
# Ajout de l'evenement dans l'historique
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
# L'action n'est loggué pour les envois reels (en prod)
|
|
if (send_in_production == 1):
|
|
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "partner_client"
|
|
history_event_dict['related_collection_recid'] = str(diction['partner_client_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire)
|
|
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))
|
|
|
|
# Recuperation des données du stagiaire
|
|
inscription_data = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'client_rattachement_id': str(
|
|
diction['partner_client_id'])})
|
|
|
|
for inscription in inscription_data:
|
|
|
|
# Pour la collection inscription
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "inscription"
|
|
history_event_dict['related_collection_recid'] = str(inscription['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_session_info = ""
|
|
if ("code_session" in session_data.keys()):
|
|
local_session_info = local_session_info + ", " + session_data["code_session"]
|
|
else:
|
|
local_session_info = "Id Session : " + str(session_data['_id'])
|
|
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire)+" pour la session "+str(local_session_info)
|
|
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))
|
|
|
|
# Pour la collection session_formation
|
|
history_event_dict = {}
|
|
history_event_dict['token'] = diction['token']
|
|
history_event_dict['related_collection'] = "session_formation"
|
|
history_event_dict['related_collection_recid'] = str(session_data['_id'])
|
|
history_event_dict['action_date'] = str(now)
|
|
|
|
local_inscrit_info = "Id Inscrit : " + str(inscription['_id'])
|
|
if ("email" in inscription.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription["email"]
|
|
|
|
if ("nom" in inscription.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription["nom"]
|
|
|
|
if ("prenom" in inscription.keys()):
|
|
local_inscrit_info = local_inscrit_info + ", " + inscription["prenom"]
|
|
|
|
history_event_dict['action_description'] = "Convention envoyée par email à la liste : " + str(
|
|
tab_emails_destinataire) + " pour l'inscrit " + str(local_inscrit_info)
|
|
|
|
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, "L'email a été correctement envoyé "
|
|
|
|
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'envoyer la convention par email "
|
|
|
|
|
|
"""
|
|
Cette fonction retourne la liste des adresses emails de communication
|
|
d'un apprenant.
|
|
Cela peut inclure les 2 tuteurs ou pas selon les parametrage
|
|
"""
|
|
def Get_Stagiaire_Communication_List_Email(diction):
|
|
try:
|
|
field_list_obligatoire = ['token', 'inscription_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"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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 le stagiaire est bien inscrit. Le statut de l'inscription doit etre "1"
|
|
|
|
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_inscription_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
is_inscription_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
if( "email" in is_inscription_data.keys()):
|
|
node = {"email":str(is_inscription_data['email'])}
|
|
RetObject.append(mycommon.JSONEncoder().encode(node))
|
|
|
|
|
|
if( "tuteur1_include_com" in is_inscription_data.keys() and str(is_inscription_data['tuteur1_include_com']) == "1"
|
|
and "tuteur1_email" in is_inscription_data.keys() and is_inscription_data['tuteur1_email']):
|
|
node = {"email": str(is_inscription_data['tuteur1_email'])}
|
|
RetObject.append(mycommon.JSONEncoder().encode(node))
|
|
|
|
if ("tuteur2_include_com" in is_inscription_data.keys() and str(
|
|
is_inscription_data['tuteur2_include_com']) == "1"
|
|
and "tuteur2_email" in is_inscription_data.keys() and is_inscription_data['tuteur2_email']):
|
|
node = {"email": str(is_inscription_data['tuteur2_email'])}
|
|
RetObject.append(mycommon.JSONEncoder().encode(node))
|
|
|
|
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 emails de communication "
|
|
|
|
|
|
"""
|
|
Cette fonction permet de recuperer les contacts de communication d'un stagiaire.
|
|
Par exemple :
|
|
- le stagiaire, le tuteur1 et le tuteur 2
|
|
|
|
"""
|
|
def Get_Statgiaire_Communication_Contact(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'existe pas")
|
|
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
|
|
|
|
|
|
# Verifier la validité du client
|
|
is_stagiaire_exist_valide = MYSY_GV.dbname['inscription'].count_documents({"_id":ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_stagiaire_exist_valide <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du stagiaire est invalide ")
|
|
return False, " L'identifiant du stagiaire est invalide ",
|
|
|
|
# Verifier la validité du client
|
|
stagiaire_data = MYSY_GV.dbname['inscription'].find_one(
|
|
{"_id": ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
tab_stagiaire_contact_communication = []
|
|
|
|
# Ajout des datas du stagiaire
|
|
new_node = {}
|
|
if ("nom" in stagiaire_data.keys()):
|
|
new_node['nom'] = stagiaire_data['nom']
|
|
else:
|
|
new_node['nom'] = ""
|
|
|
|
if ("prenom" in stagiaire_data.keys()):
|
|
new_node['prenom'] = stagiaire_data['prenom']
|
|
else:
|
|
new_node['prenom'] = ""
|
|
|
|
if ("adresse" in stagiaire_data.keys()):
|
|
new_node['adresse'] = stagiaire_data['adresse']
|
|
else:
|
|
new_node['adresse'] = ""
|
|
|
|
if ("code_postal" in stagiaire_data.keys()):
|
|
new_node['code_postal'] = stagiaire_data['code_postal']
|
|
else:
|
|
new_node['code_postal'] = ""
|
|
|
|
if ("ville" in stagiaire_data.keys()):
|
|
new_node['ville'] = stagiaire_data['ville']
|
|
else:
|
|
new_node['ville'] = ""
|
|
|
|
if ("pays" in stagiaire_data.keys()):
|
|
new_node['pays'] = stagiaire_data['pays']
|
|
else:
|
|
new_node['pays'] = ""
|
|
|
|
if ("email" in stagiaire_data.keys()):
|
|
new_node['email'] = stagiaire_data['email']
|
|
else:
|
|
new_node['email'] = ""
|
|
|
|
if ("telephone" in stagiaire_data.keys()):
|
|
new_node['telephone'] = stagiaire_data['telephone']
|
|
else:
|
|
new_node['telephone'] = ""
|
|
|
|
tab_stagiaire_contact_communication.append(new_node)
|
|
|
|
|
|
# Ajout des datas du tuteur 1 s'il est autorisé
|
|
if( stagiaire_data and "tuteur1_include_com" in stagiaire_data.keys() and str(stagiaire_data['tuteur1_include_com']) == "1" ):
|
|
new_node = {}
|
|
if( "tuteur1_nom" in stagiaire_data.keys()):
|
|
new_node['nom'] = stagiaire_data['tuteur1_nom']
|
|
else:
|
|
new_node['nom'] = ""
|
|
|
|
if ("tuteur1_prenom" in stagiaire_data.keys()):
|
|
new_node['prenom'] = stagiaire_data['tuteur1_prenom']
|
|
else:
|
|
new_node['prenom'] = ""
|
|
|
|
if ("tuteur1_adresse" in stagiaire_data.keys()):
|
|
new_node['adresse'] = stagiaire_data['tuteur1_adresse']
|
|
else:
|
|
new_node['adresse'] = ""
|
|
|
|
if ("tuteur1_cp" in stagiaire_data.keys()):
|
|
new_node['code_postal'] = stagiaire_data['tuteur1_cp']
|
|
else:
|
|
new_node['code_postal'] = ""
|
|
|
|
if ("tuteur1_ville" in stagiaire_data.keys()):
|
|
new_node['ville'] = stagiaire_data['tuteur1_ville']
|
|
else:
|
|
new_node['ville'] = ""
|
|
|
|
if ("tuteur1_pays" in stagiaire_data.keys()):
|
|
new_node['pays'] = stagiaire_data['tuteur1_pays']
|
|
else:
|
|
new_node['pays'] = ""
|
|
|
|
if ("tuteur1_email" in stagiaire_data.keys()):
|
|
new_node['email'] = stagiaire_data['tuteur1_email']
|
|
else:
|
|
new_node['email'] = ""
|
|
|
|
if ("tuteur1_telephone" in stagiaire_data.keys()):
|
|
new_node['telephone'] = stagiaire_data['tuteur1_telephone']
|
|
else:
|
|
new_node['telephone'] = ""
|
|
|
|
|
|
tab_stagiaire_contact_communication.append(new_node)
|
|
|
|
|
|
# Ajout des datas du tuteur 2 s'il est autorisé
|
|
if (stagiaire_data and "tuteur2_include_com" in stagiaire_data.keys() and str( stagiaire_data['tuteur2_include_com']) == "1"):
|
|
new_node = {}
|
|
if ("tuteur2_nom" in stagiaire_data.keys()):
|
|
new_node['nom'] = stagiaire_data['tuteur2_nom']
|
|
else:
|
|
new_node['nom'] = ""
|
|
|
|
if ("tuteur2_prenom" in stagiaire_data.keys()):
|
|
new_node['prenom'] = stagiaire_data['tuteur2_prenom']
|
|
else:
|
|
new_node['prenom'] = ""
|
|
|
|
if ("tuteur2_adresse" in stagiaire_data.keys()):
|
|
new_node['adresse'] = stagiaire_data['tuteur2_adresse']
|
|
else:
|
|
new_node['adresse'] = ""
|
|
|
|
if ("tuteur2_cp" in stagiaire_data.keys()):
|
|
new_node['code_postal'] = stagiaire_data['tuteur2_cp']
|
|
else:
|
|
new_node['code_postal'] = ""
|
|
|
|
if ("tuteur2_ville" in stagiaire_data.keys()):
|
|
new_node['ville'] = stagiaire_data['tuteur2_ville']
|
|
else:
|
|
new_node['ville'] = ""
|
|
|
|
if ("tuteur2_pays" in stagiaire_data.keys()):
|
|
new_node['pays'] = stagiaire_data['tuteur2_pays']
|
|
else:
|
|
new_node['pays'] = ""
|
|
|
|
if ("tuteur2_email" in stagiaire_data.keys()):
|
|
new_node['email'] = stagiaire_data['tuteur2_email']
|
|
else:
|
|
new_node['email'] = ""
|
|
|
|
if ("tuteur2_telephone" in stagiaire_data.keys()):
|
|
new_node['telephone'] = stagiaire_data['tuteur2_telephone']
|
|
else:
|
|
new_node['telephone'] = ""
|
|
|
|
tab_stagiaire_contact_communication.append(new_node)
|
|
|
|
|
|
|
|
return True, tab_stagiaire_contact_communication
|
|
|
|
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 contacts du stagiaire "
|
|
|
|
"""
|
|
Fonction permet d'exporter des inscription dans un fichier excel
|
|
"""
|
|
def Export_Inscription_To_Excel_From_from_List_Id(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'tab_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")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'tab_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
|
|
|
|
tab_id = []
|
|
tab_id_tmp = str(diction['tab_id']).split(",")
|
|
for val in tab_id_tmp:
|
|
tab_id.append(ObjectId(str(val)))
|
|
|
|
qery_match = {'_id': {'$in': tab_id}, 'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
|
|
list_class_datas = MYSY_GV.dbname['myclass'].find({'_id': {'$in': tab_id},
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
}, {'_id': 0,
|
|
'valide': 0, 'locked': 0})
|
|
|
|
pipe_qry = ([
|
|
{'$match': qery_match},
|
|
{'$project': {'_id': 0, 'valide': 0, 'locked': 0, }},
|
|
{'$lookup': {
|
|
'from': 'partner_client',
|
|
"let": {'client_rattachement_id': "$client_rattachement_id",
|
|
'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
|
|
{'$eq': ["$_id", {'$convert': {
|
|
'input': "$$client_rattachement_id",
|
|
'to': "objectId",
|
|
'onError': {'error': 'true'},
|
|
'onNull': {'isnull': 'true'}
|
|
}}]},
|
|
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_recid", '$$partner_owner_recid']}
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{'$project': {'nom': 1, 'raison_sociale': 1, '_id': 0}},
|
|
|
|
],
|
|
'as': 'partner_client'
|
|
}
|
|
},
|
|
{'$lookup':
|
|
{
|
|
'from': 'session_formation',
|
|
'let': {'session_id': "$session_id", 'class_internal_url': '$class_internal_url',
|
|
'partner_owner_recid': '$partner_owner_recid'},
|
|
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
{'$eq': ['$_id', {'$toObjectId': '$$session_id'}]},
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
|
]
|
|
}
|
|
}
|
|
},
|
|
{'$project': { '_id': 0, 'testdate':0}},
|
|
|
|
],
|
|
'as': 'session_collection'
|
|
}
|
|
},
|
|
|
|
{'$lookup':
|
|
{
|
|
'from': 'apprenant',
|
|
"let": {'apprenant_id': "$apprenant_id", 'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr': {'$and': [
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$_id", {'$convert': {
|
|
'input': "$$apprenant_id",
|
|
'to': "objectId",
|
|
'onError': {'error': 'true'},
|
|
'onNull': {'isnull': 'true'}
|
|
}}]},
|
|
|
|
]}}},
|
|
{'$project': {'_id': 0}},
|
|
], 'as': 'apprenant_collection'}}
|
|
|
|
])
|
|
|
|
print(" #### pipe_qry_inscrit = ", pipe_qry)
|
|
list_class_datas = MYSY_GV.dbname['inscription'].aggregate(pipe_qry)
|
|
|
|
# print(" ### list_class_datas = ", str(list_class_datas))
|
|
todays_date = str(datetime.today().strftime("%d/%m/%Y"))
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
|
|
|
orig_file_name = "Export_Inscription_csv_" + str(my_partner['recid']) + "_" + str(ts) + ".xlsx"
|
|
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
|
|
|
tab_exported_fields_header = ["apprenant_id", "nom", "email", "prenom", "civilite", "date_naissance", "telephone", "employeur", "client_rattachement_id", "adresse", "code_postal", "ville", "pays", "tuteur1_nom", "tuteur1_prenom",
|
|
"tuteur1_email", "tuteur1_telephone", "tuteur2_nom", "tuteur2_prenom", "tuteur2_email", "tuteur2_telephone", "opco", "comment", "tuteur1_adresse", "tuteur1_cp", "tuteur1_ville", "tuteur1_pays",
|
|
"tuteur1_include_com", "tuteur2_adresse", "tuteur2_cp", "tuteur2_ville", "tuteur2_pays", "tuteur2_include_com",
|
|
"client_nom", "client_raison_sociale", "Session_titre", "code_session", "session_date_debut", "session_date_fin"]
|
|
|
|
|
|
tab_exported_fields = ["nom", "email", "prenom", "civilite", "date_naissance", "telephone", "employeur", "client_rattachement_id", "adresse", "code_postal", "ville", "pays", "tuteur1_nom", "tuteur1_prenom",
|
|
"tuteur1_email", "tuteur1_telephone", "tuteur2_nom", "tuteur2_prenom", "tuteur2_email", "tuteur2_telephone", "opco", "comment", "tuteur1_adresse", "tuteur1_cp", "tuteur1_ville", "tuteur1_pays",
|
|
"tuteur1_include_com", "tuteur2_adresse", "tuteur2_cp", "tuteur2_ville", "tuteur2_pays", "tuteur2_include_com"]
|
|
|
|
# Create a workbook and add a worksheet.
|
|
workbook = xlsxwriter.Workbook(outputFilename)
|
|
worksheet = workbook.add_worksheet()
|
|
|
|
row = 0
|
|
column = 0
|
|
|
|
for header_item in tab_exported_fields_header:
|
|
worksheet.write(row, column, header_item)
|
|
column += 1
|
|
|
|
for class_data in list_class_datas:
|
|
column = 0
|
|
row = row + 1
|
|
"""
|
|
for local_fiels in tab_exported_fields:
|
|
print(" #### class_data = ", class_data)
|
|
answers_record_JSON = ast.literal_eval(str(class_data))
|
|
if (str(local_fiels) in answers_record_JSON.keys()):
|
|
local_status, local_retval = mycommon.IsFloat(str(answers_record_JSON[str(local_fiels)]).strip())
|
|
if (local_status is True):
|
|
no_html = answers_record_JSON[str(local_fiels)]
|
|
else:
|
|
no_html = mycommon.cleanhtml(answers_record_JSON[str(local_fiels)])
|
|
else:
|
|
no_html = ""
|
|
|
|
worksheet.write(row, column, no_html)
|
|
column += 1
|
|
|
|
"""
|
|
if ("apprenant_id" in class_data.keys() and str(class_data['apprenant_id']).strip() != "" and
|
|
"apprenant_collection" in class_data.keys() and len(class_data['apprenant_collection']) > 0):
|
|
|
|
worksheet.write(row, column, str(class_data['apprenant_id']))
|
|
column += 1
|
|
|
|
#print(" ### str(class_data['apprenant_id']) = ", str(class_data['apprenant_id']) )
|
|
answers_record_JSON = ast.literal_eval(str(class_data['apprenant_collection'][0]))
|
|
#print(" ### answers_record_JSON = ", answers_record_JSON)
|
|
for local_fiels in tab_exported_fields:
|
|
if (str(local_fiels) in answers_record_JSON.keys()):
|
|
local_status, local_retval = mycommon.IsFloat(
|
|
str(answers_record_JSON[str(local_fiels)]).strip())
|
|
if (local_status is True):
|
|
no_html = answers_record_JSON[str(local_fiels)]
|
|
else:
|
|
no_html = mycommon.cleanhtml(answers_record_JSON[str(local_fiels)])
|
|
else:
|
|
no_html = ""
|
|
|
|
worksheet.write(row, column, no_html)
|
|
column += 1
|
|
|
|
|
|
elif ( "apprenant_id" not in class_data.keys() or str(class_data['apprenant_id']).strip() == ""):
|
|
worksheet.write(row, column, "--")
|
|
column += 1
|
|
|
|
for local_fiels in tab_exported_fields:
|
|
#print(" #### class_data = ", class_data)
|
|
answers_record_JSON = ast.literal_eval(str(class_data))
|
|
if (str(local_fiels) in answers_record_JSON.keys()):
|
|
local_status, local_retval = mycommon.IsFloat(
|
|
str(answers_record_JSON[str(local_fiels)]).strip())
|
|
if (local_status is True):
|
|
no_html = answers_record_JSON[str(local_fiels)]
|
|
else:
|
|
no_html = mycommon.cleanhtml(answers_record_JSON[str(local_fiels)])
|
|
else:
|
|
no_html = ""
|
|
|
|
worksheet.write(row, column, no_html)
|
|
column += 1
|
|
|
|
|
|
# Récuperation des données du client de rattachement
|
|
if ("partner_client" in class_data.keys() and len(class_data['partner_client']) > 0):
|
|
if ("nom" in class_data['partner_client'][0].keys()):
|
|
no_html_formateur_nom = class_data['partner_client'][0]['nom']
|
|
worksheet.write(row, column, no_html_formateur_nom)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
if ("raison_sociale" in class_data['partner_client'][0].keys()):
|
|
no_html_formateur_raison_sociale = class_data['partner_client'][0]['raison_sociale']
|
|
worksheet.write(row, column, no_html_formateur_raison_sociale)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
# Récuperation des données de la session de formation
|
|
if ("session_collection" in class_data.keys() and len(class_data['session_collection']) > 0):
|
|
if ("titre" in class_data['session_collection'][0].keys()):
|
|
no_html_session_titre = class_data['session_collection'][0]['titre']
|
|
worksheet.write(row, column, no_html_session_titre)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
if ("code_session" in class_data['session_collection'][0].keys()):
|
|
no_html_code_session = class_data['session_collection'][0]['code_session']
|
|
worksheet.write(row, column, no_html_code_session)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
|
|
|
|
if ("date_debut" in class_data['session_collection'][0].keys()):
|
|
no_html_session_debut = class_data['session_collection'][0]['date_debut']
|
|
worksheet.write(row, column, no_html_session_debut)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
if ("date_fin" in class_data['session_collection'][0].keys()):
|
|
no_html_session_date_fin = class_data['session_collection'][0]['date_fin']
|
|
worksheet.write(row, column, no_html_session_date_fin)
|
|
column += 1
|
|
else:
|
|
worksheet.write(row, column, "")
|
|
column += 1
|
|
|
|
|
|
workbook.close()
|
|
if os.path.exists(outputFilename):
|
|
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
|
return True, send_file(outputFilename, as_attachment=True)
|
|
|
|
return False, "Impossible de générer l'export csv des inscrits (2) "
|
|
|
|
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'exporter les inscrits "
|
|
|
|
|
|
|
|
"""
|
|
Dans le cadre de la modification des inscription
|
|
cette fonction permet de recuperer les données des inscrit (on ne va pas chercher les données de l'apprenant).
|
|
|
|
Ici l'inscription n'est pas validée encore
|
|
"""
|
|
|
|
|
|
def Get_Statgaire_List_Partner_with_filter_FOR_ONLY_INSCRIPTION_NO_TOKEN(diction):
|
|
try:
|
|
field_list = ['partner_owner_recid', 'class_internal_url', 'status', 'email', 'nom',
|
|
'class_title', 'code_session', 'client_nom', 'client_rattachement_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é, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables", ""
|
|
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
|
|
partner_recid = diction['partner_owner_recid']
|
|
|
|
"""
|
|
07/03/2025 :
|
|
Etape 0 : Verifier si ceci concerne une demande stockée dans la collection 'client_preinsc_update_request'.
|
|
Si oui, alors cela conerne le cas un client doit créer lui la liste des tous preinscrit en respectant le nombre
|
|
max.
|
|
"""
|
|
max_presinscrit = "0"
|
|
is_client_preinsc_update_request = ""
|
|
is_client_preinsc_update_request_data = MYSY_GV.dbname['client_preinsc_update_request'].find_one({'partner_owner_recid': str(partner_recid),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'client_id': str(diction['client_rattachement_id']),
|
|
'session_id': str(diction['session_id'])})
|
|
|
|
if( is_client_preinsc_update_request_data and "max_presinscrit" in is_client_preinsc_update_request_data.keys()):
|
|
max_presinscrit = str(is_client_preinsc_update_request_data['max_presinscrit'])
|
|
is_client_preinsc_update_request = "1"
|
|
|
|
|
|
#print(" #### is_client_preinsc_update_request_data = ", is_client_preinsc_update_request_data)
|
|
"""
|
|
Etape 1 : si on a le champ 'code session' saisie par l'utilisateur,
|
|
alors on va commencer par aller cherche toutes les session avec un regex de la valeur saisie filter sur le partner_recid
|
|
|
|
"""
|
|
filt_session_id = {}
|
|
list_session_id = []
|
|
if ("code_session" in diction.keys()):
|
|
filt_code_session = {'code_session': {'$regex': str(diction['code_session']), "$options": "i"}}
|
|
|
|
|
|
qry_list_session_id = {"$and": [{'code_session': {'$regex': str(diction['code_session']), "$options": "i"}},
|
|
{'partner_owner_recid': str(partner_recid)}]}
|
|
|
|
# print(" ### qry_list_session_id aa = ", qry_list_session_id)
|
|
list_session_id_count = MYSY_GV.dbname['session_formation'].count_documents(qry_list_session_id)
|
|
|
|
if (list_session_id_count <= 0):
|
|
# Aucune session
|
|
return True, [], ""
|
|
|
|
for val in MYSY_GV.dbname['session_formation'].find(qry_list_session_id):
|
|
list_session_id.append(str(val['_id']))
|
|
|
|
print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
|
filt_session_id = {'session_id': {'$in': list_session_id, }}
|
|
|
|
filt_class_title = {}
|
|
if ("class_title" in diction.keys()):
|
|
filt_class_title = {'title': {'$regex': str(diction['class_title']), "$options": "i"}}
|
|
|
|
filt_class_internal_url = {}
|
|
if ("class_internal_url" in diction.keys()):
|
|
filt_class_internal_url = {
|
|
'class_internal_url': {'$regex': str(diction['class_internal_url']), "$options": "i"}}
|
|
|
|
filt_email = {}
|
|
if ("email" in diction.keys()):
|
|
filt_email = {'email': {'$regex': str(diction['email']), "$options": "i"}}
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_class_partner_recid = {'partner_owner_recid': str(partner_recid)}
|
|
|
|
filt_client_rattachement_id = {}
|
|
if ("client_rattachement_id" in diction.keys()):
|
|
filt_client_rattachement_id = {'client_rattachement_id': str(diction['client_rattachement_id'])}
|
|
|
|
filt_session_id = {}
|
|
if ("session_id" in diction.keys()):
|
|
filt_session_id = {'session_id': str(diction['session_id'])}
|
|
|
|
# -----
|
|
|
|
filt_client_nom = {}
|
|
sub_filt_client_nom = {}
|
|
Lists_partner_client_id = []
|
|
if ("client_nom" in diction.keys()):
|
|
sub_filt_client_nom = {'nom': {'$regex': str(diction['client_nom']), "$options": "i"},
|
|
'partner_recid': str(partner_recid), 'valide': '1', 'locked': '0'}
|
|
# Recuperation des '_id' des clients dont le nom match en regexp
|
|
# print(" ### sub_filt_client_nom = ", sub_filt_client_nom)
|
|
for List_Client_Data in MYSY_GV.dbname['partner_client'].find(sub_filt_client_nom, {'_id': 1}):
|
|
Lists_partner_client_id.append(str(List_Client_Data['_id']))
|
|
|
|
filt_client_nom = {'client_rattachement_id': {'$in': Lists_partner_client_id, }}
|
|
# print(' ### filt_client_nom = ', filt_client_nom)
|
|
|
|
# ----
|
|
|
|
query = [{'$match': {'$and': [filt_class_internal_url, filt_session_id, filt_email, filt_nom, filt_client_nom,
|
|
filt_client_rattachement_id,
|
|
filt_session_id, {'partner_owner_recid': str(partner_recid)}]}},
|
|
{'$sort': {'_id': -1}},
|
|
{'$lookup':
|
|
{
|
|
'from': 'myclass',
|
|
'localField': 'class_internal_url',
|
|
'foreignField': 'internal_url',
|
|
'pipeline': [{'$match': {'$and': [filt_class_title, filt_class_partner_recid]}},
|
|
{'$project': {'title': 1, 'domaine': 1,
|
|
'duration': 1,
|
|
'duration_unit': 1}}],
|
|
'as': 'myclass_collection'
|
|
}
|
|
},
|
|
|
|
]
|
|
#print("#### Get_Statgaire_List_Partner_with_filter_ONLY_INSCRIPTION laa 01 : query = ", query)
|
|
RetObject = []
|
|
cpt = 0
|
|
for retVal in MYSY_GV.dbname['inscription'].aggregate(query):
|
|
val = {}
|
|
if ('myclass_collection' in retVal.keys() and len(retVal['myclass_collection']) > 0):
|
|
|
|
val['id'] = str(cpt)
|
|
cpt = cpt + 1
|
|
val['_id'] = retVal['_id']
|
|
val['session_id'] = retVal['session_id']
|
|
val['class_internal_url'] = retVal['class_internal_url']
|
|
val['nom'] = retVal['nom']
|
|
val['partner_owner_recid'] = retVal['partner_owner_recid']
|
|
val['prenom'] = retVal['prenom']
|
|
|
|
val['email'] = retVal['email']
|
|
|
|
if ("civilite" in retVal.keys()):
|
|
val['civilite'] = str(retVal['civilite']).lower()
|
|
else:
|
|
val['civilite'] = ""
|
|
|
|
if (str(val['civilite']) not in MYSY_GV.CIVILITE):
|
|
val['civilite'] = "neutre"
|
|
|
|
if ("modefinancement" in retVal.keys()):
|
|
val['modefinancement'] = retVal['modefinancement']
|
|
else:
|
|
val['modefinancement'] = ""
|
|
|
|
if ("opco" in retVal.keys()):
|
|
val['opco'] = retVal['opco']
|
|
else:
|
|
val['opco'] = ""
|
|
|
|
if ("employeur" in retVal.keys()):
|
|
val['employeur'] = retVal['employeur']
|
|
else:
|
|
val['employeur'] = ""
|
|
|
|
if ("telephone" in retVal.keys()):
|
|
val['telephone'] = retVal['telephone']
|
|
else:
|
|
val['telephone'] = ""
|
|
|
|
if ("date_naissance" in retVal.keys()):
|
|
val['date_naissance'] = retVal['date_naissance']
|
|
else:
|
|
val['date_naissance'] = ""
|
|
|
|
if ("adresse" in retVal.keys()):
|
|
val['adresse'] = retVal['adresse']
|
|
else:
|
|
val['adresse'] = ""
|
|
|
|
if ("code_postal" in retVal.keys()):
|
|
val['code_postal'] = retVal['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("ville" in retVal.keys()):
|
|
val['ville'] = retVal['ville']
|
|
else:
|
|
val['ville'] = ""
|
|
|
|
if ("pays" in retVal.keys()):
|
|
val['pays'] = retVal['pays']
|
|
else:
|
|
val['pays'] = ""
|
|
|
|
val['status'] = retVal['status']
|
|
|
|
val['title'] = retVal['myclass_collection'][0]['title']
|
|
if ("domaine" in retVal['myclass_collection'][0].keys()):
|
|
val['domaine'] = retVal['myclass_collection'][0]['domaine']
|
|
else:
|
|
val['domaine'] = ""
|
|
|
|
# Recuperation des informations de la session
|
|
local_qry = {'_id': ObjectId(retVal['session_id']), 'valide': '1'}
|
|
|
|
# print(" #### local_qry zzz = ", local_qry)
|
|
|
|
count_session = MYSY_GV.dbname['session_formation'].count_documents(local_qry)
|
|
|
|
client_rattachement_id = ""
|
|
client_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
# print(" ### retVal = ", retVal )
|
|
if ("client_rattachement_id" in retVal.keys()):
|
|
if (retVal['client_rattachement_id'] and str(retVal['client_rattachement_id']) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(retVal['client_rattachement_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (client_retval is not None):
|
|
client_rattachement_id = client_retval['_id']
|
|
client_rattachement_nom = client_retval['nom']
|
|
|
|
val['client_rattachement_id'] = client_rattachement_id
|
|
val['client_rattachement_nom'] = client_rattachement_nom
|
|
|
|
# ----
|
|
|
|
invoiced = ""
|
|
if ("invoiced" in retVal.keys()):
|
|
invoiced = retVal['invoiced']
|
|
val['invoiced'] = invoiced
|
|
|
|
invoiced_ref = ""
|
|
if ("invoiced_ref" in retVal.keys()):
|
|
invoiced_ref = retVal['invoiced_ref']
|
|
val['invoiced_ref'] = invoiced_ref
|
|
|
|
invoiced_date = ""
|
|
if ("invoiced_date" in retVal.keys()):
|
|
invoiced_date = str(retVal['invoiced_date'])[0:10]
|
|
val['invoiced_date'] = invoiced_date
|
|
|
|
financeur_rattachement_id = ""
|
|
financeur_rattachement_nom = ""
|
|
|
|
# Si il a un client rattacher, recuperation des information du client
|
|
# print(" ### retVal = ", retVal )
|
|
if ("financeur_rattachement_id" in retVal.keys()):
|
|
if (retVal['financeur_rattachement_id'] and str(
|
|
retVal['financeur_rattachement_id']) != 'undefined'):
|
|
client_retval = MYSY_GV.dbname['partner_client'].find_one(
|
|
{'_id': ObjectId(retVal['financeur_rattachement_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (client_retval is not None):
|
|
financeur_rattachement_id = client_retval['_id']
|
|
financeur_rattachement_nom = client_retval['nom']
|
|
|
|
val['financeur_rattachement_id'] = financeur_rattachement_id
|
|
val['financeur_rattachement_nom'] = financeur_rattachement_nom
|
|
|
|
if (count_session != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Impossible de récupérer la liste des stagiaires, Il y a une incohérence sur la session : " + str(
|
|
retVal['session_id']))
|
|
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes. Il y a une incohérence sur la session : " + str(
|
|
retVal['session_id'])
|
|
|
|
# qry2 = {'class_internal_url':str(retVal['class_internal_url']), 'code_session':str(retVal['session_id']), 'valide':'1'}
|
|
# print(" ### qry 2 =", qry2)
|
|
session_retval = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(retVal['session_id'])), 'valide': '1'})
|
|
|
|
if ("code_session" in session_retval.keys()):
|
|
val['code_session'] = str(session_retval['code_session'])
|
|
else:
|
|
val['code_session'] = ""
|
|
|
|
if ("titre" in session_retval.keys()):
|
|
val['session_titre'] = str(session_retval['titre'])
|
|
else:
|
|
val['session_titre'] = ""
|
|
|
|
|
|
if ("date_debut" in session_retval.keys()):
|
|
val['date_du'] = str(session_retval['date_debut'])[0:10]
|
|
else:
|
|
val['date_du'] = ""
|
|
|
|
if ("date_fin" in session_retval.keys()):
|
|
val['date_au'] = str(session_retval['date_fin'])[0:10]
|
|
else:
|
|
val['date_au'] = ""
|
|
|
|
if ("code_postal" in session_retval.keys()):
|
|
val['code_postal'] = session_retval['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("prix_session" in session_retval.keys()):
|
|
val['price'] = session_retval['prix_session']
|
|
else:
|
|
val['price'] = ""
|
|
|
|
if ("presentiel" in session_retval.keys()):
|
|
val['presentiel'] = session_retval['presentiel']
|
|
else:
|
|
val['presentiel'] = "0"
|
|
|
|
if ("distantiel" in session_retval.keys()):
|
|
val['distantiel'] = session_retval['distantiel']
|
|
else:
|
|
val['distantiel'] = "0"
|
|
|
|
if ("session_ondemande" in session_retval.keys()):
|
|
val['session_ondemande'] = session_retval['session_ondemande']
|
|
else:
|
|
val['session_ondemande'] = "0"
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(val))
|
|
|
|
|
|
"""
|
|
S'il n'y aucune personne déjà inscrite et que 'is_client_preinsc_update_request' == 1 , j'initialise le table
|
|
'RetObject' avec une seule ligne vide
|
|
|
|
"""
|
|
if( cpt == 0 and is_client_preinsc_update_request == "1"):
|
|
|
|
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(partner_recid)})
|
|
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(session_data['class_internal_url'])})
|
|
|
|
val = {}
|
|
val['id'] = str(cpt)
|
|
cpt = cpt + 1
|
|
val['_id'] = "new"
|
|
val['session_id'] = diction['session_id']
|
|
val['class_internal_url'] = session_data['class_internal_url']
|
|
val['nom'] = "new_nom"
|
|
val['partner_owner_recid'] = session_data['partner_owner_recid']
|
|
val['prenom'] = "new_prenom"
|
|
val['email'] = "new_email@email.com"
|
|
val['civilite'] = "neutre"
|
|
val['modefinancement'] = ""
|
|
val['opco'] = ""
|
|
|
|
val['employeur'] = ""
|
|
val['telephone'] = ""
|
|
val['date_naissance'] = ""
|
|
|
|
val['adresse'] = ""
|
|
val['code_postal'] = ""
|
|
val['ville'] = ""
|
|
val['pays'] = ""
|
|
val['status'] = "0"
|
|
|
|
val['title'] = class_data['title']
|
|
if ("domaine" in class_data.keys()):
|
|
val['domaine'] = class_data['domaine']
|
|
else:
|
|
val['domaine'] = ""
|
|
|
|
|
|
if ("code_session" in session_data.keys()):
|
|
val['code_session'] = str(session_data['code_session'])
|
|
else:
|
|
val['code_session'] = ""
|
|
|
|
if ("titre" in session_data.keys()):
|
|
val['session_titre'] = str(session_data['titre'])
|
|
else:
|
|
val['session_titre'] = ""
|
|
|
|
if ("date_debut" in session_data.keys()):
|
|
val['date_du'] = str(session_data['date_debut'])[0:10]
|
|
else:
|
|
val['date_du'] = ""
|
|
|
|
if ("date_fin" in session_data.keys()):
|
|
val['date_au'] = str(session_data['date_fin'])[0:10]
|
|
else:
|
|
val['date_au'] = ""
|
|
|
|
if ("code_postal" in session_data.keys()):
|
|
val['code_postal'] = session_data['code_postal']
|
|
else:
|
|
val['code_postal'] = ""
|
|
|
|
if ("prix_session" in session_data.keys()):
|
|
val['price'] = session_data['prix_session']
|
|
else:
|
|
val['price'] = ""
|
|
|
|
if ("presentiel" in session_data.keys()):
|
|
val['presentiel'] = session_data['presentiel']
|
|
else:
|
|
val['presentiel'] = "0"
|
|
|
|
if ("distantiel" in session_data.keys()):
|
|
val['distantiel'] = session_data['distantiel']
|
|
else:
|
|
val['distantiel'] = "0"
|
|
|
|
if ("session_ondemande" in session_data.keys()):
|
|
val['session_ondemande'] = session_data['session_ondemande']
|
|
else:
|
|
val['session_ondemande'] = "0"
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(val))
|
|
|
|
|
|
|
|
|
|
RetObject_global_data = []
|
|
# Gestion du cas le client peut ajouter lui meme des preinscrits
|
|
val_global_data = {}
|
|
val_global_data['max_presinscrit'] = str(max_presinscrit)
|
|
val_global_data['is_client_preinsc_update_request'] = str(is_client_preinsc_update_request)
|
|
RetObject_global_data.append(mycommon.JSONEncoder().encode(val_global_data))
|
|
|
|
return True, RetObject, RetObject_global_data
|
|
|
|
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 récupérer la liste des stagiaires", ""
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction prend l'_id d'une session et retourne les inscriptions qui sont valide
|
|
avec un nombre de champs limité
|
|
"""
|
|
def Get_Accepted_Insription_From_Session_id_Reduice_Fields(diction):
|
|
try:
|
|
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é, Creation partenaire annulée")
|
|
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Impossible de récupérer la liste des stagiaires, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
|
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes "
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
|
|
|
|
## Recuperation de toutes les stagiaire rattaché à cette session
|
|
coll_session = MYSY_GV.dbname['inscription']
|
|
myquery = {}
|
|
myquery['session_id'] = session_id
|
|
myquery['status'] = "1"
|
|
myquery['valide'] = "1"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
#print(" #### myquery 01111 = "+str(myquery))
|
|
|
|
|
|
for retval in coll_session.find(myquery,
|
|
{'_id':1, 'email':1,
|
|
'session_id':1,
|
|
'apprenant_id':1,
|
|
'nom': 1,
|
|
'prenom': 1,
|
|
|
|
}).sort([("_id", pymongo.DESCENDING), ]):
|
|
val_tmp = val_tmp + 1
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
apprenant_nom = str(retval['nom'])
|
|
apprenant_prenom = str(retval['prenom'])
|
|
apprenant_email = str(retval['email'])
|
|
|
|
# Si il a un apprenant_id
|
|
# print(" ### retVal = ", retVal )
|
|
if ("apprenant_id" in retval.keys()):
|
|
if (retval['apprenant_id'] and str(retval['apprenant_id']) != 'undefined'):
|
|
apprenant_retval = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'_id': ObjectId(retval['apprenant_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (apprenant_retval is not None):
|
|
apprenant_nom = apprenant_retval['nom']
|
|
apprenant_prenom = apprenant_retval['prenom']
|
|
apprenant_email = apprenant_retval['email']
|
|
|
|
user['apprenant_nom'] = apprenant_nom
|
|
user['apprenant_prenom'] = apprenant_prenom
|
|
user['apprenant_email'] = apprenant_email
|
|
|
|
user['groupe'] = ""
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des stagiaires de la formation"
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction prend l'_id d'une session et retourne les inscriptions qui sont validé et celle en cours de validation
|
|
(statut IN [0, 1, 2]
|
|
avec un nombre de champs limité
|
|
"""
|
|
def Get_Insription_From_Session_id_Reduice_Fields_With_Filter(diction):
|
|
try:
|
|
field_list = ['token', 'session_id', 'tab_statut_ids']
|
|
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é, Creation partenaire annulée")
|
|
return False, "de récupérer la liste des stagiaires . Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste 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, "Impossible de récupérer la liste des stagiaires, Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", mytoken)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer la liste des stagiaires, ")
|
|
return False, "Impossible de récupérer la liste des stagiaires, Les informations d'identification sont incorrectes "
|
|
|
|
class_internal_url = ""
|
|
if ("class_internal_url" in diction.keys()):
|
|
if diction['class_internal_url']:
|
|
class_internal_url = diction['class_internal_url']
|
|
|
|
session_id = ""
|
|
if ("session_id" in diction.keys()):
|
|
if diction['session_id']:
|
|
session_id = diction['session_id']
|
|
|
|
tab_statut_ids = ""
|
|
tab_statut_ids_filter = {}
|
|
if ("tab_statut_ids" in diction.keys()):
|
|
if diction['tab_statut_ids']:
|
|
tab_statut_ids = diction['tab_statut_ids']
|
|
|
|
tab_statut_ids_splited = str(tab_statut_ids).split(",")
|
|
|
|
|
|
## Recuperation de toutes les stagiaire rattaché à cette session
|
|
|
|
myquery = {}
|
|
myquery['session_id'] = session_id
|
|
myquery['status'] = "1"
|
|
myquery['valide'] = "1"
|
|
if (len(tab_statut_ids_splited) > 0):
|
|
myquery['status'] = {'$in': tab_statut_ids_splited}
|
|
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
#print(" #### myquery 01111 = "+str(myquery))
|
|
|
|
|
|
for retval in MYSY_GV.dbname['inscription'].find(myquery,
|
|
{'_id':1, 'email':1,
|
|
'session_id':1,
|
|
'apprenant_id':1,
|
|
'nom':1,
|
|
'prenom':1,
|
|
|
|
}).sort([("_id", pymongo.DESCENDING), ]):
|
|
val_tmp = val_tmp + 1
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
apprenant_nom = str(retval['nom'])
|
|
apprenant_prenom = str(retval['prenom'])
|
|
apprenant_email = str(retval['email'])
|
|
|
|
# Si il a un apprenant_id
|
|
# print(" ### retVal = ", retVal )
|
|
if ("apprenant_id" in retval.keys()):
|
|
if (retval['apprenant_id'] and str(retval['apprenant_id']) != 'undefined'):
|
|
apprenant_retval = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'_id': ObjectId(retval['apprenant_id']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (apprenant_retval is not None):
|
|
apprenant_nom = apprenant_retval['nom']
|
|
apprenant_prenom = apprenant_retval['prenom']
|
|
apprenant_email = apprenant_retval['email']
|
|
|
|
user['apprenant_nom'] = apprenant_nom
|
|
user['apprenant_prenom'] = apprenant_prenom
|
|
user['apprenant_email'] = apprenant_email
|
|
|
|
user['groupe'] = ""
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des stagiaires de la formation"
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction retourne la liste des UE aux quelles un apprenant est inscrit
|
|
"""
|
|
def Get_Inscrit_List_EU(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'inscription_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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
formation_initiale = "0"
|
|
if ("formation_initiale" in my_partner.keys()):
|
|
formation_initiale = my_partner['formation_initiale']
|
|
|
|
if (formation_initiale != "1"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il ne s'agit pas d'un formation initiale ")
|
|
return True, " Il ne s'agit pas d'un formation initiale "
|
|
|
|
"""
|
|
Verifier que l'inscription est valide
|
|
"""
|
|
is_valide_inscription_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(diction['inscription_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_inscription_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
|
return False, " L'identifiant de l'inscrit est invalide "
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
|
|
qery_match = {'inscription_id': str(diction['inscription_id']), 'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
pipe_qry = ([
|
|
{'$match': qery_match},
|
|
{'$lookup': {
|
|
'from': 'unite_enseignement',
|
|
"let": {'class_eu_id': "$class_eu_id",
|
|
'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
|
|
{'$eq': ["$_id", {'$convert': {
|
|
'input': "$$class_eu_id",
|
|
'to': "objectId",
|
|
'onError': {'error': 'true'},
|
|
'onNull': {'isnull': 'true'}
|
|
}}]},
|
|
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
],
|
|
'as': 'collection_unite_enseignement'
|
|
}
|
|
},
|
|
{
|
|
'$unwind': '$collection_unite_enseignement'
|
|
}
|
|
|
|
])
|
|
|
|
for val in MYSY_GV.dbname['inscription_liste_ue'].aggregate(pipe_qry):
|
|
user = {}
|
|
main_field = ['_id', 'class_eu_id', 'class_id', 'inscription_id', ]
|
|
second_field = ['_id', 'code', 'titre']
|
|
|
|
for tmp in main_field :
|
|
if( str(tmp) in val.keys() ):
|
|
user[str(tmp)] = val[str(tmp)]
|
|
|
|
for tmp in second_field:
|
|
if (str(tmp) in val['collection_unite_enseignement'].keys()):
|
|
user["ue_"+str(tmp)] = val['collection_unite_enseignement'][str(tmp)]
|
|
|
|
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 les UE associées à l'inscription"
|
|
|
|
|
|
"""
|
|
Cette fonction permet de recuperer la liste des types d'evaluation pour un inscrit
|
|
exemple : Pour l'UE xxxx, il est inscrit pour les 'PROJETS' seulement
|
|
"""
|
|
def Get_Inscrit_List_EU_Type_Evaluation(diction):
|
|
try:
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'inscription_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 ne sont pas correctes"
|
|
|
|
mytoken = ""
|
|
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
|
|
|
|
formation_initiale = "0"
|
|
if ("formation_initiale" in my_partner.keys()):
|
|
formation_initiale = my_partner['formation_initiale']
|
|
|
|
if (formation_initiale != "1"):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il ne s'agit pas d'un formation initiale ")
|
|
return True, " Il ne s'agit pas d'un formation initiale "
|
|
|
|
"""
|
|
Verifier que l'inscription est valide
|
|
"""
|
|
is_valide_inscription_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(diction['inscription_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_valide_inscription_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
|
return False, " L'identifiant de l'inscrit est invalide "
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
|
|
qery_match = {'inscription_id': str(diction['inscription_id']), 'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
|
|
'locked': '0'}
|
|
|
|
pipe_qry = ([
|
|
{'$match': qery_match},
|
|
{'$lookup': {
|
|
'from': 'type_evaluation',
|
|
"let": {'type_evaluation_id': '$type_evaluation_id',
|
|
'partner_owner_recid': '$partner_owner_recid'},
|
|
'pipeline': [
|
|
{'$match':
|
|
{'$expr':
|
|
{'$and':
|
|
[
|
|
|
|
{'$eq': ["$_id", {'$convert': {
|
|
'input': "$$type_evaluation_id",
|
|
'to': "objectId",
|
|
'onError': {'error': 'true'},
|
|
'onNull': {'isnull': 'true'}
|
|
}}]},
|
|
|
|
{'$eq': ["$valide", "1"]},
|
|
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
|
|
|
]
|
|
}
|
|
}
|
|
},
|
|
],
|
|
'as': 'collection_type_evaluation'
|
|
}
|
|
},
|
|
{
|
|
'$unwind': '$collection_type_evaluation'
|
|
}
|
|
|
|
])
|
|
|
|
#print(" ### Get_Inscrit_List_EU_Type_Evaluation pipe_qry = ", pipe_qry)
|
|
|
|
for val in MYSY_GV.dbname['inscription_liste_ue_type_evalution'].aggregate(pipe_qry):
|
|
user = {}
|
|
main_field = ['_id', 'class_eu_id', 'class_id', 'inscription_id', 'type_evaluation_id']
|
|
second_field = ['_id', 'code', 'nom']
|
|
|
|
for tmp in main_field :
|
|
if( str(tmp) in val.keys() ):
|
|
user[str(tmp)] = val[str(tmp)]
|
|
|
|
class_eu_code = ""
|
|
if( "class_eu_id" in val.keys() ):
|
|
class_eu_id_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id':ObjectId(str(val['class_eu_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( class_eu_id_data and 'code' in class_eu_id_data.keys() ):
|
|
class_eu_code = class_eu_id_data['code']
|
|
|
|
user['class_eu_code'] = class_eu_code
|
|
|
|
for tmp in second_field:
|
|
if (str(tmp) in val['collection_type_evaluation'].keys()):
|
|
user["type_eval_"+str(tmp)] = val['collection_type_evaluation'][str(tmp)]
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
|
|
#print(" ### Get_Inscrit_List_EU_Type_Evaluation RetObject = ", RetObject)
|
|
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 évaluation par UE "
|
|
|
|
|
|
"""
|
|
Cette fonction retourne la liste des inscrits à
|
|
une UE et un type d'evaluation donnée.
|
|
|
|
sont données en option :
|
|
- Liste UE,
|
|
- Liste Type evaluation
|
|
|
|
use case :
|
|
Avec cette fonction on peut recuperer la liste des personnes inscrite à
|
|
- ue : ue1, ue2, etc
|
|
- type eval : TP, Projet, etc
|
|
|
|
"""
|
|
|
|
def Get_List_Inscrit_OF_UE_And_Type_Evaluation_with_filter(diction):
|
|
try:
|
|
field_list = ['token', 'class_id', 'tab_session_id', 'tab_ue_id', 'tab_type_eval_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é, Creation partenaire annulée")
|
|
return False, "Toutes les informations fournies ne sont pas valables"
|
|
|
|
"""
|
|
Verification de la liste des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'class_id', 'tab_session_id', 'tab_ue_id', 'tab_type_eval_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, "Toutes les informations necessaires n'ont pas été fournies"
|
|
|
|
# Recuperation du recid du partner
|
|
mydata = {}
|
|
mytoken = ""
|
|
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
|
|
|
|
# Verification de la validité de toutes les session dans tab_session_id
|
|
tab_session_id = str(diction['tab_session_id']).split(',')
|
|
for session_id in tab_session_id:
|
|
if (MYSY_GV.dbname['session_formation'].count_documents({'_id': ObjectId(str(session_id)),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])}) != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La session_id :" + str(session_id) + " n'est pas valide ")
|
|
return False, " La session_id :" + str(session_id) + " n'est pas valide "
|
|
|
|
# Verification de la validité de la formation
|
|
if (MYSY_GV.dbname['myclass'].count_documents({'_id': ObjectId(str(diction['class_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])}) != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La formation :" + str(diction['class_id']) + " n'est pas valide ")
|
|
return False, " La formation :" + str(diction['class_id']) + " n'est pas valide "
|
|
|
|
|
|
# Verification de la validité de toutes les ue_id dans tab_ue_id
|
|
tab_ue_id = str(diction['tab_ue_id']).split(',')
|
|
for ue_id in tab_ue_id:
|
|
if (MYSY_GV.dbname['unite_enseignement'].count_documents({'_id': ObjectId(str(ue_id)),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])}) != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'UE :" + str(session_id) + " n'est pas valide ")
|
|
return False, " L'UE :" + str(session_id) + " n'est pas valide "
|
|
|
|
# Verification de la validité de toutes les type_eval_id dans tab_type_eval_id
|
|
tab_type_eval_id = str(diction['tab_type_eval_id']).split(',')
|
|
for type_eval_id in tab_type_eval_id:
|
|
if (MYSY_GV.dbname['unite_enseignement'].count_documents({'_id': ObjectId(str(type_eval_id)),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])}) != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type d'évaluation :" + str(type_eval_id) + " n'est pas valide ")
|
|
return False, " Le type d'évaluation :" + str(type_eval_id) + " n'est pas valide "
|
|
|
|
|
|
|
|
RetObject = []
|
|
cpt = 0
|
|
|
|
qry = {'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'class_id': {'$in': str(diction['class_id']) },
|
|
'class_eu_id': {'$in': tab_ue_id},
|
|
'type_evaluation_id': {'$in': tab_type_eval_id},
|
|
}
|
|
|
|
|
|
|
|
for retval in MYSY_GV.dbname['inscription_liste_ue_type_evalution'].find( qry ).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = {}
|
|
# Recuperation des données de l'inscrit et de l'apprenant
|
|
if( "inscription_id" in retval.keys() ):
|
|
inscrit_data = MYSY_GV.dbname['inscription'].find_one({'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'_id':ObjectId(str(retval['inscription_id']))})
|
|
|
|
|
|
local_new_dict = {}
|
|
local_new_dict['token'] = diction['token']
|
|
local_new_dict['inscrit_id'] = retval['inscription_id']
|
|
|
|
local_inscrit_data_status, local_inscrit_data_retval = mycommon.Get_Inscrit_And_Apprenant_Data(local_new_dict)
|
|
if( local_inscrit_data_status is False ):
|
|
return local_inscrit_data_status, local_inscrit_data_retval
|
|
|
|
if( "inscrit_data" in local_inscrit_data_retval.keys() ):
|
|
user['inscrit_data'] = local_inscrit_data_retval['inscrit_data']
|
|
|
|
if ("apprenant_data" in local_inscrit_data_retval.keys()):
|
|
user['apprenant_data'] = local_inscrit_data_retval['apprenant_data']
|
|
|
|
if ("class_eu_id" in retval.keys()):
|
|
class_eu_data = MYSY_GV.dbname['unite_enseignement'].find_one({'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'_id': ObjectId(str(retval['class_eu_id']))})
|
|
|
|
if( class_eu_data and 'id' in class_eu_data.keys() ):
|
|
user['class_eu_data'] = class_eu_data
|
|
else:
|
|
user['class_eu_data'] = {}
|
|
|
|
if ("type_evaluation_id" in retval.keys()):
|
|
type_evaluation_data = MYSY_GV.dbname['type_evaluation'].find_one({'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'_id': ObjectId(str(retval['type_evaluation_id']))})
|
|
|
|
if( type_evaluation_data and 'id' in type_evaluation_data.keys() ):
|
|
user['type_evaluation_data'] = type_evaluation_data
|
|
else:
|
|
user['type_evaluation_data'] = {}
|
|
|
|
|
|
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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de récupérer la liste des inscrits"
|
|
|
|
|
|
|
|
"""
|
|
22/06/2024 - nouvelle methode pour envoyer les demandes
|
|
d'emargement de manière securisée, à l'image de la gestion des QR code
|
|
"""
|
|
"""
|
|
Cette fonction prends une liste d'inscription et une session
|
|
pui créer un QR pour l'emargement
|
|
"""
|
|
|
|
def Create_Emargement_Send_Email_From_Inscription(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'tab_emargement_ids']
|
|
|
|
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', 'tab_emargement_ids']
|
|
|
|
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 que la session est valide
|
|
is_session_id_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_session_id_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide "
|
|
|
|
"""
|
|
Recuperation du modèle de courrier pour la demande d'emargement
|
|
"""
|
|
local_diction = {}
|
|
local_diction['ref_interne'] = "EMARGEMENT_REQUEST_EMAIL"
|
|
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
|
|
|
|
|
|
# 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_own_smtp_value
|
|
|
|
|
|
# Verifier que les inscriptions sont valides
|
|
my_emargement_ids = ""
|
|
if ("tab_emargement_ids" in diction.keys()):
|
|
if diction['tab_emargement_ids']:
|
|
my_emargement_ids = diction['tab_emargement_ids']
|
|
|
|
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
if(len(tab_my_emargement_ids) <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Aucune Séquence ")
|
|
return False, " Aucun Séquence "
|
|
|
|
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['emargement'].count_documents({'session_id': str(diction['session_id']),
|
|
'_id': ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
})
|
|
|
|
|
|
|
|
if (tmp_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide ")
|
|
return False, " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide "
|
|
|
|
# Creation d'une clé securisé
|
|
my_safe_token = mycommon.create_user_recid()
|
|
|
|
"""
|
|
Mettre à jour l'inscription avec la clé
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
ret_val2 = MYSY_GV.dbname['emargement'].find_one_and_update(
|
|
{'session_id': str(diction['session_id']),
|
|
'_id': ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'
|
|
},
|
|
{"$set": {'emargement_qr_safe_token':str(my_safe_token), 'statut':'1',
|
|
'date_envoi':str(now), 'update_by':str(my_partner['_id'])}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
url_for_qr_code = str(MYSY_GV.CLIENT_URL_BASE)+"qr_emargement/"+str(diction['session_id'])+"/"+str(my_partner['recid'])+"/"+str(my_safe_token)+"/"
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
|
qr_code_img_file = str(MYSY_GV.TEMPORARY_DIRECTORY_V2) + "qr_code_" + str(ts) + ".png"
|
|
|
|
qrcode = segno.make_qr(str(url_for_qr_code))
|
|
qrcode.save(
|
|
qr_code_img_file,
|
|
scale=5,
|
|
dark="darkblue",
|
|
)
|
|
|
|
"""
|
|
25/01/2024 : Apres l'envoi de la demande
|
|
d'emargement, on log une action dans la collection ==> courrier_template_tracking_history
|
|
"""
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
|
|
val_emarge = MYSY_GV.dbname['emargement'].find_one({'_id':ObjectId(str(my_emargement_id)), 'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':my_partner['recid']})
|
|
|
|
|
|
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
|
my_partner, "EMARGEMENT_FORMATION", str(val_emarge['session_id']), "inscription", str(val_emarge['inscription_id']),
|
|
"")
|
|
|
|
"""
|
|
Debut de la procedure d'envoie de l'email
|
|
"""
|
|
convention_dictionnary_data = {}
|
|
new_diction = {}
|
|
new_diction['token'] = diction['token']
|
|
new_diction['list_stagiaire_id'] = []
|
|
new_diction['list_session_id'] = [ObjectId(str(diction['session_id']))]
|
|
new_diction['list_class_id'] = []
|
|
new_diction['list_client_id'] = []
|
|
|
|
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
|
|
|
if (local_status is False):
|
|
return local_status, local_retval
|
|
|
|
emargement_dictionnary_data = local_retval
|
|
emargement_dictionnary_data['mysyurl'] = url_for_qr_code
|
|
|
|
smtpserver = None
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
|
else:
|
|
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
|
|
|
smtpserver.ehlo()
|
|
smtpserver.starttls()
|
|
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
|
|
|
"""
|
|
on envoi qu'un seul mail d'emargement par personnes.
|
|
1 - On va aller recuperer la liste des personnes concernée (inscription_id)
|
|
2 - Apres avoir envoyer les email, on va venir mettre à jour la table emargement id)
|
|
"""
|
|
|
|
cpt_email_envoye = 0
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
|
|
"""
|
|
Des qu'on envoie un emailn on met l'inscription_id dans la collection 'tab_inscription_id_emargement_send'
|
|
Avant d'envoyer un email à un inscrit on verifie qu'il n'est pa dans la table : tab_inscription_id_emargement_send
|
|
|
|
"""
|
|
tab_inscription_id_emargement_send = []
|
|
|
|
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
my_emargement_data = MYSY_GV.dbname['emargement'].find_one({'_id':ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
|
|
if( str(my_emargement_data['inscription_id']) not in tab_inscription_id_emargement_send ):
|
|
|
|
tab_inscription_id_emargement_send.append(str(my_emargement_data['inscription_id']))
|
|
cpt_email_envoye = cpt_email_envoye + 1
|
|
|
|
# Recuperation des données de l'inscrit
|
|
local_inscrit_data = mycommon.Get_Inscrit_And_Apprenant_Data({'token':str(diction['token']), 'inscrit_id':str(my_emargement_data['inscription_id'])})
|
|
emargement_dictionnary_data['emargement_inscrit_data'] = local_inscrit_data
|
|
|
|
# Recuperation des données de la formation
|
|
myclass_data = MYSY_GV.dbname['myclass'].find_one( {'internal_url':str(my_emargement_data['class_internal_url']), 'partner_owner_recid':my_partner['recid']}, {'title':1})
|
|
emargement_dictionnary_data['emargement_class_data'] = myclass_data
|
|
|
|
emargement_dictionnary_data['emargement_data'] = my_emargement_data
|
|
|
|
body = {
|
|
"params": emargement_dictionnary_data,
|
|
}
|
|
|
|
#print( " ### emargement_dictionnary_data ===== ", emargement_dictionnary_data)
|
|
|
|
# Traitement du sujet du mail
|
|
sujet_mail_Template = jinja2.Template(str(courrier_data_retval['sujet']))
|
|
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
|
|
|
# Traitement du corps du mail
|
|
contenu_doc_Template = jinja2.Template(str(courrier_data_retval['contenu_doc']))
|
|
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
|
html_mime = MIMEText(sourceHtml, 'html')
|
|
|
|
# Creation de l'email à enoyer
|
|
msg = MIMEMultipart("alternative")
|
|
|
|
|
|
if (str(partner_own_smtp_value) == "1"):
|
|
msg.attach(html_mime)
|
|
msg['From'] = partner_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = sujetHtml
|
|
msg['to'] = str(str(my_emargement_data['email']))
|
|
val = smtpserver.send_message(msg)
|
|
print(" Email demande emargement envoyé " + str(val))
|
|
|
|
else:
|
|
msg.attach(html_mime)
|
|
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
|
msg['Bcc'] = 'contact@mysy-training.com'
|
|
msg['Subject'] = sujetHtml
|
|
msg['to'] = str(str(my_emargement_data['email']))
|
|
val = smtpserver.send_message(msg)
|
|
print(" Email demande emargement envoyé " + str(val))
|
|
|
|
smtpserver.close()
|
|
|
|
print(" NB_email envoyé = ", cpt_email_envoye)
|
|
return True, "Les demandes d'émargement ont été correctement envoyées "
|
|
|
|
|
|
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'envoyer les demandes d'émargement "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction prends une liste d'inscription et une session
|
|
pui créer un QR pour l'emargement
|
|
"""
|
|
def Create_Emargement_QR_Code_From_Inscription(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'tab_emargement_ids']
|
|
|
|
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', 'tab_emargement_ids']
|
|
|
|
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 que la session est valide
|
|
is_session_id_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_session_id_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide "
|
|
|
|
|
|
# Verifier que les inscriptions sont valides
|
|
my_emargement_ids = ""
|
|
if ("tab_emargement_ids" in diction.keys()):
|
|
if diction['tab_emargement_ids']:
|
|
my_emargement_ids = diction['tab_emargement_ids']
|
|
|
|
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
if(len(tab_my_emargement_ids) <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Aucune Séquence ")
|
|
return False, " Aucun Séquence "
|
|
|
|
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
# Verifier qui la formation n'a pas deja été evaluée
|
|
tmp_count = MYSY_GV.dbname['emargement'].count_documents({'session_id': str(diction['session_id']),
|
|
'_id': ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0' })
|
|
|
|
if (tmp_count != 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide ")
|
|
return False, " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide "
|
|
|
|
# Creation d'une clé securisé
|
|
my_safe_token = mycommon.create_user_recid()
|
|
|
|
"""
|
|
Mettre à jour l'inscription avec la , et on met le statut à "1" pour dire qu'on a demarré le process
|
|
"""
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
|
|
ret_val2 = MYSY_GV.dbname['emargement'].find_one_and_update(
|
|
{'session_id': str(diction['session_id']),
|
|
'_id': ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide':'1','locked':'0'},
|
|
{"$set": {'emargement_qr_safe_token':str(my_safe_token), 'statut':'1',
|
|
'date_envoi':str(now), 'update_by':str(my_partner['_id'])}},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
url_for_qr_code = str(MYSY_GV.CLIENT_URL_BASE)+"qr_emargement/"+str(diction['session_id'])+"/"+str(my_partner['recid'])+"/"+str(my_safe_token)+"/"
|
|
ts = datetime.now().timestamp()
|
|
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
|
qr_code_img_file = str(MYSY_GV.TEMPORARY_DIRECTORY_V2) + "qr_code_" + str(ts) + ".png"
|
|
|
|
qrcode = segno.make_qr(str(url_for_qr_code))
|
|
qrcode.save(
|
|
qr_code_img_file,
|
|
scale=5,
|
|
dark="darkblue",
|
|
)
|
|
|
|
print(" ### Create_Emargement_QR_Code_From_Inscription url_for_qr_code = ", url_for_qr_code)
|
|
|
|
"""
|
|
25/01/2024 : Apres l'envoi de la demande
|
|
d'emargement, on log une action dans la collection ==> courrier_template_tracking_history
|
|
"""
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
val_emarge = MYSY_GV.dbname['emargement'].find_one({'_id':ObjectId(str(my_emargement_id)), 'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':my_partner['recid']})
|
|
|
|
local_status, local_retval = module_editique.Editic_Log_History_Action_From_courrier_template_type_document_ref_interne(
|
|
my_partner, "EMARGEMENT_FORMATION", str(val_emarge['session_id']), "inscription", str(val_emarge['inscription_id']),
|
|
"")
|
|
|
|
if os.path.exists(qr_code_img_file):
|
|
return True, send_file(qr_code_img_file, as_attachment=True)
|
|
|
|
return False, " Impossible de générer les QR Code (1) "
|
|
|
|
|
|
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 le QR code "
|
|
|
|
"""
|
|
Verifier qu'un QR code est valide avec le mail de la personne.
|
|
C'est le controle qui est fait avant acces à l'emargemnt
|
|
"""
|
|
|
|
def Check_Emargement_QR_Code_From_Inscription_No_Token(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['partner_owner_recid', 'my_safe_token', 'session_id', 'user_email']
|
|
|
|
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 = ['partner_owner_recid', 'my_safe_token', 'session_id', 'user_email']
|
|
|
|
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
|
|
"""
|
|
|
|
local_status, my_partner = mycommon.Get_Connected_User_Partner_Data_From_RecID(
|
|
str(diction['partner_owner_recid']))
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que les info sont valide
|
|
is_emargement_valide_count = MYSY_GV.dbname['emargement'].count_documents({'session_id': str(diction['session_id']),
|
|
'emargement_qr_safe_token': str(diction['my_safe_token']),
|
|
'email': str( diction['user_email']),
|
|
'partner_owner_recid': str(diction['partner_owner_recid']),
|
|
'statut': '1'})
|
|
|
|
if( is_emargement_valide_count <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Les identifiants sont invalides ")
|
|
return False, " Les identifiants sont invalides "
|
|
|
|
RetObject = []
|
|
nb_val = 0
|
|
|
|
for retval in MYSY_GV.dbname['emargement'].find(
|
|
{'session_id': str(diction['session_id']),
|
|
'emargement_qr_safe_token': str(diction['my_safe_token']),
|
|
'email': str(diction['user_email']),
|
|
'partner_owner_recid': str(diction['partner_owner_recid']),
|
|
'statut': '1'}):
|
|
|
|
|
|
user = {}
|
|
user = retval
|
|
user['id'] = str(nb_val)
|
|
code_session = ""
|
|
class_interna_url = ""
|
|
class_title = ""
|
|
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id':ObjectId(str(retval['session_id'])),
|
|
'partner_owner_recid':str(diction['partner_owner_recid']),
|
|
'valide':'1'})
|
|
|
|
if( session_data and 'code_session' in session_data.keys() ):
|
|
code_session = session_data['code_session']
|
|
|
|
if (session_data and 'class_internal_url' in session_data.keys()):
|
|
class_interna_url = session_data['class_internal_url']
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(class_interna_url),
|
|
'partner_owner_recid':str(diction['partner_owner_recid']),
|
|
'valide':'1'}, {'title':1})
|
|
|
|
if( class_data and "title" in class_data.keys() ):
|
|
class_title = class_data['title']
|
|
|
|
user['class_title'] = str(class_title)
|
|
user['code_session'] = str(code_session)
|
|
|
|
nb_val = nb_val + 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 vérifier la validité des informations "
|
|
|
|
|
|
"""
|
|
Emargement avec le QR CODE pour dire qu'on est présent ou absent
|
|
"""
|
|
def Update_Emargement_QR_Code_From_Inscription_No_Token(file_img=None, Folder=None, diction=None):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['partner_owner_recid', 'my_safe_token', 'tab_emargement_ids', 'is_present', 'signature_img_selected']
|
|
|
|
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 = ['partner_owner_recid', 'my_safe_token', 'tab_emargement_ids', 'is_present', 'signature_img_selected']
|
|
|
|
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
|
|
"""
|
|
|
|
|
|
|
|
local_status, my_partner = mycommon.Get_Connected_User_Partner_Data_From_RecID(
|
|
str(diction['partner_owner_recid']))
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que l'identifiant de l'emargement est valide
|
|
my_emargement_ids = ""
|
|
if ("tab_emargement_ids" in diction.keys()):
|
|
if diction['tab_emargement_ids']:
|
|
my_emargement_ids = diction['tab_emargement_ids']
|
|
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
is_emargement_valide_count = MYSY_GV.dbname['emargement'].count_documents({'emargement_qr_safe_token': str(diction['my_safe_token']),
|
|
'_id': ObjectId(str( my_emargement_id) ),
|
|
'partner_owner_recid': str(diction['partner_owner_recid']),
|
|
'statut': '1'})
|
|
|
|
if( is_emargement_valide_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide ")
|
|
return False, " L'identifiant de l'émargement "+str(my_emargement_id)+" est invalide "
|
|
|
|
image_signature_manuelle_string = ""
|
|
if (file_img):
|
|
status, saved_file = mycommon.Upload_Save_IMG_File(file_img, Folder)
|
|
if (status is False):
|
|
mycommon.myprint(str(saved_file))
|
|
return False, str(saved_file)
|
|
|
|
#print(" signature manuelle = ", saved_file)
|
|
with open(saved_file, "rb") as imageFile:
|
|
image_signature_manuelle_string = base64.b64encode(imageFile.read()).decode()
|
|
|
|
"""
|
|
22/06/204 - On abandone l'approche qui consiste a envoyer le fichier de signature.
|
|
on va plutot envoyer directement la signature sous forme d'image.
|
|
"""
|
|
image_signature_manuelle_string_v2 = diction['signature_img_selected']
|
|
|
|
tab_my_emargement_ids = str(my_emargement_ids).split(",")
|
|
for my_emargement_id in tab_my_emargement_ids:
|
|
data_cle = {'emargement_qr_safe_token': str(diction['my_safe_token']),
|
|
'_id': ObjectId(str(my_emargement_id)),
|
|
'partner_owner_recid': str(diction['partner_owner_recid']),
|
|
'statut': '1'}
|
|
|
|
is_present = ""
|
|
if ("is_present" in diction.keys()):
|
|
if diction['is_present']:
|
|
is_present = diction['is_present']
|
|
|
|
|
|
|
|
# Mettre à jour de l'emargement
|
|
data_update = {}
|
|
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
|
data_update['date_update'] = now
|
|
data_update['statut'] = "2"
|
|
data_update['date_emargement'] = now
|
|
data_update['update_by'] = str(my_partner['_id'])
|
|
|
|
#data_update["mysy_manual_signature_img"] = "data:image/png;base64," + image_signature_manuelle_string
|
|
|
|
data_update["mysy_manual_signature_img"] = image_signature_manuelle_string_v2
|
|
|
|
if (is_present == "1"):
|
|
data_update['is_present'] = True
|
|
elif (is_present == "0"):
|
|
data_update['is_present'] = False
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['emargement'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
return True, "L'émargement a été pris en compte"
|
|
|
|
|
|
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'émarger "
|
|
|
|
"""
|
|
Cette fonction permet d'ajouter et mettre à jour un split de facture sur une inscription
|
|
|
|
La fonction prends en entrée, l'inscription_id, tab_split :[{'partner_client':'cccc', 'invoice_part':'10'},
|
|
{'partner_client':'yyyyy', 'invoice_part':'800'}]}
|
|
"""
|
|
def Add_Update_Inscription_Split_Invoice(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'inscription_id', 'split_type', 'tab_split']
|
|
|
|
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', 'inscription_id', 'split_type', 'tab_split']
|
|
|
|
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é de l'inscription
|
|
is_inscription_valide_count = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])
|
|
})
|
|
if( is_inscription_valide_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
# Verifier que le 'split_type' est soit percent, soit fixe
|
|
split_type = str(diction["split_type"]).lower()
|
|
|
|
if( split_type not in ['fixe', 'percent']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type de partage doit être en pourcentage ou en montant ")
|
|
return False, " Le type de partage doit être en pourcentage ou en montant "
|
|
|
|
# Verifier que le contenu 'tab_split' est valide et du type : [{'partner_client':'cccc', 'invoice_part':'10'},
|
|
# {'partner_client':'yyyyy', 'invoice_part':'800'}]
|
|
tab_split = diction['tab_split']
|
|
tab_split_JSON = ast.literal_eval(tab_split)
|
|
|
|
print(" ### tab_split_JSON = ", tab_split_JSON)
|
|
|
|
total_invoice_part = 0
|
|
|
|
for val in tab_split_JSON:
|
|
is_val_ok = "0"
|
|
if( "partner_client" in val.keys() and val['partner_client'] and "invoice_part" in val.keys() and val["invoice_part"]):
|
|
local_client = str(val['partner_client'])
|
|
local_partage = str(val["invoice_part"])
|
|
|
|
# Verifier que le client dans le partage est valide
|
|
is_partage_client_valide = MYSY_GV.dbname['partner_client'].count_documents({'_id':ObjectId(str(local_client)),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_recid':str(my_partner['recid'])})
|
|
|
|
|
|
if( is_partage_client_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du client "+str(local_client)+" est invalide ")
|
|
return False, " L'identifiant du client "+str(local_client)+" est invalide "
|
|
|
|
# Verifier que la valeur de partage est bien un floattant
|
|
is_partage_float_status, is_partage_float_retval = mycommon.IsFloat(local_partage)
|
|
if( is_partage_float_status is False ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur de partage " + str(
|
|
local_partage) + " est invalide ")
|
|
return False, " La valeur de partage " + str(local_partage) + " est invalide "
|
|
|
|
|
|
total_invoice_part = total_invoice_part + is_partage_float_retval
|
|
is_val_ok = "1"
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Les paramètres de partage de la facture sont invalides ")
|
|
return False, " Les paramètres de partage de la facture sont invalides "
|
|
|
|
|
|
|
|
if( split_type == "percent" and total_invoice_part > 100 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Pour une répartition par pourcentage, le total ne doit pas depasser 100% ")
|
|
return False, " Pour une répartition par pourcentage, le total ne doit pas dépasser 100% "
|
|
|
|
|
|
node_invoice_split = {}
|
|
node_invoice_split['split_type'] = split_type
|
|
node_invoice_split['tab_split'] = tab_split_JSON
|
|
|
|
data_update = {}
|
|
data_update['update_by'] = str(my_partner['_id'])
|
|
data_update['date_update'] = str(datetime.now())
|
|
data_update['invoice_split'] = node_invoice_split
|
|
|
|
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
},
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(" Impossible de mettre à jour le partage de facture (2) ")
|
|
return False, " Impossible de mettre à jour le partage de facture (2) "
|
|
|
|
return True, " Le partage de facture 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) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour le Le partage de facture "
|
|
|
|
"""
|
|
Cette fonction permet de recuperer uniquement
|
|
le partage de facture d'un inscription
|
|
"""
|
|
|
|
def Get_Inscription_Split_Invoice(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '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', 'inscription_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
|
|
|
|
# Verifier la validité de l'inscription
|
|
is_inscription_valide_count = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])
|
|
})
|
|
if( is_inscription_valide_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
for New_retVal in MYSY_GV.dbname['inscription'].find({'_id':ObjectId(str(diction['inscription_id'])),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])
|
|
}, {'_id':1, 'email':1, 'invoice_split':1}):
|
|
user = New_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 partage de facture "
|
|
|
|
|
|
"""
|
|
Cette fonction supprime un partage de facture sur une inscription
|
|
"""
|
|
|
|
def Delete_Inscription_Split_Invoice(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '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', 'inscription_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
|
|
|
|
# Verifier la validité de l'inscription
|
|
is_inscription_valide_count = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
})
|
|
if (is_inscription_valide_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'inscription est invalide ")
|
|
return False, " L'identifiant de l'inscription est invalide "
|
|
|
|
result = MYSY_GV.dbname['inscription'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['inscription_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
},
|
|
{"$unset": {"invoice_split":""}},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(" Impossible supprimer le partage de facture (2) ")
|
|
return False, " Impossible supprimer le partage de facture (2) "
|
|
|
|
return True, " Le partage de facture a été correctement supprimé "
|
|
|
|
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 supprimer le partage de facture "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet de modidier la fin de
|
|
validité des acces au e-learning pour une liste
|
|
d'inscription.
|
|
Concretement cette fonction va desincrire l'apprenant à la formation dans le LMS
|
|
"""
|
|
def Update_LMS_Inscrition_End_Date(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'tab_inscription_ids', 'end_date']
|
|
|
|
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', 'tab_inscription_ids', 'end_date']
|
|
|
|
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
|
|
"""
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_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, False
|
|
|
|
end_date = str(diction['end_date'])[0:10]
|
|
local_status = mycommon.CheckisDate(end_date)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " La date de fin n'est pas au format jj/mm/aaaa.")
|
|
return False, " La date de fin n'est pas au format jj/mm/aaaa."
|
|
|
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
|
if (datetime.strptime(str(diction['end_date'])[0:10], '%d/%m/%Y') < datetime.strptime(str(mytoday).strip(),
|
|
'%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin d'accès au LMS " + str(
|
|
diction['end_date']) + " est antérieure à la date du jour ")
|
|
|
|
return False, " La date de fin d'accès au LMS " + str(
|
|
diction['end_date']) + " est antérieure à la date du jour "
|
|
|
|
|
|
# Verifier que la session est valide
|
|
is_session_id_valide = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_session_id_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la session est invalide ")
|
|
return False, " L'identifiant de la session est invalide ", False
|
|
|
|
|
|
my_inscription_ids = ""
|
|
if ("tab_inscription_ids" in diction.keys()):
|
|
if diction['tab_inscription_ids']:
|
|
my_inscription_ids = diction['tab_inscription_ids']
|
|
|
|
tab_my_inscription_ids = str(my_inscription_ids).split(",")
|
|
tab_my_inscription_ids_ObjectId = []
|
|
for tmp in tab_my_inscription_ids:
|
|
tab_my_inscription_ids_ObjectId.append(ObjectId(str(tmp)))
|
|
|
|
|
|
tab_my_inscription_ids = str(my_inscription_ids).split(",")
|
|
|
|
now = str(datetime.now())
|
|
update_data = {}
|
|
|
|
update_data['date_update'] = now
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['lms_account_expiration_date'] = str(end_date)
|
|
|
|
update = MYSY_GV.dbname['inscription'].update_many({'partner_owner_recid': str(my_partner['recid']),
|
|
'session_id': diction['session_id'],
|
|
'_id':{'$in':tab_my_inscription_ids_ObjectId},},
|
|
{'$set': update_data})
|
|
|
|
|
|
|
|
|
|
|
|
return True, " La mise à jour é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) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour la date "
|
|
|