24/12/2022 - 15h00
parent
06c2b5870e
commit
c4b91143a2
|
@ -5,6 +5,8 @@
|
|||
<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$/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$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
|
|
@ -1164,7 +1164,7 @@ def MySyckeckEvaluationToken(diction):
|
|||
|
||||
local_qry = {'class_internal_url':internal_url, '_id': ObjectId(eval_token), "eval_date":{"$exists":False} }
|
||||
|
||||
print(" ### local_qry =",local_qry)
|
||||
#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} } )
|
||||
|
||||
|
@ -1180,3 +1180,297 @@ def MySyckeckEvaluationToken(diction):
|
|||
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']
|
||||
|
||||
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"
|
||||
|
||||
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']),
|
||||
"eval_date": {"$exists": True}})
|
||||
|
||||
if (tmp_count > 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Vous avez deja evalué cette formation")
|
||||
return False, " Vous avez deja evalué cette formation"
|
||||
|
||||
|
||||
RetObject = []
|
||||
# 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'])})
|
||||
|
||||
my_retrun_dict = {}
|
||||
|
||||
my_retrun_dict['token_eval'] = local_Insc_retval['_id']
|
||||
my_retrun_dict['session_id'] = local_Insc_retval['session_id']
|
||||
my_retrun_dict['date_du'] = local_Insc_retval['date_du']
|
||||
my_retrun_dict['date_au'] = local_Insc_retval['date_au']
|
||||
my_retrun_dict['ville'] = local_Insc_retval['ville']
|
||||
my_retrun_dict['code_postal'] = local_Insc_retval['code_postal']
|
||||
my_retrun_dict['internal_url'] = local_Insc_retval['class_internal_url']
|
||||
|
||||
my_retrun_dict['adresse'] = local_Insc_retval['adresse']
|
||||
my_retrun_dict['nom'] = local_Insc_retval['nom']
|
||||
my_retrun_dict['prenom'] = local_Insc_retval['prenom']
|
||||
my_retrun_dict['employeur'] = local_Insc_retval['employeur']
|
||||
my_retrun_dict['telephone'] = local_Insc_retval['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']
|
||||
|
||||
# Envoi de l'email de notification au formateur
|
||||
local_status, local_message = email_session.Evaluation_training_confirmation_mail(my_retrun_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 le certificat d'un stagiaire
|
||||
"""
|
||||
def SendAttendeeCertification(diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['session_id', 'token', 'attendee_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 liste ")
|
||||
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_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({'formation_session_id': str(diction['session_id']),
|
||||
'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"
|
||||
|
||||
attestation_certificat = MYSY_GV.dbname['attestation_certificat'].find_one({'nom': str(session_formation['attestation_certif']),
|
||||
'valide': "1"})
|
||||
|
||||
my_retrun_dict = {}
|
||||
|
||||
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 recuperer les données de l'inscrit")
|
||||
return False, " Impossible de recuperer 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']
|
||||
my_retrun_dict['ville'] = local_Insc_retval['ville']
|
||||
my_retrun_dict['code_postal'] = local_Insc_retval['code_postal']
|
||||
my_retrun_dict['internal_url'] = local_Insc_retval['class_internal_url']
|
||||
|
||||
my_retrun_dict['inscription_id'] = local_Insc_retval['_id']
|
||||
|
||||
|
||||
my_retrun_dict['adresse'] = local_Insc_retval['adresse']
|
||||
my_retrun_dict['nom'] = local_Insc_retval['nom']
|
||||
my_retrun_dict['prenom'] = local_Insc_retval['prenom']
|
||||
my_retrun_dict['employeur'] = local_Insc_retval['employeur']
|
||||
my_retrun_dict['telephone'] = local_Insc_retval['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']
|
||||
|
||||
# Envoi de l'email de notification au formateur
|
||||
local_status, local_message = email_session.SendAttestion_to_attendee_by_email(my_retrun_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']
|
||||
|
||||
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"
|
||||
|
||||
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 evalué cette formation")
|
||||
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(
|
||||
{'formation_session_id': str(diction['session_id']),
|
||||
'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"
|
||||
|
||||
attestation_certificat = MYSY_GV.dbname['attestation_certificat'].find_one(
|
||||
{'nom': str(session_formation['attestation_certif']),
|
||||
'valide': "1"})
|
||||
|
||||
my_retrun_dict = {}
|
||||
|
||||
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 recuperer les données de l'inscrit")
|
||||
return False, " Impossible de recuperer 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']
|
||||
my_retrun_dict['ville'] = local_Insc_retval['ville']
|
||||
my_retrun_dict['code_postal'] = local_Insc_retval['code_postal']
|
||||
my_retrun_dict['internal_url'] = local_Insc_retval['class_internal_url']
|
||||
|
||||
my_retrun_dict['adresse'] = local_Insc_retval['adresse']
|
||||
my_retrun_dict['nom'] = local_Insc_retval['nom']
|
||||
my_retrun_dict['prenom'] = local_Insc_retval['prenom']
|
||||
my_retrun_dict['employeur'] = local_Insc_retval['employeur']
|
||||
my_retrun_dict['telephone'] = local_Insc_retval['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']
|
||||
|
||||
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"])
|
||||
orig_file_name = "Attestation_.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"
|
||||
|
||||
|
||||
|
|
1179
Log/log_file.log
1179
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -8,6 +8,10 @@ import locale
|
|||
import datetime
|
||||
import inspect
|
||||
import sys, os
|
||||
|
||||
from bson import ObjectId
|
||||
from pymongo import ReturnDocument
|
||||
|
||||
import prj_common as mycommon
|
||||
import GlobalVariable as MYSY_GV
|
||||
from dateutil import tz
|
||||
|
@ -398,3 +402,169 @@ def Notification_partner_Pre_incription_mail(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible d'envoyer l'email de notification "
|
||||
|
||||
"""
|
||||
Envoi de l'email d'evaluation
|
||||
"""
|
||||
def Evaluation_training_confirmation_mail(diction):
|
||||
try:
|
||||
|
||||
print(" ### Evaluation_training_confirmation_mail = " + str(diction))
|
||||
"""
|
||||
Verification de la liste des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'date_au', 'adresse', 'title', 'token_eval', '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 liste ")
|
||||
return False, "Impossible d'envoyer l'email de confirmation de l'inscritpion"
|
||||
|
||||
|
||||
|
||||
tomorrow = datetime.date.today() + datetime.timedelta(days=1)
|
||||
tomorrow_day = tomorrow.strftime("%A")
|
||||
|
||||
print("debut envoi mail de test ")
|
||||
# on rentre les renseignements pris sur le site du fournisseur
|
||||
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
msg['Subject'] = 'MySy Training : Evaluation formation'
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['To'] = str(diction['email'])
|
||||
|
||||
my_url = ""
|
||||
if (MYSY_GV.MYSY_ENV == "PROD"):
|
||||
my_url = "https://www.mysy-training.com/Display-Detail-formation/" + str(diction['internal_url'])+"/"+str(diction['token_eval'])
|
||||
elif (MYSY_GV.MYSY_ENV == "DEV"):
|
||||
my_url = "http://localhost:3009/Display-Detail-formation/" + str(diction['internal_url'])+"/"+str(diction['token_eval'])
|
||||
elif (MYSY_GV.MYSY_ENV == "REC"):
|
||||
my_url = "https://dev.mysy-training.com/Display-Detail-formation/" + str(diction['internal_url'])+"/"+str(diction['token_eval'])
|
||||
|
||||
print(" ### Adresse = "+str(diction['adresse']) )
|
||||
|
||||
# msg = MIMEMultipart("alternative")
|
||||
msg = EmailMessage()
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
|
||||
# JINJA2
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "Template/MySy_Evaluation_Class_tpl.html"
|
||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||
# This data can come from database query
|
||||
body = {
|
||||
"params":{"nom": str(diction['nom']),
|
||||
"prenom": str(diction['prenom']),
|
||||
"date_du": str(diction['date_du']),
|
||||
"date_fin": str(diction['date_au']),
|
||||
"adresse": str(diction['adresse']),
|
||||
"title": str(diction['title']),
|
||||
"email": str(diction['email']),
|
||||
"mysyurl": str(my_url)} }
|
||||
|
||||
sourceHtml = template.render(params=body["params"])
|
||||
|
||||
msg.set_content(sourceHtml, subtype='html')
|
||||
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Cc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = 'MySy Training : Evaluation formation : '+str(diction['title'])
|
||||
msg['To'] = str(diction['email'])
|
||||
|
||||
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))
|
||||
|
||||
return True, " Email bien envoyé"
|
||||
|
||||
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 l'email de demande d'evaluation "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction envoi l'attestion par email
|
||||
"""
|
||||
def SendAttestion_to_attendee_by_email(diction):
|
||||
try:
|
||||
"""
|
||||
Verification de la liste des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'date_au', 'adresse', 'title',
|
||||
'attestation_tmpl', '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 liste ")
|
||||
return False, "Impossible d'envoyer l'attestation par email "
|
||||
|
||||
|
||||
print(' ### diction = ',str(diction))
|
||||
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['To'] = str(diction['email'])
|
||||
|
||||
|
||||
# msg = MIMEMultipart("alternative")
|
||||
msg = EmailMessage()
|
||||
smtpserver = smtplib.SMTP(MYSY_GV.O365_SMTP_COUNT_smtpsrv, MYSY_GV.O365_SMTP_COUNT_port)
|
||||
|
||||
# JINJA2
|
||||
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||
TEMPLATE_FILE = "Template/"+ str(diction['attestation_tmpl']) +".html"
|
||||
|
||||
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||
# This data can come from database query
|
||||
body = {
|
||||
"params": {"nom": str(diction['nom']),
|
||||
"prenom": str(diction['prenom']),
|
||||
"date_du": str(diction['date_du']),
|
||||
"date_fin": str(diction['date_au']),
|
||||
"adresse": str(diction['adresse']),
|
||||
"title": str(diction['title']),
|
||||
"email": str(diction['email']),
|
||||
}}
|
||||
|
||||
sourceHtml = template.render(json_data=body["params"])
|
||||
|
||||
msg.set_content(sourceHtml, subtype='html')
|
||||
|
||||
msg['From'] = MYSY_GV.O365_SMTP_COUNT_From_User
|
||||
msg['Cc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = 'MySy Training : Votre attestation de formation : ' + str(diction['title'])
|
||||
msg['To'] = str(diction['email'])
|
||||
|
||||
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))
|
||||
|
||||
mytoday = datetime.date.today().strftime("%d/%m/%Y")
|
||||
my_local_mydata = {'certification_send_date':str(mytoday)}
|
||||
|
||||
print(" ### str(diction['inscription_id']) = ",str(diction['inscription_id']) )
|
||||
## Mise à jour de la date d'envoi du certificat
|
||||
MYSY_GV.dbname['inscription'].find_one_and_update({'_id':ObjectId(str(diction['inscription_id']))},
|
||||
{"$set":my_local_mydata},
|
||||
return_document=ReturnDocument.AFTER,)
|
||||
|
||||
|
||||
return True, " Email bien envoyé"
|
||||
|
||||
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 l'attestation par email "
|
||||
|
|
44
main.py
44
main.py
|
@ -2174,10 +2174,8 @@ def PrintAttendeeDetail_perSession(token, session_id, attendee_email):
|
|||
payload['token'] = str(token)
|
||||
payload['session_id'] = str(session_id)
|
||||
payload['attendee_email'] = str(attendee_email)
|
||||
|
||||
print(" ### PrintAttendeeDetail_perSession : payload = ",str(payload))
|
||||
|
||||
|
||||
localStatus, response= inscription.PrintAttendeeDetail_perSession(payload)
|
||||
if(localStatus ):
|
||||
return response
|
||||
|
@ -2208,7 +2206,49 @@ def Evaluation_Class():
|
|||
localStatus, message= inscription.Evaluation_Class(payload)
|
||||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
"""
|
||||
API Qui declenche l'envoi de l'email d'evaluation d'une formation
|
||||
"""
|
||||
@app.route('/myclass/api/SendTrainingEvaluationEmail/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def SendTrainingEvaluationEmail():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### SendTrainingEvaluationEmail : payload = ",payload)
|
||||
localStatus, message= inscription.SendTrainingEvaluationEmail(payload)
|
||||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
"""
|
||||
API Qui declenche l'envoi de l'attestation de formation par email
|
||||
"""
|
||||
@app.route('/myclass/api/SendAttendeeCertification/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def SendAttendeeCertification():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### SendAttendeeCertification : payload = ",payload)
|
||||
localStatus, message= inscription.SendAttendeeCertification(payload)
|
||||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
"""
|
||||
API qui imprime l'attestation de formation d'un participant
|
||||
"""
|
||||
@app.route('/myclass/api/PrintAttendeeCertification/<token>/<session_id>/<attendee_email>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def PrintAttendeeCertification(token, session_id, attendee_email):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
payload = {}
|
||||
payload['token'] = str(token)
|
||||
payload['session_id'] = str(session_id)
|
||||
payload['attendee_email'] = str(attendee_email)
|
||||
print(" ### PrintAttendeeCertification : payload = ", str(payload))
|
||||
|
||||
localStatus, response = inscription.PrintAttendeeCertification(payload)
|
||||
if (localStatus):
|
||||
return response
|
||||
else:
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
|
|
|
@ -2517,6 +2517,8 @@ def GetAttendeeDetail_perSession(diction):
|
|||
my_retrun_dict['date_au'] = local_Insc_retval['date_au']
|
||||
my_retrun_dict['ville'] = local_Insc_retval['ville']
|
||||
my_retrun_dict['code_postal'] = local_Insc_retval['code_postal']
|
||||
my_retrun_dict['certification_send_date'] = str(local_Insc_retval['certification_send_date'])[0:10]
|
||||
|
||||
|
||||
my_retrun_dict['adresse'] = local_Insc_retval['adresse']
|
||||
my_retrun_dict['nom'] = local_Insc_retval['nom']
|
||||
|
|
Loading…
Reference in New Issue