04/04/24 - 19h30
parent
a22bac4a55
commit
1576282562
|
@ -1,11 +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="2/04/24 - 20h30">
|
||||
<change afterPath="$PROJECT_DIR$/formulaire_mgt.py" afterDir="false" />
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="03/04/24 - 21h30">
|
||||
<change afterPath="$PROJECT_DIR$/survey_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/E_Sign_Document.py" beforeDir="false" afterPath="$PROJECT_DIR$/E_Sign_Document.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.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$/formulaire_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/formulaire_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -76,13 +78,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00206" summary="ss">
|
||||
<created>1706645717009</created>
|
||||
<option name="number" value="00206" />
|
||||
<option name="presentableId" value="LOCAL-00206" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1706645717009</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00207" summary="31/01/2024 - 16h">
|
||||
<created>1706713340253</created>
|
||||
<option name="number" value="00207" />
|
||||
|
@ -419,7 +414,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1712082670298</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="255" />
|
||||
<task id="LOCAL-00255" summary="03/04/24 - 21h30">
|
||||
<created>1712174236031</created>
|
||||
<option name="number" value="00255" />
|
||||
<option name="presentableId" value="LOCAL-00255" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1712174236031</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="256" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -461,7 +463,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="26/02/2024 - 16h30" />
|
||||
<MESSAGE value="28/02/2024 - 21h30" />
|
||||
<MESSAGE value="29/02/2024 - 21h30" />
|
||||
<MESSAGE value="01/03/2024 - 23h30" />
|
||||
|
@ -486,6 +487,7 @@
|
|||
<MESSAGE value="01/04/24 - 23h30" />
|
||||
<MESSAGE value="01/04/24 - 23h50" />
|
||||
<MESSAGE value="2/04/24 - 20h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="2/04/24 - 20h30" />
|
||||
<MESSAGE value="03/04/24 - 21h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="03/04/24 - 21h30" />
|
||||
</component>
|
||||
</project>
|
|
@ -1124,8 +1124,8 @@ def Sent_E_Document_Signature_Request(diction):
|
|||
local_partner_owner_recid = e_document_data['partner_owner_recid']
|
||||
|
||||
"""
|
||||
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(e_document_data['partner_owner_recid']),
|
||||
|
|
|
@ -683,4 +683,14 @@ Formulaire : Type de question :
|
|||
- note
|
||||
- entier
|
||||
"""
|
||||
FORM_QUESTION_TYPE = ['qcm', 'text', 'note', 'entier']
|
||||
FORM_QUESTION_TYPE = ['qcm', 'text', 'note', 'entier', 'bool']
|
||||
|
||||
|
||||
"""
|
||||
Survey Statut :
|
||||
Une enquete a les statuts suivants :
|
||||
0 - envoyé
|
||||
1 - repondu
|
||||
-1 - annulé
|
||||
"""
|
||||
SURVEY_STATUS = ['-1', '0', '1']
|
1968
Log/log_file.log
1968
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -520,7 +520,7 @@ def Delete_Formulaire(diction):
|
|||
|
||||
|
||||
"""
|
||||
Recuperer la listes des formulaire d'un partenaire
|
||||
Recuperer la listes des formulaire d'un partenaire, sans filter
|
||||
"""
|
||||
def Get_List_Formulaire(diction):
|
||||
try:
|
||||
|
@ -582,6 +582,88 @@ def Get_List_Formulaire(diction):
|
|||
return False, " Impossible de récupérer la liste des formulaires "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperer la listes des formulaire d'un partenaire, AVEC filter
|
||||
"""
|
||||
def Get_List_Formulaire_with_filter(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'code', 'nom', 'description' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token',]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
filt_code = {}
|
||||
if ("code" in diction.keys()):
|
||||
filt_code = {'code': {'$regex': str(diction['code']), "$options": "i"}}
|
||||
|
||||
filt_nom = {}
|
||||
if ("nom" in diction.keys()):
|
||||
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
||||
|
||||
filt_description = {}
|
||||
if ("description" in diction.keys()):
|
||||
filt_description = {'description': {'$regex': str(diction['description']), "$options": "i"}}
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
qry = {"partner_owner_recid": str(my_partner['recid']), 'valide': '1', 'locked': '0'}
|
||||
query_with_filter = {'$and': [qry, filt_code, filt_nom, filt_description]}
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['formulaire'].find(query_with_filter).sort([("_id", pymongo.DESCENDING), ]):
|
||||
user = New_retVal
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
return True, RetObject
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer la liste des formulaires "
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Fonction pour recuperer les données d'un formulaire données
|
||||
"""
|
||||
|
|
45
main.py
45
main.py
|
@ -80,6 +80,7 @@ import paiement_condition as paiement_condition
|
|||
import E_Sign_Document as E_Sign_Document
|
||||
import competence as competence
|
||||
import formulaire_mgt as formulaire_mgt
|
||||
import survey_mgt as survey_mgt
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
@ -8230,7 +8231,7 @@ def Delete_Formulaire():
|
|||
|
||||
|
||||
"""
|
||||
API pour recuperer la listes des formulaire d'un partenaire
|
||||
API pour recuperer la listes des formulaire d'un partenaire, sans filtre
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Formulaire/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
|
@ -8243,6 +8244,20 @@ def Get_List_Formulaire():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer la listes des formulaire d'un partenaire, avec filtre
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Formulaire_with_filter/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_List_Formulaire_with_filter():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_List_Formulaire_with_filter payload = ",payload)
|
||||
status, retval = formulaire_mgt.Get_List_Formulaire_with_filter(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer les données d'un formulaire données
|
||||
"""
|
||||
|
@ -8271,6 +8286,34 @@ def Update_Formulaire():
|
|||
|
||||
|
||||
|
||||
"""
|
||||
API pour recuperer les données d'une enquete
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Given_Survey_Data_No_Token/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Given_Survey_Data_No_Token():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Given_Survey_Data_No_Token payload = ",payload)
|
||||
status, retval = survey_mgt.Get_Given_Survey_Data_No_Token(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API pour enregistrer les resultat d'une enquete
|
||||
"""
|
||||
@app.route('/myclass/api/Record_Survey_Data_No_Token/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Record_Survey_Data_No_Token():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Record_Survey_Data_No_Token payload = ",payload)
|
||||
status, retval = survey_mgt.Record_Survey_Data_No_Token(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
|
@ -0,0 +1,530 @@
|
|||
"""
|
||||
Ce document permet de gerer les "enquetes" avec utilisation des formulaires
|
||||
|
||||
"""
|
||||
import ast
|
||||
|
||||
import bson
|
||||
import pymongo
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
import GlobalVariable as MYSY_GV
|
||||
from math import isnan
|
||||
import GlobalVariable as MYSY_GV
|
||||
import ela_index_bdd_classes as eibdd
|
||||
import email_mgt as email
|
||||
import jinja2
|
||||
from flask import send_file
|
||||
from xhtml2pdf import pisa
|
||||
from email.message import EmailMessage
|
||||
from email.mime.text import MIMEText
|
||||
from email import encoders
|
||||
import smtplib
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.mime.base import MIMEBase
|
||||
from email import encoders
|
||||
|
||||
|
||||
"""
|
||||
Fontion pour recupérer les données d'une enquete données
|
||||
"""
|
||||
|
||||
def Get_Given_Survey_Data_No_Token(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['survey_id' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = [ 'survey_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
qry = { 'statut':'0', 'valide': '1', 'locked': '0', '_id':ObjectId(str(diction['survey_id']))}
|
||||
|
||||
|
||||
for New_retVal in MYSY_GV.dbname['survey'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
||||
user = New_retVal
|
||||
user['id'] = str(val_tmp)
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
|
||||
class_title = ""
|
||||
session_code = ""
|
||||
session_title = ""
|
||||
session_code_date_debut = ""
|
||||
session_code_date_fin = ""
|
||||
|
||||
|
||||
if( "session_id" in New_retVal.keys() and New_retVal['session_id']):
|
||||
# On va recuperer les données de la session
|
||||
my_session_data = MYSY_GV.dbname['session_formation'].find_one( {"partner_owner_recid": str(New_retVal['partner_owner_recid']), 'valide': '1', '_id':ObjectId(str(New_retVal['session_id']))})
|
||||
if( my_session_data and "class_internal_url" in my_session_data.keys() ):
|
||||
my_class_data = MYSY_GV.dbname['myclass'].find_one(
|
||||
{"partner_owner_recid":str(New_retVal['partner_owner_recid']), 'valide': '1',
|
||||
'internal_url': str(my_session_data['class_internal_url'])})
|
||||
|
||||
if( my_class_data and "title" in my_class_data.keys() ):
|
||||
class_title = my_class_data['title']
|
||||
session_code = my_session_data['code_session']
|
||||
session_title = my_session_data['titre']
|
||||
session_code_date_debut = my_session_data['date_debut']
|
||||
session_code_date_fin = my_session_data['date_fin']
|
||||
|
||||
|
||||
user['class_title'] = class_title
|
||||
user['session_code'] = session_code
|
||||
user['session_title'] = session_title
|
||||
user['session_code_date_debut'] = session_code_date_debut
|
||||
user['session_code_date_fin'] = session_code_date_fin
|
||||
|
||||
"""
|
||||
Recuperation des données du formulaire (question)
|
||||
"""
|
||||
list_questions = []
|
||||
if( "formulaire_id" in New_retVal.keys() ):
|
||||
my_formulaire_data = MYSY_GV.dbname['formulaire'].find_one( {"partner_owner_recid": str(New_retVal['partner_owner_recid']), 'valide': '1', 'locked':'0', '_id':ObjectId(str(New_retVal['formulaire_id']))})
|
||||
|
||||
if(my_formulaire_data and "list_questions" in my_formulaire_data.keys() ):
|
||||
list_questions = my_formulaire_data['list_questions']
|
||||
|
||||
user['list_questions'] = list_questions
|
||||
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
return True, RetObject
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer les données "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction enregistrer le resultat d'un survey
|
||||
"""
|
||||
|
||||
def Record_Survey_Data_No_Token(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['survey_id', "list_response" ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = [ 'survey_id', "list_response" ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
"""
|
||||
Verification de l'identité et autorisation de l'entité qui
|
||||
appelle cette API
|
||||
"""
|
||||
token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
"""
|
||||
Verifier que l'enquete est valide
|
||||
"""
|
||||
qry = {'statut': '0', 'valide': '1', 'locked': '0', '_id': ObjectId(str(diction['survey_id']))}
|
||||
|
||||
is_valide_survey = MYSY_GV.dbname['survey'].count_documents(qry)
|
||||
|
||||
if( is_valide_survey <= 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " L'identifiant de l'enquête est invalide ")
|
||||
return False, " L'identifiant de l'enquête est invalide "
|
||||
|
||||
|
||||
JSON_user_response = ast.literal_eval(diction['list_response'])
|
||||
list_keys = list(JSON_user_response.keys())
|
||||
global_response = []
|
||||
for my_key in list_keys:
|
||||
question_id = my_key
|
||||
response = JSON_user_response[my_key]
|
||||
node = {"question_id":question_id, "response":response}
|
||||
global_response.append(node)
|
||||
|
||||
|
||||
|
||||
"""
|
||||
On va enregister les reponse et changer le statut
|
||||
"""
|
||||
mydata = {}
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
mydata['update_by'] = ""
|
||||
mydata['statut'] = "1"
|
||||
mydata['user_response'] = global_response
|
||||
|
||||
result = MYSY_GV.dbname['survey'].find_one_and_update(
|
||||
{'statut': '0', 'valide': '1', 'locked': '0', '_id': ObjectId(str(diction['survey_id']))},
|
||||
{"$set": mydata},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
if (result is None or "_id" not in result.keys()):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour le formulaire (2) ")
|
||||
return False, " Impossible de mettre à jour le formulaire (2) "
|
||||
|
||||
|
||||
return True, " Le formulaire a été correctement mis à jour"
|
||||
|
||||
|
||||
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'enregister les informations "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Survey for enduser : Cette fonction créer une enquete en prenant à partir d'une liste d'inscri
|
||||
"""
|
||||
def Add_Survey_Tab_Inscrit(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['session_id', 'token', 'tab_ids', 'formulaire_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
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
|
||||
|
||||
my_inscription_ids = ""
|
||||
if ("tab_ids" in diction.keys()):
|
||||
if diction['tab_ids']:
|
||||
my_inscription_ids = diction['tab_ids']
|
||||
|
||||
tab_my_inscription_ids = str(my_inscription_ids).split(",")
|
||||
for my_inscription_id in tab_my_inscription_ids:
|
||||
|
||||
# Verifier que les inscriptions sont valides pour cette session
|
||||
tmp_count = MYSY_GV.dbname['inscription'].count_documents({'session_id': str(diction['session_id']),
|
||||
'_id':ObjectId(str(my_inscription_id)),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide':'1'})
|
||||
|
||||
if (tmp_count > 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant est invalide ")
|
||||
return False, " L'identifiant de l'apprenant est invalide "
|
||||
|
||||
|
||||
"""
|
||||
Verifier la valididé du formulaire
|
||||
"""
|
||||
is_valide_form = MYSY_GV.dbname['formulaire'].count_documents({'_id':ObjectId(str(diction['formulaire_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_valide_form <= 0 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant du formulaire est invalide ")
|
||||
return False, " L'identifiant du formulaire est invalide "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Les inscriptions etant toutes valides, on va preceder à la creation de l'enquete
|
||||
"""
|
||||
for my_inscription_id in tab_my_inscription_ids:
|
||||
# Recuperation des données de l'inscript
|
||||
local_Insc_retval = MYSY_GV.dbname['inscription'].find_one({'session_id': str(diction['session_id']),
|
||||
'_id':ObjectId(str(my_inscription_id)),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'valide': '1'
|
||||
})
|
||||
|
||||
if(local_Insc_retval is None ):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de l'inscrit est invalide ")
|
||||
return False, " L'identifiant de l'inscrit est invalide "
|
||||
|
||||
server_diction = {}
|
||||
server_diction['token'] = diction['token']
|
||||
server_diction['session_id'] = diction['session_id']
|
||||
server_diction['inscrit_id'] = str(local_Insc_retval['_id'])
|
||||
server_diction['formulaire_id'] = diction['formulaire_id']
|
||||
|
||||
|
||||
|
||||
|
||||
return True, " La demande d'enquete a été créée "
|
||||
|
||||
|
||||
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 formulaire "
|
||||
|
||||
"""
|
||||
Cette fonction envoi un formulaire pour inscrit
|
||||
"""
|
||||
def Send_One_Survey_To_Inscrit(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['session_id', 'token', 'inscrit_id', 'formulaire_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " La valeur '" + val + "' n'est pas presente dans liste ")
|
||||
return False, " Les informations fournies sont incorrectes"
|
||||
|
||||
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
|
||||
|
||||
"""
|
||||
Recuperer les données du formulaire
|
||||
"""
|
||||
my_formulaire_data = MYSY_GV.dbname['formulaire'].find_one({'_id':ObjectId(str(diction['formulaire_id'])),
|
||||
'valide':'1',
|
||||
'locked':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( my_formulaire_data is None):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant du formulaire est invalide ")
|
||||
return False, " L'identifiant du formulaire est invalide "
|
||||
|
||||
"""
|
||||
Recuperation des données de la session
|
||||
"""
|
||||
my_session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id'])),
|
||||
'valide': '1',
|
||||
'locked': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (my_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 "
|
||||
|
||||
|
||||
"""
|
||||
Recuperer les données de l'inscrit
|
||||
"""
|
||||
my_inscrit_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['inscrit_id'])),
|
||||
'valide': '1',
|
||||
'locked': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid'])})
|
||||
|
||||
if (my_inscrit_data is None):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'inscrit est invalide ")
|
||||
return False, " L'identifiant de l'inscrit est invalide "
|
||||
|
||||
|
||||
|
||||
new_survey_data = {}
|
||||
new_survey_data['email'] = my_inscrit_data['email']
|
||||
new_survey_data['formulaire_id'] = str(diction['formulaire_id'])
|
||||
new_survey_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
new_survey_data['session_id'] = str(diction['session_id'])
|
||||
|
||||
new_survey_data['statut'] = "0"
|
||||
new_survey_data['type'] = "1"
|
||||
new_survey_data['date_update'] = str(datetime.now())
|
||||
new_survey_data['update_by'] = str(my_partner['_id'])
|
||||
new_survey_data['created_by'] = str(my_partner['_id'])
|
||||
|
||||
inserted_id = MYSY_GV.dbname['survey'].insert_one(new_survey_data).inserted_id
|
||||
|
||||
if (not inserted_id):
|
||||
mycommon.myprint(" Impossible de créer l'enquete (2) ")
|
||||
return False, " Impossible de créer l'enquete (2) "
|
||||
|
||||
servey_url = MYSY_GV.CLIENT_URL_BASE+"Survey/"+str(inserted_id)
|
||||
|
||||
"""
|
||||
A présent l'enquete est créée, il faut donc envoyer
|
||||
le mail avec l'url à la personne qui doit remplir l'enquete
|
||||
"""
|
||||
|
||||
"""
|
||||
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)
|
||||
|
||||
html = """\
|
||||
<html>
|
||||
<body>
|
||||
<p>Hi,<br>
|
||||
Merci de suivre l'enquete :"""+str(servey_url)+""" </p>
|
||||
<p><a href="https://blog.mailtrap.io/2018/09/27/cloud-or-local-smtp-server">SMTP Server for Testing: Cloud-based or Local?</a></p>
|
||||
<p> Feel free to <strong>let us</strong> know what content would be useful for you!</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
html_mime = MIMEText(html, 'html')
|
||||
|
||||
# Creation de l'email à enoyer
|
||||
msg = MIMEMultipart("alternative")
|
||||
|
||||
if (str(partner_own_smtp_value) == "1"):
|
||||
msg.attach(html_mime)
|
||||
msg['From'] = partner_SMTP_COUNT_From_User
|
||||
msg['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Demande d'enquete "
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(my_inscrit_data['email'])
|
||||
|
||||
|
||||
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['Bcc'] = 'contact@mysy-training.com'
|
||||
msg['Subject'] = " Demande d'enquete "
|
||||
# msg['to'] = "billardman01@hotmail.com"
|
||||
|
||||
msg['to'] = str(my_inscrit_data['email'])
|
||||
|
||||
smtpserver.ehlo()
|
||||
smtpserver.starttls()
|
||||
smtpserver.login(MYSY_GV.O365_SMTP_COUNT_user, MYSY_GV.O365_SMTP_COUNT_password)
|
||||
|
||||
val = smtpserver.send_message(msg)
|
||||
smtpserver.close()
|
||||
print(" Email envoyé " + str(val))
|
||||
|
||||
return True, "OK"
|
||||
|
||||
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 l'enquete unitaire "
|
||||
|
||||
"""
|
||||
Survey for customer : Cette fonction créer une enquete en prenant à partir d'une liste d'inscri
|
||||
"""
|
Loading…
Reference in New Issue