15/12/2023 - 18h
parent
ba57632866
commit
2ebf5312f4
|
@ -1,8 +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="14/12/2023 - 21h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="14/12/2023 - 22h">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Collection_Historique.py" beforeDir="false" afterPath="$PROJECT_DIR$/Collection_Historique.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_document_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_document_mgt.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -73,13 +78,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00124" summary="04/10/2023 - 21h40">
|
||||
<created>1696447101805</created>
|
||||
<option name="number" value="00124" />
|
||||
<option name="presentableId" value="LOCAL-00124" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1696447101806</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00125" summary="06/10/2023 - 21h40">
|
||||
<created>1696628469996</created>
|
||||
<option name="number" value="00125" />
|
||||
|
@ -416,7 +414,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1702583972425</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="173" />
|
||||
<task id="LOCAL-00173" summary="14/12/2023 - 22h">
|
||||
<created>1702588091723</created>
|
||||
<option name="number" value="00173" />
|
||||
<option name="presentableId" value="LOCAL-00173" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1702588091723</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="174" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -431,7 +436,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="14/11/2023 - 20h" />
|
||||
<MESSAGE value="15/11/2023 - 12h" />
|
||||
<MESSAGE value="15/11/2023 - 17h" />
|
||||
<MESSAGE value="15/11/2023 - 21h" />
|
||||
|
@ -456,6 +460,7 @@
|
|||
<MESSAGE value="14/12/2023 - 08h30" />
|
||||
<MESSAGE value="14/12/2023 - 16h16" />
|
||||
<MESSAGE value="14/12/2023 - 21h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="14/12/2023 - 21h" />
|
||||
<MESSAGE value="14/12/2023 - 22h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="14/12/2023 - 22h" />
|
||||
</component>
|
||||
</project>
|
|
@ -36,6 +36,17 @@ from email.mime.base import MIMEBase
|
|||
from email import encoders
|
||||
|
||||
|
||||
|
||||
"""
|
||||
/!\ : 15/12/2024 : A faire
|
||||
Ajouter le log vers celui qui a éffectué l'action.
|
||||
Ceci pour tracer les action d'une pesonne comme la suppression d'un objet.
|
||||
|
||||
Idée :
|
||||
Si suppresion : Mettre l'_id, nom, prenom (ou numero de commande, code) de l'objet supprimé.
|
||||
"""
|
||||
|
||||
|
||||
"""
|
||||
Pour un ajout, sont pris en compte :
|
||||
- related_collection ==> Collection concercée
|
||||
|
|
|
@ -35,6 +35,8 @@ import email_mgt as email_mgt
|
|||
import lms_chamilo.mysy_lms as mys_lms
|
||||
from email.message import EmailMessage
|
||||
import attached_file_mgt as attached_file_mgt
|
||||
from zipfile import ZipFile
|
||||
|
||||
"""
|
||||
Enregistrement d'un stagiaire
|
||||
|
||||
|
@ -6141,10 +6143,15 @@ adresse email de test, on accepte en non obligatoire
|
|||
- email_test
|
||||
- email_production
|
||||
|
||||
Question : Comment traiter les emails envoyées dans la liste des pièces echangés
|
||||
/!\ : Regle de gestion :
|
||||
|
||||
Si le modele de courrier est 'edit_by_client', alors le mail est envoyé au contact de communication
|
||||
du client rattaché au stagiaire.
|
||||
|
||||
Si le stagiaire n'a pas de client rattacher, le système retourne un message d'erreur.
|
||||
|
||||
"""
|
||||
def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
||||
def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
||||
try:
|
||||
field_list_obligatoire = [ 'token', 'inscription_id', 'courrier_template_id', 'email_test', 'email_production' ]
|
||||
|
||||
|
@ -6288,8 +6295,6 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
#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)
|
||||
|
||||
|
@ -6310,6 +6315,22 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
|
||||
|
||||
# Verifier si le modele de courrier est 'edit_by_client', au quel cas on verifie que l'appressant est bien lié à un client
|
||||
if ("edit_by_client" in courrier_template_data.keys() and str(courrier_template_data['edit_by_client']) == "1"):
|
||||
stagiaire_client_id = ""
|
||||
if( "client_rattachement_id" in inscription_data.keys() ):
|
||||
stagiaire_client_id = str(inscription_data['client_rattachement_id'])
|
||||
|
||||
if( str(stagiaire_client_id).strip() == "" ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " Impossible d'envoyer un document édité par client à un stagiaire qui n'est pas rattaché à un client. L'email de l'apprenant est "+str(inscription_data['email'])+" ")
|
||||
return False, " Impossible d'envoyer un document édité par client à un stagiaire qui n'est pas rattaché à un client. L'email de l'apprenant est "+str(inscription_data['email'])+" "
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
tab_participant = []
|
||||
tab_participant.append(inscription_data['_id'])
|
||||
|
||||
|
@ -6344,28 +6365,81 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
|
||||
convention_dictionnary_data = local_retval
|
||||
|
||||
|
||||
## Creation du PDF
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data,
|
||||
}
|
||||
|
||||
## Creation du PDF
|
||||
|
||||
contenu_doc_Template = jinja2.Template(str(courrier_template_data['contenu_doc']))
|
||||
# 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"])
|
||||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||||
|
||||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||||
|
||||
orig_file_name = "Convention_" + str(my_partner['recid']) + "_" + 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)
|
||||
|
||||
|
||||
html_mime = MIMEText(sourceHtml, 'html')
|
||||
## 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")
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
"""
|
||||
Recuperation des parametre SMTP du partner si le client a decidé d'utiliser son propre smpt
|
||||
"""
|
||||
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']),
|
||||
|
@ -6452,8 +6526,8 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
print(" Email envoyé " + str(val))
|
||||
|
||||
"""
|
||||
# Ajout de l'evenement dans l'historique
|
||||
"""
|
||||
# Ajout de l'evenement dans l'historique
|
||||
"""
|
||||
|
||||
# L'action n'est loggué pour les envois reels (en prod)
|
||||
if( send_in_production == 1):
|
||||
|
@ -6582,6 +6656,43 @@ def Sent_Convention_Stagiaire_By_Email_mass(tab_files, Folder, diction):
|
|||
return False, " Impossible d'envoyer la convention par email "
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Creation d'un fichie zip de pdf
|
||||
"""
|
||||
|
||||
def Download_zip_PDF():
|
||||
try:
|
||||
|
||||
files = ['./temp_direct/pdf1.pdf', './temp_direct/pdf3.pdf', './temp_direct/pdf3.pdf']
|
||||
|
||||
# Create a ZipFile Object
|
||||
with ZipFile('./temp_direct/mysy.zip', 'w') as zip_object:
|
||||
# Adding files that need to be zipped
|
||||
zip_object.write('./temp_direct/pdf1.pdf')
|
||||
zip_object.write('./temp_direct/pdf3.pdf')
|
||||
zip_object.write('./temp_direct/pdf3.pdf')
|
||||
|
||||
# Check to see if the zip file is created
|
||||
if os.path.exists('./temp_direct/mysy.zip'):
|
||||
print("ZIP file created")
|
||||
else:
|
||||
print("ZIP file not created")
|
||||
|
||||
if os.path.exists("./temp_direct/mysy.zip"):
|
||||
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
return True, send_file("./temp_direct/mysy.zip", as_attachment=True)
|
||||
|
||||
return False, " Impossible de générer le fichier PDF (2) "
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de générer le fichier PDF (2) "
|
||||
|
||||
"""
|
||||
Impression de la convocation en mode PDF
|
||||
"""
|
||||
|
|
2361
Log/log_file.log
2361
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -4,12 +4,17 @@ Ce fichier gere les sessions de formation
|
|||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
|
||||
import jinja2
|
||||
import pymongo
|
||||
from flask import send_file
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, date
|
||||
|
||||
from xhtml2pdf import pisa
|
||||
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
|
@ -23,7 +28,7 @@ import GlobalVariable as MYSY_GV
|
|||
from datetime import timedelta
|
||||
from datetime import timedelta
|
||||
import Inscription_mgt as Inscription_mgt
|
||||
|
||||
from zipfile import ZipFile
|
||||
|
||||
"""
|
||||
Fonction de creation et mise à jour d'une session de formation.
|
||||
|
@ -3994,11 +3999,14 @@ def Prepare_and_Send_Convention_From_Session_By_Email(tab_files, Folder, diction
|
|||
"""
|
||||
Cette fonction permet de telecharger PDF toutes les conventions d'une session.
|
||||
Depuis la session, l'utilisateur choisi le modele PDF et
|
||||
telecharge les convention d'entreprise et les conventions individuelle
|
||||
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_Convention_From_Session_By_PDF(tab_files, Folder, diction):
|
||||
def Prepare_and_Send_Convention_From_Session_By_PDF(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'email_test', 'email_production']
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -4028,6 +4036,8 @@ def Prepare_and_Send_Convention_From_Session_By_PDF(tab_files, Folder, diction):
|
|||
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 = []
|
||||
|
||||
# Verifier qu'il ya bien des inscriptions valides dans la session pour le client
|
||||
liste_client_rattachement_id = MYSY_GV.dbname['inscription'].distinct("client_rattachement_id",
|
||||
|
@ -4039,86 +4049,330 @@ def Prepare_and_Send_Convention_From_Session_By_PDF(tab_files, Folder, diction):
|
|||
}
|
||||
)
|
||||
|
||||
|
||||
print(" ### la liste des liste_client_rattachement_id = ", liste_client_rattachement_id)
|
||||
|
||||
for val in liste_client_rattachement_id:
|
||||
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['client_id'] = str(val)
|
||||
|
||||
print(" #### Traitemnt de local_diction = ", local_diction)
|
||||
local_status, local_full_file_name = Create_Convention_By_Client_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))
|
||||
|
||||
|
||||
|
||||
# Recuperer inscriptions indépenantes, donc pas liée à un client
|
||||
liste_inscription_no_client = MYSY_GV.dbname['inscription'].find( {'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
"client_rattachement_id":''
|
||||
}
|
||||
}, {'_id':1}
|
||||
)
|
||||
|
||||
print(" ### la liste des liste_inscription_no_client = ", str(liste_inscription_no_client))
|
||||
for val in liste_inscription_no_client:
|
||||
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)
|
||||
|
||||
|
||||
for single_client in liste_client_rattachement_id :
|
||||
print(" Traintement du client_id = ", single_client)
|
||||
#field_list_obligatoire = ['token', 'courrier_template_id', 'email_test', 'email_production', 'partner_client_id', 'session_id']
|
||||
new_diction_client = {}
|
||||
new_diction_client['partner_client_id'] = single_client
|
||||
new_diction_client['token'] = diction['token']
|
||||
new_diction_client['courrier_template_id'] = diction['courrier_template_id']
|
||||
new_diction_client['email_test'] = diction['email_test']
|
||||
new_diction_client['email_production'] = diction['email_production']
|
||||
new_diction_client['session_id'] = diction['session_id']
|
||||
|
||||
print(" ##### new_diction_client = ", new_diction_client)
|
||||
local_status, local_retval = Inscription_mgt.Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files, Folder, new_diction_client)
|
||||
|
||||
print(" #### Traitemnt de local_diction = ", local_diction)
|
||||
local_status, local_full_file_name = Create_Convention_By_Client_PDF(local_diction)
|
||||
if( local_status is False):
|
||||
mycommon.myprint(" WARNING : impossible d'envoyer la convention au client : "+str( single_client))
|
||||
return local_status, local_full_file_name
|
||||
else:
|
||||
list_file_name_to_zip.append(str(local_full_file_name))
|
||||
|
||||
|
||||
# Envoie des convention pour les inscrits sans client_id
|
||||
for single_inscrit_no_client in liste_inscription_no_client :
|
||||
print(" ### traitement de l'inscrit : ",single_inscrit_no_client )
|
||||
#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_no_client['_id'])
|
||||
new_diction_no_client['courrier_template_id'] = diction['courrier_template_id']
|
||||
# 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 = "List_Convention_session_"+str(diction['session_id'])+"_"+str(str)+".pdf"
|
||||
|
||||
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 = Inscription_mgt.Sent_Convention_Stagiaire_By_Email(tab_files, Folder, new_diction_no_client)
|
||||
|
||||
if (local_status is False):
|
||||
mycommon.myprint(" WARNING impossible d'envoyer la convention a l'apprenant : " + str(single_inscrit_no_client['_id']) )
|
||||
|
||||
# Traitement de l'eventuel fichier joint
|
||||
tab_files_to_attache_to_mail = []
|
||||
with ZipFile('zip_file_name', 'w') as zip_object:
|
||||
for pdf_files in list_file_name_to_zip :
|
||||
zip_object.write(str(pdf_files))
|
||||
|
||||
|
||||
if os.path.exists("./temp_direct/mysy.zip"):
|
||||
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
return True, send_file(zip_file_name, as_attachment=True)
|
||||
|
||||
return False, " Impossible de générer les conventions par pdf PDF (1) "
|
||||
|
||||
|
||||
return True, " Les conventions 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 "
|
||||
return False, " Impossible de générer les conventions par pdf PDF "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction envoie les conventions par client
|
||||
Cette fonction créer un PDF par client et retounr l'url complet du fichier pdf
|
||||
pour les client (convention de type client)
|
||||
"""
|
||||
|
||||
def Send_Convention_From_Session_By_Email(tab_files, Folder, diction):
|
||||
def Create_Convention_By_Client_PDF(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_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
|
||||
|
||||
|
||||
return True, " La convention a été correctement envoyée par email"
|
||||
# 1 - Verifier que le modele de courrier est bien editable par client
|
||||
template_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'])})
|
||||
|
||||
if( template_courrier_data is None or "edit_by_client" not in template_courrier_data.keys() or 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 client ")
|
||||
return False, " Le modèle de courrier n'est pas éditable par client "
|
||||
|
||||
# Verifier que le client est valide
|
||||
client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(diction['client_id'])), 'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if (client_data is None ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant du client est invalide ")
|
||||
return False, " L'identifiant du client est invalide "
|
||||
|
||||
tab_client = []
|
||||
tab_client.append(client_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'] = []
|
||||
new_diction['list_session_id'] = tab_session
|
||||
new_diction['list_class_id'] = tab_class
|
||||
new_diction['list_client_id'] = tab_client
|
||||
|
||||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||||
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
convention_dictionnary_data = local_retval
|
||||
|
||||
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 = "Convention_" + 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, template_courrier_data
|
||||
|
||||
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 le convention par email "
|
||||
return False, " Impossible de créer le fichier pdf de convention client "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction envoie les convention à des stagiaires sans rattachement a des clients
|
||||
"""
|
||||
Cette fonction créer un PDF par client et retounr l'url complet du fichier pdf pour les
|
||||
personnes sans rattachement client (convention indivisuelle)
|
||||
"""
|
||||
def Create_Convention_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',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( template_courrier_data is None or "edit_by_client" not in template_courrier_data.keys() or 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
|
||||
statgiaire_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(diction['inscription_id'])), 'status':'1','locked':'0',
|
||||
'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 = "Convention_" + 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, template_courrier_data
|
||||
|
||||
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 convention par stagiaire "
|
||||
|
||||
|
|
42
main.py
42
main.py
|
@ -2146,6 +2146,28 @@ def Prepare_and_Send_Convention_From_Session_By_Email():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API : pour préprer et générer un zip de fichier PDF pour les convention en partant d'une session
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Convention_From_Session_By_PDF/<token>/<session_id>/<courrier_template_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Convention_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(" ### GerneratePDFEmargementList : payload = ",str(payload))
|
||||
|
||||
localStatus, response= SF.Prepare_and_Send_Convention_From_Session_By_PDF(payload)
|
||||
if(localStatus ):
|
||||
return response
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API de generation de liste PDF des liste d'emargement
|
||||
|
@ -4184,6 +4206,26 @@ def Download_Convention_Stagiaire_PDF(token, inscription_id, courrier_template_i
|
|||
else:
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
Test teclechargement d'un zip
|
||||
"""
|
||||
@app.route('/myclass/api/Download_zip_PDF/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Download_zip_PDF():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary(request.form.to_dict())
|
||||
|
||||
|
||||
print(" ### Download_zip_PDF payload = ",payload)
|
||||
|
||||
status, retval = inscription.Download_zip_PDF()
|
||||
if (status):
|
||||
return retval
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
API qui permet de telecharger la convention en mode PDF en partant du client (donc liste partipant dans le fichier)
|
||||
"""
|
||||
|
|
|
@ -39,7 +39,7 @@ def Add_Partner_Document(diction):
|
|||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', "nom", "ref_interne", "type_doc", "cible", "sujet",'contenu_doc', 'duplicate',
|
||||
'joint_pdf', 'default_version', 'corps_mail']
|
||||
'joint_pdf', 'default_version', 'corps_mail', 'edit_by_client']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -170,16 +170,25 @@ def Add_Partner_Document(diction):
|
|||
joint_pdf = diction['joint_pdf']
|
||||
if (str(joint_pdf) not in ['0', '1']):
|
||||
joint_pdf = '0'
|
||||
|
||||
data['joint_pdf'] = joint_pdf
|
||||
|
||||
edit_by_client = "0"
|
||||
if ("edit_by_client" in diction.keys()):
|
||||
if diction['edit_by_client']:
|
||||
edit_by_client = diction['edit_by_client']
|
||||
if (str(edit_by_client) not in ['0', '1']):
|
||||
edit_by_client = '0'
|
||||
|
||||
data['edit_by_client'] = edit_by_client
|
||||
|
||||
|
||||
|
||||
default_version = "0"
|
||||
if ("default_version" in diction.keys()):
|
||||
if diction['default_version']:
|
||||
default_version = diction['default_version']
|
||||
if (str(default_version) not in ['0', '1']):
|
||||
default_version = '0'
|
||||
|
||||
data['default_version'] = default_version
|
||||
|
||||
corps_mail = ""
|
||||
|
@ -214,7 +223,7 @@ def Add_Partner_Document(diction):
|
|||
- type_doc
|
||||
|
||||
"""
|
||||
if( str(diction['default_version']) == "1"):
|
||||
if( "default_version" in diction.keys() and str(diction['default_version']) == "1"):
|
||||
MYSY_GV.dbname['courrier_template'].update_many({'ref_interne':str(ref_interne),
|
||||
'valide':'1',
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
|
@ -252,7 +261,7 @@ def Update_Partner_Document(diction):
|
|||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', "nom", "ref_interne", "type_doc", "cible", "sujet",'contenu_doc', '_id',
|
||||
'joint_pdf', 'default_version', 'corps_mail']
|
||||
'joint_pdf', 'default_version', 'corps_mail', 'edit_by_client']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -386,9 +395,6 @@ def Update_Partner_Document(diction):
|
|||
data_update['contenu_doc'] = diction['contenu_doc']
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ----
|
||||
joint_pdf = "0"
|
||||
if ("joint_pdf" in diction.keys()):
|
||||
|
@ -396,16 +402,23 @@ def Update_Partner_Document(diction):
|
|||
joint_pdf = diction['joint_pdf']
|
||||
if (str(joint_pdf) not in ['0', '1']):
|
||||
joint_pdf = '0'
|
||||
|
||||
data_update['joint_pdf'] = joint_pdf
|
||||
|
||||
edit_by_client = "0"
|
||||
if ("edit_by_client" in diction.keys()):
|
||||
if diction['edit_by_client']:
|
||||
edit_by_client = diction['edit_by_client']
|
||||
if (str(edit_by_client) not in ['0', '1']):
|
||||
edit_by_client = '0'
|
||||
data_update['edit_by_client'] = edit_by_client
|
||||
|
||||
|
||||
default_version = "0"
|
||||
if ("default_version" in diction.keys()):
|
||||
if diction['default_version']:
|
||||
default_version = diction['default_version']
|
||||
if (str(default_version) not in ['0', '1']):
|
||||
default_version = '0'
|
||||
|
||||
data_update['default_version'] = default_version
|
||||
|
||||
corps_mail = ""
|
||||
|
@ -433,7 +446,7 @@ def Update_Partner_Document(diction):
|
|||
- type_doc
|
||||
|
||||
"""
|
||||
if (str(diction['default_version']) == "1"):
|
||||
if ("default_version" in diction.keys() and str(diction['default_version']) == "1"):
|
||||
MYSY_GV.dbname['courrier_template'].update_many({'ref_interne': str(ref_interne),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
|
|
Loading…
Reference in New Issue