04/02/2024 - 21h
parent
6bd21df4c5
commit
36142417a6
|
@ -1,19 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="02/02/2024 - 23h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="03/02/2024 - 21h">
|
||||
<change afterPath="$PROJECT_DIR$/attestation_formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/class_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/class_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/email_inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/email_inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_client.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_invoice.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_order.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_order.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ressources_humaines.py" beforeDir="false" afterPath="$PROJECT_DIR$/ressources_humaines.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" beforeDir="false" afterPath="$PROJECT_DIR$/tools_cherif/tools_cherif.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -83,13 +77,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00162" summary="05/12/2023 - 21h">
|
||||
<created>1701809248688</created>
|
||||
<option name="number" value="00162" />
|
||||
<option name="presentableId" value="LOCAL-00162" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1701809248689</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00163" summary="06/12/2023 - 21h">
|
||||
<created>1701892535755</created>
|
||||
<option name="number" value="00163" />
|
||||
|
@ -426,7 +413,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1706911273735</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="211" />
|
||||
<task id="LOCAL-00211" summary="03/02/2024 - 21h">
|
||||
<created>1706989870351</created>
|
||||
<option name="number" value="00211" />
|
||||
<option name="presentableId" value="LOCAL-00211" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1706989870351</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="212" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -441,7 +435,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="01/01/2024- 18h" />
|
||||
<MESSAGE value="03/01/2024 - 17h30" />
|
||||
<MESSAGE value="04/01/2024 - 22h30" />
|
||||
<MESSAGE value="5555" />
|
||||
|
@ -466,6 +459,7 @@
|
|||
<MESSAGE value="31/01/2024 - 20h" />
|
||||
<MESSAGE value="02/02/2024 - 17h" />
|
||||
<MESSAGE value="02/02/2024 - 23h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="02/02/2024 - 23h" />
|
||||
<MESSAGE value="03/02/2024 - 21h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="03/02/2024 - 21h" />
|
||||
</component>
|
||||
</project>
|
1868
Log/log_file.log
1868
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -6259,3 +6259,564 @@ def Sent_Convocation_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
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 prepare et envoi les attestation de formation a chaque
|
||||
participant à la session de formation
|
||||
"""
|
||||
def Prepare_and_Send_Attestation_From_Session_By_Email(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'session_id', 'email_test', 'email_production', '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 liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste"
|
||||
|
||||
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_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_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 "
|
||||
|
||||
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)))
|
||||
|
||||
qry = {"session_id":str(diction['session_id']),
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
'valide':"1",
|
||||
"locked":'0',
|
||||
'_id': { '$in': tab_inscriptions_ids_splited_obj} }
|
||||
print("### qry zzzz = ", qry)
|
||||
|
||||
|
||||
|
||||
for attestation_formation_data in MYSY_GV.dbname['attestation_formation'].find({"session_id":str(diction['session_id']),
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
'valide':"1",
|
||||
"locked":'0',
|
||||
'_id': { '$in': tab_inscriptions_ids_splited_obj} }):
|
||||
|
||||
|
||||
|
||||
|
||||
# Recupération des données du modèle de document
|
||||
is_convention_by_client = "0"
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one(
|
||||
{'_id': ObjectId(str(attestation_formation_data['courrier_template_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
)
|
||||
|
||||
if( courrier_template_data and "edit_by_client" in courrier_template_data.keys() and courrier_template_data['edit_by_client'] == "1"):
|
||||
is_convention_by_client = "1"
|
||||
|
||||
|
||||
#field_list_obligatoire = [ 'token', 'inscription_id', 'courrier_template_id', 'email_test', 'email_production' ]
|
||||
new_diction_no_client = {}
|
||||
new_diction_no_client['token'] = str(diction['token'])
|
||||
new_diction_no_client['inscription_id'] = str(attestation_formation_data['inscription_id'])
|
||||
new_diction_no_client['courrier_template_id'] = attestation_formation_data['courrier_template_id']
|
||||
|
||||
new_diction_no_client['session_id'] = diction['session_id']
|
||||
new_diction_no_client['email_test'] = diction['email_test']
|
||||
new_diction_no_client['email_production'] = diction['email_production']
|
||||
|
||||
print(" ##### new_diction_no_client = ", new_diction_no_client)
|
||||
tab_saved_file_full_path = []
|
||||
local_status, local_retval = Sent_Attestation_Stagiaire_By_Email(tab_saved_file_full_path, Folder, new_diction_no_client)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" WARNING impossible d'envoyer l'attestation de formation a l'apprenant : " + str(attestation_formation_data['inscription_id']) )
|
||||
|
||||
|
||||
# Traitement de l'eventuel fichier joint
|
||||
tab_files_to_attache_to_mail = []
|
||||
|
||||
"""
|
||||
25/01/2024 : pour 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, "ATTESTATION_FORMATION", str(diction['session_id']), 'inscription',
|
||||
str(attestation_formation_data['inscription_id']),
|
||||
str(attestation_formation_data['courrier_template_id']))
|
||||
|
||||
# Mettre à jour avec la date d'envoi de l'attestation
|
||||
updata_data = {}
|
||||
updata_data['date_update'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
updata_data['update_by'] = str(my_partner['recid'])
|
||||
updata_data['statut'] = "1"
|
||||
updata_data['date_envoie'] = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||
|
||||
|
||||
MYSY_GV.dbname['attestation_formation'].find_one_and_update({'_id':ObjectId(str(attestation_formation_data['_id'])),
|
||||
'partner_owner_recid':str(my_partner['recid'])},
|
||||
{'$set':updata_data})
|
||||
|
||||
|
||||
return True, " Les attestation ont été correctement envoyées par emails"
|
||||
|
||||
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 conventions par email "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Envoi d'une attestation pour un participant donné par email
|
||||
Si le participants est rattaché à un client , alors on va mettre en copie de
|
||||
l'email les contacts de communication du client de rattachement
|
||||
"""
|
||||
def Sent_Attestation_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 liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste"
|
||||
|
||||
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 "
|
||||
|
||||
# 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 = Inscription_mgt.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'])})
|
||||
|
||||
tab_apprenant_client_rattachement_contact = ""
|
||||
# Verifier si le modele de courrier n'est par 'edit_by_client', au quel cas on verifie que l'appressant est bien lié à un client
|
||||
if ("edit_by_client" in courrier_template_data.keys() and str(courrier_template_data['edit_by_client']) == "0"):
|
||||
stagiaire_client_id = ""
|
||||
|
||||
if ("client_rattachement_id" in inscription_data.keys() and inscription_data['client_rattachement_id']):
|
||||
stagiaire_client_id = str(inscription_data['client_rattachement_id'])
|
||||
local_diction = {"token":str(diction['token']), "_id":stagiaire_client_id }
|
||||
|
||||
print(" ##### local_diction pr Get_Partner_Client_Communication_Contact= ", local_diction)
|
||||
local_status, partner_client_contact_communication = partner_client.Get_Partner_Client_Communication_Contact(local_diction)
|
||||
|
||||
if (local_status is True):
|
||||
print(" ### partner_client_contact_communication = ", partner_client_contact_communication)
|
||||
tab_local_email_production = []
|
||||
for tmp in partner_client_contact_communication:
|
||||
tmp_JSON = ast.literal_eval(tmp)
|
||||
if ("email" in tmp_JSON.keys()):
|
||||
tab_local_email_production.append(str(tmp_JSON["email"]))
|
||||
|
||||
tab_apprenant_client_rattachement_contact = ",".join(tab_local_email_production)
|
||||
|
||||
|
||||
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'])))
|
||||
|
||||
|
||||
|
||||
# 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 = "Convocation_" + 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['Cc'] = tab_apprenant_client_rattachement_contact
|
||||
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['Cc'] = tab_apprenant_client_rattachement_contact
|
||||
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)
|
||||
history_event_dict['action_description'] = "Attestation de formation 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))
|
||||
|
||||
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 "
|
||||
|
|
|
@ -0,0 +1,661 @@
|
|||
"""
|
||||
Ce document permet de gerer les attestations de formation.
|
||||
|
||||
Dans le processus d'utilisation,
|
||||
- On initialiser les attestation d'une session
|
||||
- On peut visualiser les attestion
|
||||
- on peut envoyer et renvoyer / télécharger des attestations
|
||||
|
||||
Pour permettre d'avoir des attestation differentes sur une session,
|
||||
on prendre entrée le tab_ids des inscriptions concernée
|
||||
|
||||
|
||||
- Envoi
|
||||
- recuperation des attestation d'une session
|
||||
- etc
|
||||
"""
|
||||
import bson
|
||||
import pymongo
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import jinja2
|
||||
from flask import send_file
|
||||
from xhtml2pdf import pisa
|
||||
from email.message import EmailMessage
|
||||
from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
|
||||
|
||||
"""
|
||||
Initialisation de la liste des attestation avec une version du courrier
|
||||
"""
|
||||
def Init_Attestation_Formation_With_Template(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'tab_inscriptions_ids', 'courrier_template_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', 'tab_inscriptions_ids', '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 liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
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(",")
|
||||
|
||||
# Controle de validité de toutes info avant de commencer à initialiser les attesations
|
||||
for my_inscription in tab_inscriptions_ids_splited:
|
||||
|
||||
# Verifier que l'inscription est valide
|
||||
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(my_inscription)), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
|
||||
if( my_inscription_is_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' n'est pas valide ")
|
||||
return False, " L'inscription_id '" + my_inscription + "' n'est pas valide "
|
||||
|
||||
# Verifier la valididé du model de courrier
|
||||
is_courrier_valide = MYSY_GV.dbname['courrier_template'].count_documents({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (is_courrier_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide ")
|
||||
return False, " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide "
|
||||
|
||||
|
||||
# A présent les inscriptions sont ok, le modele de courrier ok, on peut proceder à l'initialisation des attestations
|
||||
|
||||
warning_message = " WARNING : "
|
||||
is_warning_message = 0
|
||||
is_courrier_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'])})
|
||||
|
||||
cpt = 0
|
||||
for my_inscription in tab_inscriptions_ids_splited:
|
||||
|
||||
# Verifier que l'inscription est valide
|
||||
my_inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(my_inscription)), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
new_attestation_data = {}
|
||||
new_attestation_data['date_update'] = str(datetime.now())
|
||||
new_attestation_data['update_by'] = str(my_partner['_id'])
|
||||
new_attestation_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
new_attestation_data['valide'] = "1"
|
||||
new_attestation_data['locked'] = "0"
|
||||
new_attestation_data['statut'] = "0"
|
||||
new_attestation_data['date_envoie'] = ""
|
||||
|
||||
new_attestation_data['inscription_id'] = str(my_inscription_data['_id'])
|
||||
new_attestation_data['session_id'] = str(my_inscription_data['session_id'])
|
||||
new_attestation_data['courrier_template_id'] = str(is_courrier_data['_id'])
|
||||
|
||||
update_key = {}
|
||||
update_key['inscription_id'] = str(my_inscription_data['_id'])
|
||||
update_key['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
ret_val2 = MYSY_GV.dbname['attestation_formation'].find_one_and_update(
|
||||
update_key,
|
||||
{"$set": new_attestation_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=True,
|
||||
)
|
||||
|
||||
if (ret_val2 is None):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription_data['_id']))
|
||||
warning_message = warning_message +" Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription_data['_id']) +" - "
|
||||
is_warning_message = 1
|
||||
else:
|
||||
cpt = cpt +1
|
||||
|
||||
|
||||
|
||||
if( is_warning_message == 1 ):
|
||||
return True, str(cpt) + " Attestation(s) initialisée(s) : "+str(warning_message)
|
||||
|
||||
return True, str(cpt)+" Attestation(s) initialisé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'initialiser les attestations"
|
||||
|
||||
|
||||
"""
|
||||
Initialisation de la liste des attestation pour toutes les inscription d'une session.
|
||||
ici on ne prend pas une inscription specifique
|
||||
"""
|
||||
def Init_Attestation_Formation_With_Template_For_All_Inscription(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_id', 'courrier_template_id', ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'session_id', '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 liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
|
||||
|
||||
# Verifier la valididé du model de courrier
|
||||
is_courrier_valide = MYSY_GV.dbname['courrier_template'].count_documents({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (is_courrier_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide ")
|
||||
return False, " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide "
|
||||
|
||||
|
||||
# A présent les inscriptions sont ok, le modele de courrier ok, on peut proceder à l'initialisation des attestations
|
||||
|
||||
warning_message = " WARNING : "
|
||||
is_warning_message = 0
|
||||
is_courrier_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'])})
|
||||
|
||||
cpt = 0
|
||||
for my_inscription in MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])}):
|
||||
|
||||
|
||||
new_attestation_data = {}
|
||||
new_attestation_data['date_update'] = str(datetime.now())
|
||||
new_attestation_data['update_by'] = str(my_partner['_id'])
|
||||
new_attestation_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
new_attestation_data['valide'] = "1"
|
||||
new_attestation_data['locked'] = "0"
|
||||
new_attestation_data['statut'] = "0"
|
||||
|
||||
new_attestation_data['inscription_id'] = str(my_inscription['_id'])
|
||||
new_attestation_data['session_id'] = str(my_inscription['session_id'])
|
||||
new_attestation_data['courrier_template_id'] = str(is_courrier_data['_id'])
|
||||
|
||||
update_key = {}
|
||||
update_key['inscription_id'] = str(my_inscription['_id'])
|
||||
update_key['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
ret_val2 = MYSY_GV.dbname['attestation_formation'].find_one_and_update(
|
||||
update_key,
|
||||
{"$set": new_attestation_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=True,
|
||||
)
|
||||
|
||||
if (ret_val2 is None):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription['_id']))
|
||||
warning_message = warning_message +" Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription['_id']) +" - "
|
||||
is_warning_message = 1
|
||||
else:
|
||||
cpt = cpt +1
|
||||
|
||||
|
||||
if( is_warning_message == 1 ):
|
||||
return True, str(cpt) + " Attestation(s) initialisée(s) : "+str(warning_message)
|
||||
|
||||
return True, str(cpt)+" Attestation(s) initialisé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'initialiser les attestations"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Récuperer les attestatioon d'une session de formation
|
||||
"""
|
||||
def Get_Attestion_By_Session(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = field_list = ['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 liste ")
|
||||
return False, " Les informations fournies sont incorrectes",
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
for New_retVal in MYSY_GV.dbname['attestation_formation'].find({'session_id':str(diction['session_id']),
|
||||
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}):
|
||||
|
||||
user = New_retVal
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
# Recuperation des données de l'apprenant concernée
|
||||
qry_filter = {'session_id': str(New_retVal['session_id']), '_id': ObjectId(str(New_retVal['inscription_id'])),'partner_owner_recid': str(New_retVal['partner_owner_recid'])}
|
||||
pipe_qry = ([{'$match': qry_filter},
|
||||
|
||||
{'$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_Attestion_By_Session ici pipe_qry = ", pipe_qry)
|
||||
|
||||
|
||||
nom = ""
|
||||
prenom = ""
|
||||
email = ""
|
||||
for local_Insc_retval in MYSY_GV.dbname['inscription'].aggregate(pipe_qry):
|
||||
|
||||
if ('apprenant_collection' in local_Insc_retval.keys() and len(local_Insc_retval['apprenant_collection']) > 0):
|
||||
|
||||
nom = str(local_Insc_retval['apprenant_collection'][0]['nom'])
|
||||
prenom = str(local_Insc_retval['apprenant_collection'][0]['prenom'])
|
||||
email = str(local_Insc_retval['apprenant_collection'][0]['email'])
|
||||
|
||||
else:
|
||||
|
||||
nom = str(local_Insc_retval['nom'])
|
||||
prenom = str(local_Insc_retval['prenom'])
|
||||
email = str(local_Insc_retval['email'])
|
||||
|
||||
user['nom'] = nom
|
||||
user['prenom'] = prenom
|
||||
user['email'] = email
|
||||
|
||||
if( "date_envoie" not in user.keys() ):
|
||||
user['date_envoie'] = ""
|
||||
|
||||
if ("courrier_template_id" not in user.keys()):
|
||||
user['courrier_template_id'] = ""
|
||||
user['courrier_template_nom'] = ""
|
||||
else:
|
||||
model_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(user['courrier_template_id'])),
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if("nom" in model_courrier_data.keys() ):
|
||||
user['courrier_template_nom'] = str(model_courrier_data['nom'])
|
||||
else:
|
||||
user['courrier_template_nom'] = ""
|
||||
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
|
||||
|
||||
return True, RetObject
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer la liste des attestations "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction recupere les differentes modele d'attestation de formation de stagiaire avec des option comme :
|
||||
- ref_interne
|
||||
- nom
|
||||
- type_doc
|
||||
|
||||
On accepte plusieurs versions du meme doc
|
||||
"""
|
||||
|
||||
def Get_List_Modele_Attestion_Formation_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 liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste"
|
||||
|
||||
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' = 'ATTESTATION_FORMATION'
|
||||
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': 'ATTESTATION_FORMATION',
|
||||
'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 ]}
|
||||
|
||||
print(" #### qry = ", qry)
|
||||
|
||||
for retval in MYSY_GV.dbname['courrier_template'].find({'$and': [{'ref_interne': 'ATTESTATION_FORMATION',
|
||||
'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': 'ATTESTATION_FORMATION',
|
||||
'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 attestations de formation"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Envoi des attestation de formation
|
||||
"""
|
||||
def Send_Attestation_Formation_With_Template(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'tab_inscriptions_ids', 'courrier_template_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', 'tab_inscriptions_ids', '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 liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
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(",")
|
||||
|
||||
# Controle de validité de toutes info avant de commencer à initialiser les attesations
|
||||
for my_inscription in tab_inscriptions_ids_splited:
|
||||
|
||||
# Verifier que l'inscription est valide
|
||||
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(my_inscription)), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
|
||||
if( my_inscription_is_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' n'est pas valide ")
|
||||
return False, " L'inscription_id '" + my_inscription + "' n'est pas valide "
|
||||
|
||||
# Verifier la valididé du model de courrier
|
||||
is_courrier_valide = MYSY_GV.dbname['courrier_template'].count_documents({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (is_courrier_valide != 1):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide ")
|
||||
return False, " Le modèle de courrier '" + str(diction['courrier_template_id']) + "' n'est pas valide "
|
||||
|
||||
|
||||
# A présent les inscriptions sont ok, le modele de courrier ok, on peut proceder à l'initialisation des attestations
|
||||
|
||||
warning_message = " WARNING : "
|
||||
is_warning_message = 0
|
||||
is_courrier_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'])})
|
||||
|
||||
cpt = 0
|
||||
for my_inscription in tab_inscriptions_ids_splited:
|
||||
|
||||
# Verifier que l'inscription est valide
|
||||
my_inscription_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(my_inscription)), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
new_attestation_data = {}
|
||||
new_attestation_data['date_update'] = str(datetime.now())
|
||||
new_attestation_data['update_by'] = str(my_partner['_id'])
|
||||
new_attestation_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
new_attestation_data['valide'] = "1"
|
||||
new_attestation_data['locked'] = "0"
|
||||
new_attestation_data['statut'] = "0"
|
||||
|
||||
new_attestation_data['inscription_id'] = str(my_inscription_data['_id'])
|
||||
new_attestation_data['session_id'] = str(my_inscription_data['session_id'])
|
||||
new_attestation_data['courrier_template_id'] = str(is_courrier_data['_id'])
|
||||
|
||||
update_key = {}
|
||||
update_key['inscription_id'] = str(my_inscription_data['_id'])
|
||||
update_key['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
ret_val2 = MYSY_GV.dbname['attestation_formation'].find_one_and_update(
|
||||
update_key,
|
||||
{"$set": new_attestation_data},
|
||||
return_document=ReturnDocument.AFTER,
|
||||
upsert=True,
|
||||
)
|
||||
|
||||
if (ret_val2 is None):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription_data['_id']))
|
||||
warning_message = warning_message +" Impossible d'initialiser l'attestation de formation pour l'inscription : "+str(my_inscription_data['_id']) +" - "
|
||||
is_warning_message = 1
|
||||
else:
|
||||
cpt = cpt +1
|
||||
|
||||
|
||||
|
||||
if( is_warning_message == 1 ):
|
||||
return True, str(cpt) + " Attestation(s) initialisée(s) : "+str(warning_message)
|
||||
|
||||
return True, str(cpt)+" Attestation(s) initialisé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'initialiser les attestations"
|
80
main.py
80
main.py
|
@ -73,6 +73,7 @@ import Collection_Historique as Collection_Historique
|
|||
import purchase_prices as purchase_prices
|
||||
import apprenant_mgt as apprenant_mgt
|
||||
import module_editique as module_editique
|
||||
import attestation_formation as attestation_formation
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
@ -7363,11 +7364,11 @@ def Action_Server_send_convention_entreprise_mail():
|
|||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Action_Server_send_convention_entreprise_mail payload = ",payload)
|
||||
|
||||
return jsonify(status=True, message=" OK Action_Server_send_convention_entreprise_mail")
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API : pour préprer et générer un zip de fichier PDF pour les convocation en partant d'une session
|
||||
"""
|
||||
|
@ -7413,8 +7414,85 @@ def Prepare_and_Send_Convocation_From_Session_By_Email():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API pour initialiser les attestation de formation pour une session données
|
||||
"""
|
||||
@app.route('/myclass/api/Init_Attestation_Formation_With_Template/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Init_Attestation_Formation_With_Template():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Init_Attestation_Formation_With_Template payload = ",payload)
|
||||
print(request.files)
|
||||
status, retval = attestation_formation.Init_Attestation_Formation_With_Template(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour l'initialisation de la liste des attestation pour toutes les inscription d'une session.
|
||||
ici on ne prend pas une inscription specifique
|
||||
"""
|
||||
@app.route('/myclass/api/Init_Attestation_Formation_With_Template_For_All_Inscription/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Init_Attestation_Formation_With_Template_For_All_Inscription():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Init_Attestation_Formation_With_Template_For_All_Inscription payload = ",payload)
|
||||
print(request.files)
|
||||
status, retval = attestation_formation.Init_Attestation_Formation_With_Template_For_All_Inscription(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer la listes des attestation de formation pour une session données
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Attestion_By_Session/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Attestion_By_Session():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Attestion_By_Session payload = ",payload)
|
||||
print(request.files)
|
||||
status, retval = attestation_formation.Get_Attestion_By_Session(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer les differentes modele d'attestation de formation de stagiaire avec des option comme
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Modele_Attestion_Formation_With_Filter/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_List_Modele_Attestion_Formation_With_Filter():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_List_Modele_Attestion_Formation_With_Filter payload = ",payload)
|
||||
print(request.files)
|
||||
status, retval = attestation_formation.Get_List_Modele_Attestion_Formation_With_Filter(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API Pour envoyer les attestation par email
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Attestation_From_Session_By_Email/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Attestation_From_Session_By_Email():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Prepare_and_Send_Attestation_From_Session_By_Email : payload = ",str(payload))
|
||||
|
||||
file = []
|
||||
if request.method == 'POST':
|
||||
# Create variable for uploaded file
|
||||
tab_files = []
|
||||
for tmp in request.files.getlist("File"):
|
||||
tab_files.append(tmp)
|
||||
|
||||
status, retval = SF.Prepare_and_Send_Attestation_From_Session_By_Email(tab_files, MYSY_GV.TEMPORARY_DIRECTORY_V2, payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
|
|
|
@ -4397,7 +4397,6 @@ def Get_Dictionnary_data_For_Template(diction):
|
|||
|
||||
local_JSON = ast.literal_eval(local_part_imgs[0])
|
||||
|
||||
|
||||
new_field_logo = {'societe_logo': "data:image/png;base64,"+local_JSON['logo_img']}
|
||||
new_field_cachet = {'societe_cachet': "data:image/png;base64,"+local_JSON['cachet_img']}
|
||||
company_data.update(new_field_logo)
|
||||
|
|
Loading…
Reference in New Issue