29/01/24 - 21h30
parent
71ea27c918
commit
3f7c82584b
|
@ -8,6 +8,7 @@
|
|||
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/module_editique.py" beforeDir="false" afterPath="$PROJECT_DIR$/module_editique.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_document_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_document_mgt.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -77,13 +78,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00155" summary="22/11/2023 - 23h00">
|
||||
<created>1700691598342</created>
|
||||
<option name="number" value="00155" />
|
||||
<option name="presentableId" value="LOCAL-00155" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1700691598344</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00156" summary="23/11/23 - 13:30">
|
||||
<created>1700742130513</created>
|
||||
<option name="number" value="00156" />
|
||||
|
@ -420,7 +414,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1706302326450</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="204" />
|
||||
<task id="LOCAL-00204" summary="rrrf">
|
||||
<created>1706369454940</created>
|
||||
<option name="number" value="00204" />
|
||||
<option name="presentableId" value="LOCAL-00204" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1706369454943</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="205" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
|
|
@ -6808,6 +6808,115 @@ def Get_List_Conventions_Stagiaire_With_Filter(diction):
|
|||
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 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' = '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 ]}
|
||||
|
||||
print(" #### qry = ", qry)
|
||||
|
||||
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"
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperatin des convention SEULEMENT Individuelles
|
||||
"""
|
||||
|
|
3772
Log/log_file.log
3772
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -2,6 +2,7 @@
|
|||
Ce fichier gere les sessions de formation
|
||||
"""
|
||||
import ast
|
||||
import smtplib
|
||||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
|
||||
|
@ -17,6 +18,7 @@ from datetime import datetime, date
|
|||
from xhtml2pdf import pisa
|
||||
|
||||
import Session_Formation_Sequence
|
||||
import attached_file_mgt
|
||||
import module_editique
|
||||
import partner_client
|
||||
import prj_common as mycommon
|
||||
|
@ -33,6 +35,10 @@ from datetime import timedelta
|
|||
from datetime import timedelta
|
||||
import Inscription_mgt as Inscription_mgt
|
||||
from zipfile import ZipFile
|
||||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
|
||||
"""
|
||||
Fonction de creation et mise à jour d'une session de formation.
|
||||
|
@ -5448,3 +5454,804 @@ def Create_Convention_By_Stagiaire_PDF(diction):
|
|||
return False, " Impossible de créer le fichier pdf de convention par stagiaire "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de telecharger PDF toutes les conVOCAtion d'une session.
|
||||
Depuis la session, l'utilisateur choisi le modele PDF et
|
||||
telecharge les conventions d'entreprise et les conventions individuelles.
|
||||
|
||||
On créé un fichier zip qui sera téléchargé avec toutes les pièces jointes
|
||||
|
||||
"""
|
||||
def Prepare_and_Send_Convocation_From_Session_By_PDF(diction):
|
||||
try:
|
||||
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, " 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 "
|
||||
|
||||
# Stokage des nom de fichier à zipper
|
||||
list_file_name_to_zip = []
|
||||
|
||||
|
||||
|
||||
liste_inscription = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
}
|
||||
)
|
||||
|
||||
"""
|
||||
for val in liste_inscription_no_client:
|
||||
print(" ### la liste des liste_inscription_no_client = ", str(val))
|
||||
"""
|
||||
|
||||
|
||||
|
||||
# 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(diction['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"
|
||||
|
||||
|
||||
if (str(is_convention_by_client) == "0"):
|
||||
liste_participants = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
}
|
||||
)
|
||||
for val in liste_participants:
|
||||
local_diction = {}
|
||||
# field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_id']
|
||||
local_diction['token'] = diction['token']
|
||||
local_diction['session_id'] = diction['session_id']
|
||||
local_diction['courrier_template_id'] = diction['courrier_template_id']
|
||||
local_diction['inscription_id'] = str(val['_id'])
|
||||
|
||||
print(" #### Traitemnt de local_diction bb = ", local_diction)
|
||||
local_status, local_full_file_name = Create_Convocation_By_Stagiaire_PDF(local_diction)
|
||||
if( local_status is False):
|
||||
return local_status, local_full_file_name
|
||||
else:
|
||||
list_file_name_to_zip.append(str(local_full_file_name))
|
||||
|
||||
|
||||
# Create a ZipFile Object
|
||||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
||||
zip_file_name = str(MYSY_GV.TEMPORARY_DIRECTORY_V2)+"List_Convocation_session_"+str(diction['session_id'])+"_"+str(ts)+".zip"
|
||||
|
||||
with ZipFile(zip_file_name, 'w') as zip_object:
|
||||
for pdf_files in list_file_name_to_zip :
|
||||
#print(" ### fichier a zipper = ", pdf_files)
|
||||
zip_object.write(str(pdf_files))
|
||||
|
||||
|
||||
if os.path.exists(zip_file_name):
|
||||
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
|
||||
|
||||
"""
|
||||
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']))
|
||||
|
||||
return True, send_file(zip_file_name, as_attachment=True)
|
||||
|
||||
|
||||
return False, " Impossible de générer les conventions par pdf PDF (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 générer les conventions par pdf PDF "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction créer une convocation PDF par participant à une session de formation
|
||||
Peu importe le rattachement client ou pas.
|
||||
"""
|
||||
def Create_Convocation_By_Stagiaire_PDF(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', '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, " 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
|
||||
|
||||
|
||||
# 1 - Verifier que le modele de courrier est bien editable par individu
|
||||
template_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'ref_interne': 'CONVOCATION_STAGIAIRE',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( template_courrier_data is None or ("edit_by_client" in template_courrier_data.keys() and str(template_courrier_data['edit_by_client']) == "1" ) ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Le modèle de courrier n'est pas éditable par stagiaire. ")
|
||||
return False, " Le modèle de courrier n'est pas éditable par stagiaire "
|
||||
|
||||
# Verifier que le statgiaire est valide
|
||||
local_qry = {'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])}
|
||||
|
||||
statgiaire_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (statgiaire_data is None ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant du stagiaire est invalide ")
|
||||
return False, " L'identifiant du stagiaire est invalide "
|
||||
|
||||
tab_stagiaire = []
|
||||
tab_stagiaire.append(statgiaire_data['_id'])
|
||||
|
||||
|
||||
# Verifier que la session est valide
|
||||
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
||||
{'_id': ObjectId(str(diction['session_id'])), 'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (session_data is None):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de la session est invalide ")
|
||||
return False, " L'identifiant de la session est invalide "
|
||||
|
||||
tab_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_stagiaire
|
||||
new_diction['list_session_id'] = tab_session
|
||||
new_diction['list_class_id'] = tab_class
|
||||
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
|
||||
|
||||
convention_dictionnary_data = local_retval
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data,
|
||||
}
|
||||
|
||||
"""
|
||||
Creation du ficier PDF
|
||||
"""
|
||||
contenu_doc_Template = jinja2.Template(str(template_courrier_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']) + "_" + 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()
|
||||
|
||||
|
||||
return True, outputFilename
|
||||
|
||||
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 fichier pdf de convocation par stagiaire "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction prepare et envoi les conVocation a chaque
|
||||
participant à la session de formation
|
||||
"""
|
||||
def Prepare_and_Send_Convocation_From_Session_By_Email(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
field_list_obligatoire = ['token', 'session_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 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 "
|
||||
|
||||
|
||||
# Verifier qu'il ya bien des inscriptions valides dans la session pour le client
|
||||
liste_participants = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
print(" ### la liste des liste_participants = ", liste_participants)
|
||||
|
||||
|
||||
# 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)
|
||||
|
||||
print(" #### tab_saved_file_full_path = ", tab_saved_file_full_path)
|
||||
|
||||
# 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(diction['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"
|
||||
|
||||
|
||||
if (str(is_convention_by_client) == "0"):
|
||||
liste_inscription = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
}
|
||||
)
|
||||
|
||||
print(" ### LIST liste_inscription: ", liste_inscription)
|
||||
|
||||
|
||||
for single_inscrit in liste_inscription :
|
||||
print(" ### convocation traitement de l'inscrit : ",single_inscrit )
|
||||
#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(single_inscrit['_id'])
|
||||
new_diction_no_client['courrier_template_id'] = diction['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)
|
||||
local_status, local_retval = Sent_Convocation_Stagiaire_By_Email(tab_saved_file_full_path, Folder, new_diction_no_client)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" WARNING impossible d'envoyer la convocation a l'apprenant : " + str(single_inscrit['_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(my_partner, courrier_template_data,
|
||||
str(diction['session_id']))
|
||||
|
||||
|
||||
return True, " Les convocations 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 convocation 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_Convocation_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'])
|
||||
|
||||
# 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'] = []
|
||||
|
||||
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']) + "_" + 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'] = "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))
|
||||
|
||||
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 "
|
||||
|
|
65
main.py
65
main.py
|
@ -4374,6 +4374,22 @@ def Get_List_Conventions_Stagiaire_With_Filter():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API qui permet de recuperer la liste des conVOcations stagiaires avec des options
|
||||
comme :
|
||||
- ref_interne
|
||||
- nom
|
||||
- type_doc
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Convocations_Stagiaire_With_Filter/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_List_Convocations_Stagiaire_With_Filter():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_List_Convocations_Stagiaire_With_Filter payload = ",payload)
|
||||
status, retval = inscription.Get_List_Convocations_Stagiaire_With_Filter(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer seulement les conventions INDIVIDUELLES
|
||||
|
@ -7318,6 +7334,55 @@ def Action_Server_send_convention_entreprise_mail():
|
|||
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
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Convocation_From_Session_By_PDF/<token>/<session_id>/<courrier_template_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Convocation_From_Session_By_PDF(token, session_id, courrier_template_id):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
payload = {}
|
||||
payload['token'] = str(token)
|
||||
payload['session_id'] = str(session_id)
|
||||
payload['courrier_template_id'] = str(courrier_template_id)
|
||||
|
||||
print(" ### Prepare_and_Send_Convocation_From_Session_By_PDF : payload = ",str(payload))
|
||||
|
||||
localStatus, response= SF.Prepare_and_Send_Convocation_From_Session_By_PDF(payload)
|
||||
if(localStatus ):
|
||||
return response
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API : pour préprer et envoyer les convocations en partant d'une session
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Convocation_From_Session_By_Email/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Convocation_From_Session_By_Email():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Prepare_and_Send_Convocation_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_Convocation_From_Session_By_Email(tab_files, MYSY_GV.TEMPORARY_DIRECTORY_V2, payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
|
@ -220,7 +220,7 @@ def Get_Editable_Document_By_Partner_By_Collection(diction):
|
|||
{'$eq': ["$ref_interne", '$$courrier_template_type_document_ref_interne']},
|
||||
|
||||
{'$eq': ["$valide", "1"]},
|
||||
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
||||
{'$eq': ["$partner_owner_recid", 'default']}
|
||||
|
||||
]
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ def Get_Editable_Document_By_Partner_By_Collection(diction):
|
|||
|
||||
#print(" #### Get_Editable_Document_By_Partner_By_Collection pipe_qry_Get_Editable_Document_By_Partner = ", pipe_qry)
|
||||
json_formatted_str = json.dumps(pipe_qry, indent=2)
|
||||
print(" #### Get_Editable_Document_By_Partner_By_Collection pipe_qry_Get_Editable_Document_By_Partner = ", json_formatted_str)
|
||||
#print(" #### Get_Editable_Document_By_Partner_By_Collection pipe_qry_Get_Editable_Document_By_Partner = ", json_formatted_str)
|
||||
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['courrier_template_tracking'].aggregate(pipe_qry):
|
||||
|
@ -313,10 +313,41 @@ def Get_Editable_Document_By_Partner_By_Collection(diction):
|
|||
#print(" #### is_document_has_history_event qry = ", local_qry)
|
||||
|
||||
is_document_has_history_event = MYSY_GV.dbname['courrier_template_tracking_history'].count_documents(local_qry)
|
||||
local_related_collection = ""
|
||||
local_related_collection_id = ""
|
||||
local_related_collection_name = ""
|
||||
|
||||
if( is_document_has_history_event > 0 ):
|
||||
has_history_event = "1"
|
||||
for val in MYSY_GV.dbname['courrier_template_tracking_history'].find(local_qry):
|
||||
#print(" val 1 = ", val)
|
||||
|
||||
if( val and "courrier_template_id" in val.keys() and "related_collection_recid" in val.keys() ):
|
||||
local_courrier_template_id = val['courrier_template_id']
|
||||
courrier_template_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(local_courrier_template_id))},
|
||||
{'contenu_doc':'0'})
|
||||
|
||||
related_collection_data = MYSY_GV.dbname[related_collection].find_one({'_id':ObjectId(str(diction['related_collection_recid']))})
|
||||
#print(" #### SESSSION DATA = ", related_collection_data)
|
||||
|
||||
local_related_collection = "Session Formation"
|
||||
local_related_collection_id = str(val['related_collection_recid'])
|
||||
local_related_collection_name = str(related_collection_data['code_session'])
|
||||
|
||||
val['local_related_collection'] = local_related_collection
|
||||
val['local_related_collection_id'] = local_related_collection_id
|
||||
val['local_related_collection_name'] = local_related_collection_name
|
||||
|
||||
local_update_by_email = ""
|
||||
if( "update_by" in val.keys()):
|
||||
update_by_data = MYSY_GV.dbname['partnair_account'].find_one({'_id':ObjectId(val['update_by']),
|
||||
'recid':my_partner['recid']})
|
||||
if( "email" in update_by_data ):
|
||||
local_update_by_email = update_by_data['email']
|
||||
|
||||
val['local_update_by_email'] = local_update_by_email
|
||||
|
||||
#print(" ### VALLL = ", val)
|
||||
list_document_history_event.append(val)
|
||||
|
||||
#print(" #### is_document_has_history_event RESULT = ", is_document_has_history_event)
|
||||
|
@ -584,7 +615,7 @@ def Init_And_Update_courrier_template_tracking(diction):
|
|||
warning_message = ""
|
||||
cpt = 0
|
||||
for retval in MYSY_GV.dbname['courrier_template_type_document'].find({'tracked':'0', 'valide':'1', 'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])}):
|
||||
'partner_owner_recid':'default'}):
|
||||
|
||||
|
||||
tab_tacking_collection = []
|
||||
|
@ -603,7 +634,7 @@ def Init_And_Update_courrier_template_tracking(diction):
|
|||
new_data['locked'] = "0"
|
||||
|
||||
key_data = {}
|
||||
key_data['courrier_template_id'] = str(retval['_id'])
|
||||
key_data['courrier_template_type_document_id'] = str(retval['_id'])
|
||||
key_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
key_data['related_collection'] = str(collection)
|
||||
key_data['valide'] = "1"
|
||||
|
@ -623,7 +654,7 @@ def Init_And_Update_courrier_template_tracking(diction):
|
|||
|
||||
cpt = cpt + 1
|
||||
|
||||
|
||||
"""
|
||||
# Mise à jour du courrier_template pour mettre 'tracked':'1'
|
||||
update_data = {}
|
||||
update_data['date_update'] = datetime.now().strftime("%d/%m/%Y, %H:%M:%S")
|
||||
|
@ -631,7 +662,7 @@ def Init_And_Update_courrier_template_tracking(diction):
|
|||
update_data['tracked'] = "1"
|
||||
|
||||
MYSY_GV.dbname['courrier_template_type_document'].update_one({'_id':ObjectId(str(retval['_id']))}, {'$set':update_data})
|
||||
|
||||
"""
|
||||
|
||||
if( warning_message == "" ):
|
||||
return True, "Initialisation de la traçabilité de "+str(cpt)+" document(s) Ok "
|
||||
|
@ -669,15 +700,19 @@ def Editic_Log_History_Action(my_partner, courrier_template_data, related_collec
|
|||
|
||||
courrier_template_tracking_id = str(courrier_template_tracking_data['_id'])
|
||||
|
||||
print(" ### courrier_template_data = ", courrier_template_data)
|
||||
|
||||
history_data_to_log = {}
|
||||
history_data_to_log ['partner_owner_recid'] = str(my_partner['recid'])
|
||||
history_data_to_log['related_collection_recid'] = related_collection_recid
|
||||
history_data_to_log['courrier_template_tracking_id'] = courrier_template_tracking_id
|
||||
history_data_to_log['courrier_template_id'] = str(courrier_template_data['_id'])
|
||||
history_data_to_log['date_update'] = str(datetime.now())
|
||||
history_data_to_log['update_by'] = str(my_partner['_id'])
|
||||
history_data_to_log['valide'] = "1"
|
||||
history_data_to_log['locked'] = "0"
|
||||
|
||||
|
||||
print( "#### history_data_to_log = ", history_data_to_log)
|
||||
MYSY_GV.dbname['courrier_template_tracking_history'].insert_one(history_data_to_log)
|
||||
|
||||
|
@ -690,16 +725,3 @@ def Editic_Log_History_Action(my_partner, courrier_template_data, related_collec
|
|||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Au lieu de travailler sur : 'courrier_template' dans la reccherche des courriers
|
||||
je dois créer une nouvelle collection 'type_doc' qui contient les infos statiques de 'courrier_template' comment
|
||||
- setaction_server_to_run
|
||||
- setaction_server_type_doc
|
||||
- setaction_server_nom_doc
|
||||
- setaction_server_ref_interne_doc
|
||||
|
||||
Le problème avec 'courrier_template' est que j'ai les differentes version d'un doc. Donc au lieu d'afficher juste
|
||||
un doc pour les 'conventions entreprise mail', il va m'affichier toutes version, d'ou le bin's
|
||||
|
||||
"""
|
|
@ -205,6 +205,12 @@ def Add_Partner_Document(diction):
|
|||
|
||||
# ---
|
||||
|
||||
qry = {'ref_interne':str(ref_interne), 'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
'nom': str(nom),
|
||||
'type_doc':str(diction['type_doc'])}
|
||||
|
||||
print(" ### qry = ", qry)
|
||||
|
||||
# Verifier qu'il n'existe pas un document avec le meme code code interne
|
||||
exist_doc_count = MYSY_GV.dbname['courrier_template'].count_documents({'ref_interne':str(ref_interne), 'valide':'1',
|
||||
|
@ -905,11 +911,11 @@ def Get_List_Partner_Document_no_filter(diction):
|
|||
|
||||
find_qry = {'partner_owner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }
|
||||
|
||||
print(" ### materiel find_qry = ", find_qry)
|
||||
#print(" ### materiel find_qry = ", find_qry)
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
for retval in MYSY_GV.dbname['courrier_template'].find(find_qry):
|
||||
for retval in MYSY_GV.dbname['courrier_template'].find(find_qry).sort([("_id", pymongo.DESCENDING)]):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
|
Loading…
Reference in New Issue