From 95381744bcc453f6f461290486d9be8ece8db5b2 Mon Sep 17 00:00:00 2001 From: cherif Date: Wed, 26 Oct 2022 18:12:57 +0200 Subject: [PATCH] 26/10/22 - 18h --- GlobalVariable.py | 8 +- Inscription_mgt.py | 79 +++++++++++++++++- Template/invoice.html | 118 +++++++++++++++++++++++++++ Template/tpl_emargement.html | 76 +++++++++++++++++ data_indexees_article_avis.csv | 2 + ela_output_article_file_pandas_2.txt | 2 + email_inscription_mgt.py | 89 ++++++++++++++++++++ main.py | 18 ++++ 8 files changed, 389 insertions(+), 3 deletions(-) create mode 100644 Template/invoice.html create mode 100644 Template/tpl_emargement.html create mode 100644 data_indexees_article_avis.csv create mode 100644 ela_output_article_file_pandas_2.txt create mode 100644 email_inscription_mgt.py diff --git a/GlobalVariable.py b/GlobalVariable.py index 87e63c9..58061a2 100644 --- a/GlobalVariable.py +++ b/GlobalVariable.py @@ -193,4 +193,10 @@ LIMIT_ASSOCIATED_TRAINING = 3 """ Valeur MAX du display ranking accordé aux compte de type demo """ -DEMO_RANKING_VALUE = "50" \ No newline at end of file +DEMO_RANKING_VALUE = "50" + + +""" +Sendinblu compte support +""" +SENDINBLUE_API_KEY_SUPPORT = "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" \ No newline at end of file diff --git a/Inscription_mgt.py b/Inscription_mgt.py index ba35165..395667a 100644 --- a/Inscription_mgt.py +++ b/Inscription_mgt.py @@ -18,6 +18,7 @@ import GlobalVariable as MYSY_GV from math import isnan import GlobalVariable as MYSY_GV from datetime import timedelta +import email_inscription_mgt as email_session """ @@ -213,18 +214,22 @@ def UpdateStagiairetoClass(diction): mydata = {} + user_nom = "" if ("nom" in diction.keys()): if diction['nom']: mydata['nom'] = diction['nom'] + user_nom = diction['nom'] if ("price" in diction.keys()): if diction['price']: mydata['price'] = diction['price'] + user_prenom = "" if ("prenom" in diction.keys()): if diction['prenom']: mydata['prenom'] = diction['prenom'] + user_prenom = diction['prenom'] if ("telephone" in diction.keys()): if diction['telephone']: @@ -257,8 +262,54 @@ def UpdateStagiairetoClass(diction): ) if (ret_val2 and ret_val2['_id']): - mycommon.myprint(" Les données du stagiaire ont été correctement mise à jour") - return True, "Les données du stagiaire ont été correctement mise à jour" + + """ + Si le status == 1; alors il s'agit d'une validation d'une inscription. + Du coup, il faut envoyer le mail de confirmation de l'inscription: + 1 - recuperation des infos de la session + 1 BIS - recuperation du title + 2 - Envoie de l'email + """ + email_data = {} + email_data['nom'] = user_nom + email_data['prenom'] = user_prenom + email_data['email'] = myemail + + # ici recup du titre + for local_tmp_myclass in MYSY_GV.dbname['myclass'].find( + {'internal_url': str(myinternal_url)}): + + local_title = "" + if ("title" in local_tmp_myclass.keys() and local_tmp_myclass['title']): + local_title = local_tmp_myclass['title'] + email_data['title'] = local_title + + # ici recup des infos de la session + local_query = {'formation_session_id':str(mysession_id)} + print("### local_query = "+str(local_query)) + + for local_tmp_session in MYSY_GV.dbname['session_formation'].find(local_query): + local_date_du = "" + if ("date_debut" in local_tmp_session.keys() and local_tmp_session['date_debut']): + local_date_du = local_tmp_session['date_debut'] + email_data['date_du'] = local_date_du + + local_date_au = "" + if ("date_fin" in local_tmp_session.keys() and local_tmp_session['date_fin']): + local_date_au = local_tmp_session['date_fin'] + email_data['date_au'] = local_date_au + + adresse = "" + if ("adresse" in local_tmp_session.keys() and local_tmp_session['adresse']): + local_adresse = local_tmp_session['adresse'] + email_data['adresse'] = local_adresse + + + local_status, local_message = email_session.incription_training_confirmation_mail(email_data) + + + mycommon.myprint(" Les données du stagiaire ont été correctement mise à jour") + return True, "Les données du stagiaire ont été correctement mise à jour" else: mycommon.myprint(" Impossible de mettre à jour les données du stagiaire 1") return False, "Impossible de mettre à jour les données du stagiaire " @@ -387,3 +438,27 @@ def GetAllClassStagiaire(diction): return False, "Impossible de recuperer la liste des stagiaires de la formation" +""" +Cette fonction envoie l'email de confirmation d'une inscription a une formation. + +Ceci est mis en "mode function" pour permettre aux utilisateur de renvoyer +autant de fois que soihaité la confirmation d'inscription +""" +def SendInscriptionConfirmation(diction): + try: + """ + Verification de la liste des champs obligatoires + """ + field_list_obligatoire = ['token', 'email', 'class_internal_url', 'session_id'] + for val in field_list_obligatoire: + if val not in diction: + mycommon.myprint( + str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ") + return False, "Impossible d'envoyer la confirmation d'inscription" + + return True, "La confirmation d'inscription a bien ete envoyée" + + except Exception as e: + exc_type, exc_obj, exc_tb = sys.exc_info() + mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) + return False, "Impossible d'envoyer la confirmation d'inscription" diff --git a/Template/invoice.html b/Template/invoice.html new file mode 100644 index 0000000..ef98f8a --- /dev/null +++ b/Template/invoice.html @@ -0,0 +1,118 @@ + + + +
+ Mysy Training Logo +
+
+
+
+ +
+
+ {{json_data.client_name}}
+{{json_data.client_address}}
+{{json_data.client_zip_ville}}
+{{json_data.client_pays}}
+ +
+ + +
+ +Facture n° {{json_data.invoice_id}} + + +
+
+ + + + + + + + + +
Date de facture: {{json_data.invoice_date}} Date échéance : {{json_data.due_date}}
+ +
Origine : {{json_data.orign_order}} +
+ +
 
+
+ + + + + + + + + + + + + + + + + + + +
DescriptionQuantitéPrix unitaireMontant
{{json_data.packs}}{{json_data.qty}}{{json_data.unit_price}}{{json_data.montant}}
{{json_data.packs1}}{{json_data.qty1}}{{json_data.unit_price1}}{{json_data.montant1}}
+
+ +
 
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
    Montant HT: {{json_data.total_ht}}
    TVA 20% : {{json_data.tva}}
    Montant TTC : {{json_data.total_ttc}}
+ + +
+
 
+
 
+
 
+ + + +
+ +
+
+ + + \ No newline at end of file diff --git a/Template/tpl_emargement.html b/Template/tpl_emargement.html new file mode 100644 index 0000000..99baac3 --- /dev/null +++ b/Template/tpl_emargement.html @@ -0,0 +1,76 @@ + + + +
+ Mysy Training Logo +
+
+
+
+ +
+ + +
+ +Formation : {{json_data.title}}
+Date : {{json_data.date}} + + +
+ + +
+ + + + + + + + + + + {% if users %} + {% for user in users %} + + + + + + + {% if user.matin %} + + {% else %} + + {% endif %} + + {% if user.apresmidi %} + + {% else %} + + {% endif %} + + + + {% endfor %} + {% endif %} +
DateNomPrénomMatinApres MidiSignature
{{user.date}}{{user.nom}}{{user.prenom}} X   X    
+
+ +
+ + +
+ +
 
+ + + +
+ +
+
+ + + \ No newline at end of file diff --git a/data_indexees_article_avis.csv b/data_indexees_article_avis.csv new file mode 100644 index 0000000..463d1e6 --- /dev/null +++ b/data_indexees_article_avis.csv @@ -0,0 +1,2 @@ +,index,mots,occurence,moyenne,id_article_avis,source_field +0,0,formation4,0,0.0,formation4,default diff --git a/ela_output_article_file_pandas_2.txt b/ela_output_article_file_pandas_2.txt new file mode 100644 index 0000000..19d3900 --- /dev/null +++ b/ela_output_article_file_pandas_2.txt @@ -0,0 +1,2 @@ + mots occurence moyenne id_article_avis source_field +0 formation4 0 0.0 formation4 default \ No newline at end of file diff --git a/email_inscription_mgt.py b/email_inscription_mgt.py new file mode 100644 index 0000000..36a6534 --- /dev/null +++ b/email_inscription_mgt.py @@ -0,0 +1,89 @@ +from __future__ import print_function +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText +from email.mime.base import MIMEBase +from email import encoders +import locale +import datetime +import inspect +import sys, os +import prj_common as mycommon +import GlobalVariable as MYSY_GV +from dateutil import tz +import pytz +import sib_api_v3_sdk +from sib_api_v3_sdk.rest import ApiException + +configuration = sib_api_v3_sdk.Configuration() +configuration.api_key['api-key'] = MYSY_GV.SENDINBLUE_API_KEY_SUPPORT + +api_instance = sib_api_v3_sdk.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration)) + +locale.setlocale(category=locale.LC_ALL, locale='fr_FR.utf8') + + + +smtp_address = 'smtp-relay.sendinblue.com' +port = 587 +sender = 'support@mysy-training.com' +receiver = ["cbalde3@mysy-training.com","billardman1@gmail.com"] + + +user = 'support@mysy-training.com' +password = 'Tut29488!+' + + +""" +Envoi de l'email de confirmation d'inscription à une formation +""" +def incription_training_confirmation_mail(diction): + try: + + print(" ### incription_training_confirmation_mail = "+str(diction)) + """ + Verification de la liste des champs obligatoires + """ + field_list_obligatoire = ['nom', 'prenom', 'email', 'date_du', 'date_au', 'adresse', 'title'] + 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 : Confirmation inscription formation' + msg['From'] = 'contact@mysy-training.com' + msg['To'] = str(diction['email']) + + to = [{"email": str(diction['email'])}] + bcc = [{"email": "contact@mysy-training.com"}] + + print(" ### Adresse = "+str(diction['adresse']) ) + send_smtp_email = sib_api_v3_sdk.SendSmtpEmail(template_id=1, 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'])}, + to=to, bcc=bcc ) + + api_response = api_instance.send_transac_email(send_smtp_email) + print(api_response) + + 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 notification " + diff --git a/main.py b/main.py index c00d398..02331e0 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,8 @@ import strype_payement as Stripe import Inscription_mgt as inscription import emargement as emargement import Session_Formation as SF +import email_mgt as emails +import email_inscription_mgt as emails_support app = Flask(__name__) @@ -1841,6 +1843,22 @@ def GerneratePDFEmargementList(token, session_id, internal_url): else: return False + + +""" +Envoie email d'inscription +""" +@app.route('/myclass/api/incription_training_confirmation_mail/', methods=['POST','GET']) +@crossdomain(origin='*') +def incription_training_confirmation_mail(): + # On recupere le corps (payload) de la requete + payload = request.form.to_dict() + print(" ### incription_training_confirmation_mail : payload = ",str(payload)) + localStatus, message= emails_support.incription_training_confirmation_mail() + return jsonify(status=localStatus, message=message ) + + + if __name__ == '__main__': print(" debut api") context = SSL.Context(SSL.SSLv23_METHOD)