10/12/2023 - 16h
parent
9bdf6a03a6
commit
68cf730cbd
|
@ -1,13 +1,17 @@
|
|||
<?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="07/12/2023 - 21h30">
|
||||
<change afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="08/12/2023 - 22h30">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Contact.py" beforeDir="false" afterPath="$PROJECT_DIR$/Contact.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$/agenda.py" beforeDir="false" afterPath="$PROJECT_DIR$/agenda.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_document_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_document_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/apprenant_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/apprenant_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/class_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/class_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_client.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
|
@ -78,13 +82,6 @@
|
|||
<option name="presentableId" value="Default" />
|
||||
<updated>1680804787304</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00117" summary="30/09/2023 - 18h">
|
||||
<created>1696091230108</created>
|
||||
<option name="number" value="00117" />
|
||||
<option name="presentableId" value="LOCAL-00117" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1696091230108</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00118" summary="30/09/2023 - 19h">
|
||||
<created>1696093021639</created>
|
||||
<option name="number" value="00118" />
|
||||
|
@ -421,7 +418,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1701980089274</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="166" />
|
||||
<task id="LOCAL-00166" summary="08/12/2023 - 22h30">
|
||||
<created>1702073046202</created>
|
||||
<option name="number" value="00166" />
|
||||
<option name="presentableId" value="LOCAL-00166" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1702073046202</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="167" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -436,7 +440,6 @@
|
|||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="09/11/2023 - 23h" />
|
||||
<MESSAGE value="sdds" />
|
||||
<MESSAGE value="11/11/2023 - 17h" />
|
||||
<MESSAGE value="11/11/2023 - 23h" />
|
||||
|
@ -461,6 +464,7 @@
|
|||
<MESSAGE value="06/12/2023 - 21h" />
|
||||
<MESSAGE value="07/12/2023 - 11h30" />
|
||||
<MESSAGE value="07/12/2023 - 21h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="07/12/2023 - 21h30" />
|
||||
<MESSAGE value="08/12/2023 - 22h30" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="08/12/2023 - 22h30" />
|
||||
</component>
|
||||
</project>
|
224
Contact.py
224
Contact.py
|
@ -53,8 +53,8 @@ def Add_Contact(diction):
|
|||
field_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
||||
"telephone", "website", "comment",'adr_adresse', 'adr_code_postal',
|
||||
'adr_ville', 'adr_pays', 'type', 'telephone_mobile', 'linkedin',
|
||||
'facebook', 'twitter', 'related_collection', 'related_collection_owner_email',
|
||||
'prenom', 'fonction', 'civilite']
|
||||
'facebook', 'twitter', 'related_collection',
|
||||
'prenom', 'fonction', 'civilite', 'related_collection_owner_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -66,7 +66,7 @@ def Add_Contact(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', "email", 'related_collection', 'related_collection_owner_email',]
|
||||
field_list_obligatoire = ['token', "email", 'related_collection','related_collection_owner_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -83,30 +83,14 @@ def Add_Contact(diction):
|
|||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
||||
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
|
||||
"""
|
||||
Verification s'il n'existe pas un cient du partenaire qui porte la meme adresse email
|
||||
Verification s'il n'existe pas un client du partenaire qui porte la meme adresse email
|
||||
"""
|
||||
|
||||
|
||||
tmp_count = MYSY_GV.dbname['contact'].count_documents({'email': str(diction['email']),
|
||||
'valide': '1', 'partner_recid': my_partner['recid']})
|
||||
if (tmp_count > 0):
|
||||
|
@ -128,137 +112,139 @@ def Add_Contact(diction):
|
|||
if ("raison_sociale" in diction.keys()):
|
||||
if diction['raison_sociale']:
|
||||
raison_sociale = diction['raison_sociale']
|
||||
data['raison_sociale'] = diction['raison_sociale']
|
||||
data['raison_sociale'] = raison_sociale
|
||||
|
||||
nom = ""
|
||||
if ("nom" in diction.keys()):
|
||||
if diction['nom']:
|
||||
nom = diction['nom']
|
||||
data['nom'] = diction['nom']
|
||||
data['nom'] = nom
|
||||
|
||||
siret = ""
|
||||
if ("siret" in diction.keys()):
|
||||
if diction['siret']:
|
||||
siret = diction['siret']
|
||||
data['siret'] = diction['siret']
|
||||
data['siret'] = siret
|
||||
|
||||
prenom = ""
|
||||
if ("prenom" in diction.keys()):
|
||||
if diction['prenom']:
|
||||
prenom = diction['prenom']
|
||||
data['prenom'] = diction['prenom']
|
||||
data['prenom'] = prenom
|
||||
|
||||
|
||||
fonction = ""
|
||||
if ("fonction" in diction.keys()):
|
||||
if diction['fonction']:
|
||||
fonction = diction['fonction']
|
||||
data['fonction'] = diction['fonction']
|
||||
data['fonction'] = fonction
|
||||
|
||||
civilite = ""
|
||||
if ("civilite" in diction.keys()):
|
||||
if diction['civilite']:
|
||||
civilite = diction['civilite']
|
||||
data['civilite'] = diction['civilite']
|
||||
|
||||
data['civilite'] = civilite
|
||||
|
||||
|
||||
adr_adresse = ""
|
||||
if ("adr_adresse" in diction.keys()):
|
||||
if diction['adr_adresse']:
|
||||
adr_adresse = diction['adr_adresse']
|
||||
data['adr_adresse'] = diction['adr_adresse']
|
||||
data['adr_adresse'] = adr_adresse
|
||||
|
||||
adr_code_postal = ""
|
||||
if ("adr_code_postal" in diction.keys()):
|
||||
if diction['adr_code_postal']:
|
||||
adr_code_postal = diction['adr_code_postal']
|
||||
data['adr_code_postal'] = diction['adr_code_postal']
|
||||
data['adr_code_postal'] = adr_code_postal
|
||||
|
||||
adr_ville = ""
|
||||
if ("adr_ville" in diction.keys()):
|
||||
if diction['adr_ville']:
|
||||
adr_ville = diction['adr_ville']
|
||||
data['adr_ville'] = diction['adr_ville']
|
||||
data['adr_ville'] = adr_ville
|
||||
|
||||
adr_pays = ""
|
||||
if ("adr_pays" in diction.keys()):
|
||||
if diction['adr_pays']:
|
||||
adr_pays = diction['adr_pays']
|
||||
data['adr_pays'] = diction['adr_pays']
|
||||
data['adr_pays'] = adr_pays
|
||||
|
||||
tva = ""
|
||||
if ("tva" in diction.keys()):
|
||||
if diction['tva']:
|
||||
tva = diction['tva']
|
||||
data['tva'] = diction['tva']
|
||||
data['tva'] = tva
|
||||
|
||||
email = ""
|
||||
if ("email" in diction.keys()):
|
||||
if diction['email']:
|
||||
email = diction['email']
|
||||
data['email'] = diction['email']
|
||||
if( mycommon.isEmailValide(email) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
||||
|
||||
return False, " - - L'adresse email "+str(email)+" n'est pas valide "
|
||||
data['email'] = diction['email']
|
||||
|
||||
|
||||
telephone = ""
|
||||
if ("telephone" in diction.keys()):
|
||||
if diction['telephone']:
|
||||
telephone = diction['telephone']
|
||||
data['telephone'] = diction['telephone']
|
||||
data['telephone'] = telephone
|
||||
|
||||
telephone_mobile = ""
|
||||
if ("telephone_mobile" in diction.keys()):
|
||||
if diction['telephone_mobile']:
|
||||
telephone_mobile = diction['telephone_mobile']
|
||||
data['telephone_mobile'] = diction['telephone_mobile']
|
||||
data['telephone_mobile'] = telephone_mobile
|
||||
|
||||
|
||||
website = ""
|
||||
if ("website" in diction.keys()):
|
||||
if diction['website']:
|
||||
website = diction['website']
|
||||
data['website'] = diction['website']
|
||||
data['website'] = website
|
||||
|
||||
comment = ""
|
||||
if ("comment" in diction.keys()):
|
||||
if diction['comment']:
|
||||
comment = diction['comment']
|
||||
data['comment'] = diction['comment']
|
||||
data['comment'] = comment
|
||||
|
||||
linkedin = ""
|
||||
if ("linkedin" in diction.keys()):
|
||||
if diction['linkedin']:
|
||||
linkedin = diction['linkedin']
|
||||
data['linkedin'] = diction['linkedin']
|
||||
data['linkedin'] = linkedin
|
||||
|
||||
facebook = ""
|
||||
if ("facebook" in diction.keys()):
|
||||
if diction['facebook']:
|
||||
facebook = diction['facebook']
|
||||
data['facebook'] = diction['facebook']
|
||||
data['facebook'] = facebook
|
||||
|
||||
twitter = ""
|
||||
if ("twitter" in diction.keys()):
|
||||
if diction['twitter']:
|
||||
twitter = diction['twitter']
|
||||
data['twitter'] = diction['twitter']
|
||||
data['twitter'] = twitter
|
||||
|
||||
|
||||
type = ""
|
||||
if ("type" in diction.keys()):
|
||||
if diction['type']:
|
||||
type = diction['type']
|
||||
data['type'] = diction['type']
|
||||
|
||||
if( type not in MYSY_GV.CONTACT_TYPE):
|
||||
mycommon.myprint(
|
||||
"- Le type de contact "+str(type)+" n'est pas autorisé")
|
||||
return False, "- Le type de contact "+str(type)+" n'est pas autorisé"
|
||||
|
||||
data['type'] = type
|
||||
|
||||
related_collection = ""
|
||||
if ("related_collection" in diction.keys()):
|
||||
if diction['related_collection']:
|
||||
|
@ -269,20 +255,12 @@ def Add_Contact(diction):
|
|||
"- La collection " + str(related_collection) + " n'accepte pas de contact")
|
||||
return False, "- La collection " + str(related_collection) + " n'accepte pas de contact"
|
||||
|
||||
data['related_collection'] = related_collection
|
||||
|
||||
if ("related_collection_owner_email" in diction.keys()):
|
||||
related_collection_owner_email = str(diction['related_collection_owner_email'])
|
||||
"""
|
||||
Recuperation du recid associé au related_collection_owner_email dans la collection : related_collection
|
||||
"""
|
||||
#print(" #### on cherche le recid du mail "+ str(related_collection_owner_email)+" dans la collection "+str(diction['related_collection'])+" ." )
|
||||
local_tmp_val = MYSY_GV.dbname[str(diction['related_collection'])].find_one({'email':related_collection_owner_email})
|
||||
if (local_tmp_val is None or "recid" not in local_tmp_val.keys()):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - impossible de récupérer les données de "+ str(related_collection_owner_email)+" dans la collection "+str(diction['related_collection']) )
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de "+str(related_collection_owner_email)+" dans la collection "+str(diction['related_collection'])+" . "
|
||||
|
||||
data['related_collection_recid'] = str(local_tmp_val['recid'])
|
||||
related_collection_owner_id = ""
|
||||
if ("related_collection_owner_id" in diction.keys()):
|
||||
related_collection_owner_id = str(diction['related_collection_owner_id'])
|
||||
data['related_collection_recid'] = str(related_collection_owner_id)
|
||||
|
||||
|
||||
data['valide'] = '1'
|
||||
|
@ -326,7 +304,8 @@ def Update_Contact(diction):
|
|||
field_list = ['token', "raison_sociale", "nom", "prenom", "siret", "tva", "email",
|
||||
"telephone", "website", "comment",'adr_adresse', 'adr_code_postal',
|
||||
'adr_ville', 'adr_pays', 'type', 'telephone_mobile', 'linkedin',
|
||||
'facebook', 'twitter', 'contact_recid', 'prenom', 'fonction', 'civilite']
|
||||
'facebook', 'twitter', 'prenom', 'fonction', 'civilite',
|
||||
'_id']
|
||||
|
||||
|
||||
incom_keys = diction.keys()
|
||||
|
@ -339,7 +318,7 @@ def Update_Contact(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', "email", 'contact_recid', ]
|
||||
field_list_obligatoire = ['token', "email", '_id', ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -356,44 +335,25 @@ def Update_Contact(diction):
|
|||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
||||
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
"""
|
||||
Verification s'il n'existe pas un cient du partenaire qui perte le meme
|
||||
nom, ou la meme adresse email
|
||||
Verifier que le contact qu'on souhaite mettre à jour existe bien
|
||||
"""
|
||||
|
||||
qry_update = {'email': str(diction['email']),
|
||||
'valide': '1', 'locked':'0', 'partner_recid': str(my_partner['recid']),
|
||||
'recid':str(diction['contact_recid'])}
|
||||
|
||||
|
||||
|
||||
print(" ### qry_update = ", qry_update)
|
||||
|
||||
tmp_count = MYSY_GV.dbname['contact'].count_documents(qry_update)
|
||||
tmp_count = MYSY_GV.dbname['contact'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
||||
'partner_recid':str(my_partner['recid']),
|
||||
'valide':'1',
|
||||
'locked':'0'})
|
||||
if (tmp_count <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Ce contact n'existe pas: nom = "+str(diction['nom']))
|
||||
3]) + " - L'identifiant du contact est invalide ")
|
||||
|
||||
return False, " - Ce contact n'existe pas, mise à jour impossible "
|
||||
return False, " L'identifiant du contact est invalide "
|
||||
|
||||
|
||||
|
||||
|
@ -529,26 +489,25 @@ def Update_Contact(diction):
|
|||
data_update['valide'] = '1'
|
||||
data_update['locked'] = '0'
|
||||
data_update['date_update'] = str(datetime.now())
|
||||
data_update['update_by'] = str(my_partner['_id'])
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {'email': str(diction['email']),
|
||||
'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid']),
|
||||
'recid': str(diction['contact_recid'])}
|
||||
|
||||
|
||||
inserted_id = ""
|
||||
result = MYSY_GV.dbname['contact'].find_one_and_update(
|
||||
data_cle,
|
||||
{'_id': ObjectId(str(diction['_id'])),
|
||||
'partner_recid': str(my_partner['recid']),
|
||||
'valide': '1',
|
||||
'locked': '0'},
|
||||
{"$set": data_update},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (result is None or "_id" not in result.keys()):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour le contact : email = " + str(diction['email']))
|
||||
return False, " Impossible de mettre à jour le client "
|
||||
" Impossible de mettre à jour le contact : email ")
|
||||
return False, " Impossible de mettre à jour le contact "
|
||||
|
||||
return True, " Le contact a été correctement mis à jour"
|
||||
|
||||
|
@ -562,9 +521,8 @@ def Update_Contact(diction):
|
|||
Recuperation de la liste des contacts d'une entité en se basant sur
|
||||
- related_collection
|
||||
- token (partner_recid)
|
||||
- related_collection_owner_email (s'il est fourni)
|
||||
alog :
|
||||
on va aller chercher le recid du related_collection_owner_email dans la collection concerné
|
||||
- related_collection_owner_id (s'il est fourni)
|
||||
|
||||
"""
|
||||
def Get_List_Entity_Contact(diction):
|
||||
try:
|
||||
|
@ -573,7 +531,7 @@ def Get_List_Entity_Contact(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'related_collection', 'related_collection_owner_email']
|
||||
field_list = ['token', 'related_collection', 'related_collection_owner_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -601,18 +559,9 @@ def Get_List_Entity_Contact(diction):
|
|||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
||||
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
|
@ -620,18 +569,9 @@ def Get_List_Entity_Contact(diction):
|
|||
data_cle['partner_recid'] = str(my_partner['recid'])
|
||||
data_cle['related_collection'] = str(diction['related_collection'])
|
||||
|
||||
if ("related_collection_owner_email" in diction.keys()):
|
||||
related_collection_owner_email = str(diction['related_collection_owner_email'])
|
||||
"""
|
||||
Recuperation du recid associé au related_collection_owner_email dans la collection : related_collection
|
||||
"""
|
||||
local_tmp_val = MYSY_GV.dbname[str(diction['related_collection'])].find_one({'email':related_collection_owner_email})
|
||||
if (local_tmp_val is None or "recid" not in local_tmp_val.keys()):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - impossible de récupérer les données de "+ str(related_collection_owner_email)+" dans la collection "+str(diction['related_collection']) )
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de "+str(related_collection_owner_email)+" dans la collection "+str(diction['related_collection'])+" . "
|
||||
|
||||
data_cle['related_collection_recid'] = str(local_tmp_val['recid'])
|
||||
if ("related_collection_owner_id" in diction.keys()):
|
||||
related_collection_owner_id = str(diction['related_collection_owner_id'])
|
||||
data_cle['related_collection_recid'] = str(related_collection_owner_id)
|
||||
|
||||
data_cle['locked'] = "0"
|
||||
|
||||
|
@ -650,7 +590,7 @@ def Get_List_Entity_Contact(diction):
|
|||
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 contact "
|
||||
return False, " Impossible de récupérer la liste des contacts "
|
||||
|
||||
|
||||
"""
|
||||
|
@ -663,7 +603,7 @@ def Get_Given_Contact(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'email', 'related_collection', 'related_collection_owner_email']
|
||||
field_list = ['token', '_id', 'related_collection', 'related_collection_owner_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -675,7 +615,7 @@ def Get_Given_Contact(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', 'email', 'related_collection', 'related_collection_owner_email']
|
||||
field_list_obligatoire = ['token', '_id', 'related_collection', 'related_collection_owner_id']
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
mycommon.myprint(
|
||||
|
@ -691,36 +631,18 @@ def Get_Given_Contact(diction):
|
|||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
||||
|
||||
|
||||
|
||||
# Recuperation du recid du related_collection_owner_email
|
||||
related_collection_owner_data = MYSY_GV.dbname[str(diction['related_collection'])].find_one({'email':str(diction['related_collection_owner_email']),
|
||||
'valide':'1', 'locked':'0'})
|
||||
|
||||
if( related_collection_owner_data is None or 'recid' not in related_collection_owner_data.keys()):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - related_collection_owner_email inconnu ")
|
||||
return False, str(inspect.stack()[0][3]) + " - related_collection_owner_email inconnu "
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {}
|
||||
data_cle['partner_recid'] = str(my_partner['recid'])
|
||||
data_cle['email'] = str(diction['email'])
|
||||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||||
data_cle['related_collection'] = str(diction['related_collection'])
|
||||
data_cle['related_collection_recid'] = str(related_collection_owner_data['recid'])
|
||||
data_cle['related_collection_recid'] = str(diction['related_collection_owner_id'])
|
||||
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
|
|
|
@ -1252,7 +1252,7 @@ def SendPre_InscriptionEmail(diction):
|
|||
if local_info_session['formateur_id']:
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(local_info_session['formateur_id'])),
|
||||
'valide':'1',
|
||||
'locked':'1',
|
||||
'locked':'0',
|
||||
'partner_recid':str(local_session[0]['partner_owner_recid'])})
|
||||
|
||||
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
||||
|
@ -6222,17 +6222,7 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
return False, " L'identifiant du modèle de courrier est invalide "
|
||||
|
||||
|
||||
# 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'])})
|
||||
|
||||
# Recuperation des données du partenaire associé à l'utilisateur connecté
|
||||
local_status, local_retval = mycommon.Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
|
||||
if( local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
company_data = local_retval
|
||||
|
||||
|
||||
# Recupération des données du modèle de document
|
||||
|
@ -6275,24 +6265,19 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
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_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'])})
|
||||
formateur_nom_prenom = ""
|
||||
# Si il y a un code formateur_id, alors on va recuperer les nom et prenom du formation
|
||||
if ("formateur_id" in session_data.keys() and session_data['formateur_id']):
|
||||
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'])})
|
||||
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id': ObjectId(str(session_data['formateur_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])
|
||||
})
|
||||
|
||||
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
||||
formateur_nom_prenom = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
|
||||
|
||||
session_data['formateur_nom_prenom'] = formateur_nom_prenom
|
||||
tab_session = []
|
||||
tab_session.append(session_data['_id'])
|
||||
|
||||
|
||||
|
||||
|
@ -6300,104 +6285,24 @@ def Sent_Convention_Stagiaire_By_Email(tab_files, Folder, diction):
|
|||
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)
|
||||
|
||||
"""
|
||||
Recuperartion des champs du stagiaire
|
||||
"""
|
||||
stagiaire_liste_champ = ['email', 'nom', 'prenom', 'telephone', 'client_rattachement_id', 'employeur',
|
||||
'modefinancement', 'tuteur1_adresse', 'tuteur1_cp', 'tuteur1_email', 'tuteur1_nom',
|
||||
'tuteur1_pays', 'tuteur1_telephone', 'tuteur1_ville', 'tuteur1_prenom',
|
||||
'tuteur2_adresse', 'tuteur2_cp', 'tuteur2_email', 'tuteur2_nom', 'tuteur2_pays',
|
||||
'tuteur2_prenom',
|
||||
'tuteur2_telephone', 'tuteur2_ville', 'adresse', 'code_postal', 'ville', 'pays']
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
for champ in stagiaire_liste_champ:
|
||||
if( champ in inscription_data ):
|
||||
new_champ_name = "stagiaire_"+str(champ)
|
||||
new_field = {new_champ_name: str(inscription_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "stagiaire_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la session
|
||||
"""
|
||||
session_liste_champ = ['code_session', 'class_internal_url', 'date_debut', 'session_etape', 'date_fin', 'distantiel', 'presentiel', 'session_ondemande', 'nb_participant',
|
||||
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse', 'code_postal', 'ville', 'pays', 'date_debut_inscription',
|
||||
'date_fin_inscription', 'formateur_nom_prenom'
|
||||
]
|
||||
|
||||
for champ in session_liste_champ:
|
||||
if (champ in session_data):
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: str(session_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la formation
|
||||
"""
|
||||
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title', 'duration', 'duration_unit']
|
||||
|
||||
for champ in myclass_liste_champ:
|
||||
if (champ in class_data):
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: str(class_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la personne connecté
|
||||
"""
|
||||
connected_user_liste_champ = ['email', 'contact_nom', 'contact_prenom']
|
||||
for champ in connected_user_liste_champ:
|
||||
if (champ in my_partner):
|
||||
new_champ_name = "utilisateur_" + str(champ)
|
||||
new_field = {new_champ_name: str(my_partner[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "utilisateur_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la société
|
||||
"""
|
||||
company_liste_champ = ['nom', 'email', 'num_nda', 'website', 'adr_street', 'adr_zip', 'adr_city', 'adr_country']
|
||||
for champ in company_liste_champ:
|
||||
if (champ in company_data):
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: str(company_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
# Ajout des champs système comme la date du jour
|
||||
ct = datetime.now()
|
||||
ts = ct.timestamp()
|
||||
date_jour = ct.strftime("%d/%m/%Y")
|
||||
new_field = {"date_jour": str(date_jour)}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
convention_dictionnary_data = local_retval
|
||||
|
||||
|
||||
## Creation du PDF
|
||||
|
@ -6681,7 +6586,7 @@ def Download_Convention_Stagiaire_PDF(diction):
|
|||
'type_doc':'pdf',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
|
||||
print(" ### qry = ", qry)
|
||||
|
||||
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
||||
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide': '1',
|
||||
|
@ -6715,30 +6620,22 @@ def Download_Convention_Stagiaire_PDF(diction):
|
|||
)
|
||||
|
||||
# Recuperations des info de la session de formation
|
||||
tab_session = []
|
||||
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'])})
|
||||
|
||||
formateur_nom_prenom = ""
|
||||
# Si il y a un code formateur_id, alors on va recuperer les nom et prenom du formation
|
||||
if ("formateur_id" in session_data.keys() and session_data['formateur_id']):
|
||||
tab_session.append(session_data['_id'])
|
||||
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||||
{'_id': ObjectId(str(session_data['formateur_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])
|
||||
})
|
||||
|
||||
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
||||
formateur_nom_prenom = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
|
||||
|
||||
session_data['formateur_nom_prenom'] = formateur_nom_prenom
|
||||
|
||||
# Recupérer la liste des participant pour une eventuelle à afficher pour les conventions d'entreprise
|
||||
tab_participant = []
|
||||
list_participants_session = MYSY_GV.dbname['inscription'].find({'session_id':str(session_data['_id']), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])},
|
||||
{'email':1, 'nom':1, 'prenom':1}).sort([("nom", pymongo.DESCENDING)])
|
||||
{'email':1, 'nom':1, 'prenom':1, '_id':1}).sort([("nom", pymongo.DESCENDING)])
|
||||
|
||||
for val in list_participants_session:
|
||||
tab_participant.append(val['_id'])
|
||||
|
||||
|
||||
# Recuperation du titre de la formation
|
||||
|
@ -6746,108 +6643,219 @@ def Download_Convention_Stagiaire_PDF(diction):
|
|||
{'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 = {}
|
||||
|
||||
"""
|
||||
Recuperartion des champs du stagiaire
|
||||
"""
|
||||
stagiaire_liste_champ = ['email', 'nom', 'prenom', 'telephone', 'client_rattachement_id', 'employeur',
|
||||
'modefinancement', 'tuteur1_adresse', 'tuteur1_cp', 'tuteur1_email', 'tuteur1_nom',
|
||||
'tuteur1_pays', 'tuteur1_telephone', 'tuteur1_ville', 'tuteur1_prenom',
|
||||
'tuteur2_adresse', 'tuteur2_cp', 'tuteur2_email', 'tuteur2_nom', 'tuteur2_pays',
|
||||
'tuteur2_prenom',
|
||||
'tuteur2_telephone', 'tuteur2_ville','adresse', 'code_postal', 'ville', 'pays']
|
||||
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'] = []
|
||||
|
||||
for champ in stagiaire_liste_champ:
|
||||
if (champ in inscription_data):
|
||||
new_champ_name = "stagiaire_" + str(champ)
|
||||
new_field = {new_champ_name: str(inscription_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "stagiaire_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la session
|
||||
"""
|
||||
session_liste_champ = ['code_session', 'class_internal_url', 'date_debut', 'session_etape', 'date_fin',
|
||||
'distantiel', 'presentiel', 'session_ondemande', 'nb_participant',
|
||||
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse',
|
||||
'code_postal', 'ville', 'pays', 'date_debut_inscription', 'date_fin_inscription',
|
||||
'formateur_nom_prenom']
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
for champ in session_liste_champ:
|
||||
if (champ in session_data):
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: str(session_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la formation
|
||||
"""
|
||||
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title', 'duration', 'duration_unit']
|
||||
|
||||
for champ in myclass_liste_champ:
|
||||
if (champ in class_data):
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: str(class_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la personne connecté
|
||||
"""
|
||||
connected_user_liste_champ = ['email', 'contact_nom', 'contact_prenom']
|
||||
for champ in connected_user_liste_champ:
|
||||
if (champ in my_partner):
|
||||
new_champ_name = "utilisateur_" + str(champ)
|
||||
new_field = {new_champ_name: str(my_partner[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "utilisateur_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la société
|
||||
"""
|
||||
company_liste_champ = ['nom', 'email', 'num_nda', 'website', 'adr_street', 'adr_zip', 'adr_city', 'adr_country']
|
||||
for champ in company_liste_champ:
|
||||
if (champ in company_data):
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: str(company_data[champ])}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
# Ajout des champs système comme la date du jour
|
||||
ct = datetime.now()
|
||||
ts = ct.timestamp()
|
||||
date_jour = ct.strftime("%d/%m/%Y")
|
||||
new_field = {"date_jour": str(date_jour)}
|
||||
convention_dictionnary_data.update(new_field)
|
||||
|
||||
node_list_part = []
|
||||
for val in list_participants_session:
|
||||
print(" #### val = ", val)
|
||||
del val['_id']
|
||||
node_list_part.append(val)
|
||||
|
||||
convention_dictionnary_data['list_participants'] = node_list_part
|
||||
convention_dictionnary_data = local_retval
|
||||
|
||||
|
||||
print(" ### convention_dictionnary_data = ", convention_dictionnary_data)
|
||||
#print(" ### convention_dictionnary_data = ", convention_dictionnary_data)
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data,
|
||||
}
|
||||
|
||||
json_formatted_str = json.dumps(body, indent=2)
|
||||
|
||||
print(json_formatted_str)
|
||||
|
||||
## 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 = "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()
|
||||
|
||||
if os.path.exists(outputFilename):
|
||||
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
return True, send_file(outputFilename, 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) "
|
||||
|
||||
|
||||
"""
|
||||
Pour les statgiaires rattaché à un client, edite les convetions pour le client
|
||||
donc avec la liste des participants
|
||||
"""
|
||||
def Download_Convention_Stagiaire_PDF_By_Partner_client(diction):
|
||||
try:
|
||||
field_list_obligatoire = ['token', 'courrier_template_id', 'partner_client_id', '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, " 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_id_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_id_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 que ce client a bien des inscriptions valide pour cette session
|
||||
is_valide_inscription_pr_client = MYSY_GV.dbname['inscription'].count_documents({'client_rattachement_id':str(diction['partner_client_id']),
|
||||
'session_id':str(diction['session_id']),
|
||||
'partner_owner_recid':str(my_partner['recid']),
|
||||
'status':'1'})
|
||||
|
||||
|
||||
if (is_valide_inscription_pr_client <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Aucune inscription valide pour ce client pour cette session ")
|
||||
return False, " Aucune inscription valide pour ce client pour cette session "
|
||||
|
||||
partner_client_id_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(diction['partner_client_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_recid':str(my_partner['recid'])})
|
||||
|
||||
tab_client = []
|
||||
tab_client.append(partner_client_id_data['_id'])
|
||||
|
||||
# Verifier que le 'courrier_template_id' est valide. il doit etre de type PDF
|
||||
is_courrier_template_id_valide = MYSY_GV.dbname['courrier_template'].count_documents(
|
||||
{'_id': ObjectId(str(diction['courrier_template_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'type_doc': 'pdf',
|
||||
'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 "
|
||||
|
||||
|
||||
|
||||
# Recuperation des données du partenaire associé à l'utilisateur connecté
|
||||
local_status, local_retval = mycommon.Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
company_data = local_retval
|
||||
|
||||
# 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'])}
|
||||
)
|
||||
|
||||
# Recuperations des info de la session de formation
|
||||
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
||||
{'_id': ObjectId(str(diction['session_id'])), 'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])}, {'_id':1, 'class_internal_url':1})
|
||||
|
||||
|
||||
tab_session = [session_data['_id']]
|
||||
print(" tab_session = ", tab_session)
|
||||
|
||||
tab_participant = []
|
||||
# Recupérer la liste des participant pour une eventuelle à afficher pour les conventions d'entreprise
|
||||
for participant in MYSY_GV.dbname['inscription'].find({'session_id':str(session_data['_id']), 'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])},
|
||||
{'_id':1}):
|
||||
tab_participant.append(participant['_id'])
|
||||
|
||||
|
||||
print(" tab_participant = ", tab_participant)
|
||||
|
||||
|
||||
# Recuperation du titre de la formation
|
||||
tab_class = []
|
||||
for class_data in MYSY_GV.dbname['myclass'].find(
|
||||
{'internal_url': str(session_data['class_internal_url']), 'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']), 'locked': '0'}, {'_id':1}):
|
||||
tab_class.append(class_data['_id'])
|
||||
|
||||
|
||||
print(" tab_class = ", tab_class)
|
||||
|
||||
|
||||
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'] = 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
|
||||
|
||||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||||
|
||||
print(" ### convention_dictionnary_data = ")
|
||||
|
||||
#json_object = ast.literal_eval(convention_dictionnary_data)
|
||||
|
||||
json_formatted_str = json.dumps(convention_dictionnary_data, indent=2)
|
||||
|
||||
print(json_formatted_str)
|
||||
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data,
|
||||
|
@ -6890,6 +6898,364 @@ def Download_Convention_Stagiaire_PDF(diction):
|
|||
return False, " Impossible de générer le fichier PDF (2) "
|
||||
|
||||
|
||||
"""
|
||||
Envoie par email pour les stagiaires rattachés à un client
|
||||
"""
|
||||
def Sent_Convention_Stagiaire_By_Email_By_Partner_client(tab_files, Folder, diction):
|
||||
try:
|
||||
field_list_obligatoire = ['token', 'courrier_template_id', 'email_test', 'email_production', 'partner_client_id', '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, " 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_id_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_id_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 que ce client a bien des inscriptions valide pour cette session
|
||||
is_valide_inscription_pr_client = MYSY_GV.dbname['inscription'].count_documents(
|
||||
{'client_rattachement_id': str(diction['partner_client_id']),
|
||||
'session_id': str(diction['session_id']),
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'status': '1'})
|
||||
|
||||
if (is_valide_inscription_pr_client <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Aucune inscription valide pour ce client pour cette session ")
|
||||
return False, " Aucune inscription valide pour ce client pour cette session "
|
||||
|
||||
partner_client_id_data = MYSY_GV.dbname['partner_client'].find_one(
|
||||
{'_id': ObjectId(str(diction['partner_client_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])})
|
||||
|
||||
# Traitement de l'eventuel fichier joint
|
||||
tab_files_to_attache_to_mail = []
|
||||
|
||||
for 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']):
|
||||
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:
|
||||
tab_email_prod = "default"
|
||||
|
||||
|
||||
else:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " Aucune adresse email n'a été fourni. ")
|
||||
return False, " Aucune adresse email n'a été fourni. "
|
||||
|
||||
# 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 stagiaire
|
||||
inscription_data = MYSY_GV.dbname['inscription'].find({'session_id': str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'client_rattachement_id':str(diction['partner_client_id'])})
|
||||
|
||||
tab_participant = []
|
||||
for val in inscription_data:
|
||||
tab_participant.append(val['_id'])
|
||||
|
||||
print(" ### tab_participant = ", tab_participant)
|
||||
|
||||
# Recuperations des info de la session de formation
|
||||
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(diction['session_id']))})
|
||||
|
||||
tab_session = []
|
||||
tab_session.append(session_data['_id'])
|
||||
|
||||
print(" ### tab_session = ", tab_session)
|
||||
|
||||
|
||||
# Recuperation du titre de la formation
|
||||
class_data = MYSY_GV.dbname['myclass'].find({'internal_url': str(session_data['class_internal_url']),
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid']),
|
||||
'locked': '0'})
|
||||
|
||||
tab_class = []
|
||||
for val in class_data:
|
||||
tab_class.append(val['_id'])
|
||||
|
||||
# Recuperer les données du client
|
||||
client_data = MYSY_GV.dbname['partner_client'].find_one({'_id':ObjectId(str(diction['partner_client_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_recid': str(my_partner['recid']),
|
||||
})
|
||||
|
||||
|
||||
tab_client = []
|
||||
tab_client.append(client_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'] = 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
|
||||
|
||||
## Creation du PDF
|
||||
|
||||
body = {
|
||||
"params": convention_dictionnary_data,
|
||||
}
|
||||
|
||||
## Creation du PDF
|
||||
|
||||
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['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['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 "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction retourne la liste des adresses emails de communication
|
||||
|
|
5671
Log/log_file.log
5671
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,8 @@
|
|||
"""
|
||||
Ce fichier gere les sessions de formation
|
||||
"""
|
||||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
|
||||
import pymongo
|
||||
from pymongo import MongoClient
|
||||
|
@ -20,6 +22,7 @@ from math import isnan
|
|||
import GlobalVariable as MYSY_GV
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta
|
||||
import Inscription_mgt as Inscription_mgt
|
||||
|
||||
|
||||
"""
|
||||
|
@ -3868,4 +3871,254 @@ def Duplicate_List_Session_Formation(diction):
|
|||
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 de dupliquer la session de formation"
|
||||
return False, "Impossible de dupliquer la session de formation"
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction les convention par email de formation en partant de la session.
|
||||
|
||||
Algo :
|
||||
|
||||
On recuperer les stagaiaires qu'on groupe par client_rattachement_id
|
||||
Pour tous ceux qui on le meme, on envoie une convention groupée
|
||||
|
||||
pour les autres, on envoi des conventions individuelle
|
||||
|
||||
"""
|
||||
def Prepare_and_Send_Convention_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_client_rattachement_id = MYSY_GV.dbname['inscription'].distinct("client_rattachement_id",
|
||||
{'session_id':str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid']),
|
||||
"client_rattachement_id": { '$ne': ''}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
print(" ### la liste des liste_client_rattachement_id = ", liste_client_rattachement_id)
|
||||
|
||||
# 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":''
|
||||
}
|
||||
)
|
||||
|
||||
print(" ### la liste des liste_inscription_no_client = ", str(liste_inscription_no_client))
|
||||
|
||||
|
||||
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)
|
||||
|
||||
if( local_status is False):
|
||||
mycommon.myprint(" WARNING : impossible d'envoyer la convention au client : "+str( single_client))
|
||||
|
||||
|
||||
# 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']
|
||||
|
||||
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 = []
|
||||
|
||||
|
||||
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 "
|
||||
|
||||
|
||||
"""
|
||||
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
|
||||
"""
|
||||
def Prepare_and_Send_Convention_From_Session_By_PDF(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_client_rattachement_id = MYSY_GV.dbname['inscription'].distinct("client_rattachement_id",
|
||||
{'session_id':str(diction['session_id']),
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(
|
||||
my_partner['recid']),
|
||||
"client_rattachement_id": { '$ne': ''}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
print(" ### la liste des liste_client_rattachement_id = ", liste_client_rattachement_id)
|
||||
|
||||
# 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":''
|
||||
}
|
||||
)
|
||||
|
||||
print(" ### la liste des liste_inscription_no_client = ", str(liste_inscription_no_client))
|
||||
|
||||
|
||||
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)
|
||||
|
||||
if( local_status is False):
|
||||
mycommon.myprint(" WARNING : impossible d'envoyer la convention au client : "+str( single_client))
|
||||
|
||||
|
||||
# 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']
|
||||
|
||||
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 = []
|
||||
|
||||
|
||||
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 "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction envoie les conventions par client
|
||||
"""
|
||||
|
||||
def Send_Convention_From_Session_By_Email(tab_files, Folder, diction):
|
||||
try:
|
||||
|
||||
|
||||
return True, " La convention a été correctement envoyée par email"
|
||||
|
||||
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 "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction envoie les convention à des stagiaires sans rattachement a des clients
|
||||
"""
|
|
@ -331,8 +331,6 @@ def Add_Update_Agenda_Event_Stagiaire(diction):
|
|||
|
||||
return True, " L'événement a été ajouté"
|
||||
|
||||
|
||||
|
||||
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))
|
||||
|
|
|
@ -29,7 +29,7 @@ Ajout d'un apprenant.
|
|||
La clé est l'adresse email
|
||||
"""
|
||||
|
||||
- log historique dans les fonction
|
||||
# xxxx - log historique dans les fonction
|
||||
def Add_Apprenant(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
@ -511,11 +511,12 @@ def Apprenant_Inscrire_Session(diction):
|
|||
new_data['update_by'] = str(my_partner['_id'])
|
||||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||||
|
||||
|
||||
# Reste à faire :
|
||||
"""
|
||||
# Reste à faire : xxxx
|
||||
- ajout dans la collection 'inscription'
|
||||
- log historique
|
||||
- envoie email inscription
|
||||
"""
|
||||
|
||||
return True
|
||||
|
||||
|
|
107
class_mgt.py
107
class_mgt.py
|
@ -48,7 +48,7 @@ def add_class(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel',
|
||||
field_list = ['external_code', 'title', 'description', 'institut_formation', 'distantiel', 'presentiel',
|
||||
'price', 'url','duration', 'duration_unit', 'token', 'plus_produit', 'mots_cle','domaine',
|
||||
'internal_url', 'zone_diffusion', 'metier', 'published', 'img_url', 'objectif',
|
||||
'programme', 'prerequis', 'note', 'cpf', 'certif', 'class_inscription_url', 'pourqui',
|
||||
|
@ -64,7 +64,7 @@ def add_class(diction):
|
|||
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
||||
On controle que les champs obligatoires sont presents dans la liste
|
||||
'''
|
||||
field_list_obligatoire = ['external_code', 'title', 'description', 'trainer', 'distantiel', 'presentiel', 'token']
|
||||
field_list_obligatoire = ['external_code', 'title', 'description', 'distantiel', 'presentiel', 'token']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -289,10 +289,6 @@ def add_class(diction):
|
|||
mydata['img_banner_detail_class'] = diction['img_banner_detail_class']
|
||||
|
||||
|
||||
if ("trainer" in diction.keys()):
|
||||
if diction['trainer']:
|
||||
mydata['trainer'] = diction['trainer']
|
||||
|
||||
if ("published" in diction.keys()):
|
||||
if diction['published']:
|
||||
mydata['published'] = diction['published']
|
||||
|
@ -576,7 +572,7 @@ def update_class(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel',
|
||||
field_list = ['external_code', 'title', 'description', 'institut_formation', 'distantiel',
|
||||
'presentiel','price', 'url', 'duration', 'token','plus_produit', 'mots_cle',
|
||||
'domaine', 'internal_code', 'internal_url','zone_diffusion', 'metier',
|
||||
'published', 'img_url', 'objectif', 'programme', 'prerequis', 'note',
|
||||
|
@ -745,9 +741,6 @@ def update_class(diction):
|
|||
diction['external_code']) + " a plus de " + str(MYSY_GV.CLASS_ZONE_DESCRIP_LIMIT) + " caractères"
|
||||
|
||||
|
||||
if ("trainer" in diction.keys()):
|
||||
mydata['trainer'] = diction['trainer']
|
||||
|
||||
if ("metier" in diction.keys()):
|
||||
mydata['metier'] = diction['metier']
|
||||
|
||||
|
@ -2933,12 +2926,6 @@ def add_class_mass(file=None, Folder=None, diction=None):
|
|||
return False, " - Le domaine '"+str(mydata['domaine'])+"' pour la formation à la ligne " + str(n + 2) +" n'est pas autorisé. Verifier la liste des domaines autorisés"
|
||||
|
||||
|
||||
formateur = ""
|
||||
if ("formateur" in df.keys()):
|
||||
if (str(df['formateur'].values[n])):
|
||||
formateur = str(df['formateur'].values[n]).strip()
|
||||
mydata['trainer'] = formateur
|
||||
|
||||
|
||||
institut_formation = ""
|
||||
if ("institut_formation" in df.keys()):
|
||||
|
@ -3076,7 +3063,7 @@ def add_class_mass(file=None, Folder=None, diction=None):
|
|||
formateur_email = ""
|
||||
formateur_id = ""
|
||||
if ("formateur_email" in df.keys()):
|
||||
if (str(df['formateur_email'].values[n])):
|
||||
if (str(df['formateur_email'].values[n]) and str(df['formateur_email'].values[n]).strip() != ""):
|
||||
|
||||
formateur_email = str(df['formateur_email'].values[n]).strip()
|
||||
if (mycommon.isEmailValide(formateur_email) is False):
|
||||
|
@ -3088,27 +3075,27 @@ def add_class_mass(file=None, Folder=None, diction=None):
|
|||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide."
|
||||
|
||||
is_formateur_email_ok = MYSY_GV.dbname['ressource_humaine'].count_documents({'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
if (is_formateur_email_ok <= 0):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2).")
|
||||
return False, " L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2)."
|
||||
is_formateur_email_ok = MYSY_GV.dbname['ressource_humaine'].count_documents({'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
if (is_formateur_email_ok <= 0):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2).")
|
||||
return False, " L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2)."
|
||||
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
|
||||
formateur_id = str(formateur_data['_id'])
|
||||
formateur_id = str(formateur_data['_id'])
|
||||
|
||||
mydata['formateur_id'] = formateur_id
|
||||
|
||||
|
@ -3397,10 +3384,6 @@ def Controle_add_class_mass(saved_file=None, Folder=None, diction=None):
|
|||
n + 2) + " n'est pas autorisé. Verifier la liste des domaines autorisés"
|
||||
|
||||
formateur = ""
|
||||
if ("formateur" in df.keys()):
|
||||
if (str(df['formateur'].values[n])):
|
||||
formateur = str(df['formateur'].values[n]).strip()
|
||||
mydata['trainer'] = formateur
|
||||
|
||||
institut_formation = ""
|
||||
if ("institut_formation" in df.keys()):
|
||||
|
@ -3411,33 +3394,45 @@ def Controle_add_class_mass(saved_file=None, Folder=None, diction=None):
|
|||
|
||||
# Verifier que l'adresse email du formateur est valide
|
||||
formateur_email = ""
|
||||
formateur_id = ""
|
||||
if ("formateur_email" in df.keys()):
|
||||
if (str(df['formateur_email'].values[n])):
|
||||
if (str(df['formateur_email'].values[n]) and str(df['formateur_email'].values[n]).strip() != ""):
|
||||
|
||||
formateur_email = str(df['formateur_email'].values[n]).strip()
|
||||
if (mycommon.isEmailValide(formateur_email) is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(formateur_email) + "' pour la formation à la ligne " + str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide.")
|
||||
return False, " L'email du formateur '" + str(formateur_email) + "' pour la formation à la ligne " + str(
|
||||
return False, " L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide."
|
||||
|
||||
is_formateur_email_ok = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
||||
{'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
if (is_formateur_email_ok <= 0):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2).")
|
||||
return False, " L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2)."
|
||||
|
||||
is_formateur_email_ok = MYSY_GV.dbname['ressource_humaine'].count_documents({'email':formateur_email,
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_recid':str(user_recid)})
|
||||
if( is_formateur_email_ok <= 0 ):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " - L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2).")
|
||||
return False, " L'email du formateur '" + str(
|
||||
formateur_email) + "' pour la formation à la ligne " + str(
|
||||
n + 2) + " n'est pas valide (2)."
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one({'email': formateur_email,
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(
|
||||
user_recid)})
|
||||
|
||||
formateur_id = str(formateur_data['_id'])
|
||||
|
||||
mydata['formateur_id'] = formateur_id
|
||||
|
||||
mydata['formateur_email'] = formateur_email
|
||||
|
||||
# mydata['duration'] = float(str(df['duree'].values[n]))
|
||||
|
||||
|
|
80
main.py
80
main.py
|
@ -2123,6 +2123,28 @@ def Duplicate_List_Session_Formation():
|
|||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
|
||||
"""
|
||||
API : pour préprer et envoyer les convention en partant d'une session
|
||||
"""
|
||||
@app.route('/myclass/api/Prepare_and_Send_Convention_From_Session_By_Email/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_and_Send_Convention_From_Session_By_Email():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Prepare_Convention_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_Convention_From_Session_By_Email(tab_files, MYSY_GV.TEMPORARY_DIRECTORY_V2, payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API de generation de liste PDF des liste d'emargement
|
||||
|
@ -4068,6 +4090,51 @@ def Download_Convention_Stagiaire_PDF(token, inscription_id, courrier_template_i
|
|||
else:
|
||||
return False
|
||||
|
||||
"""
|
||||
API qui permet de telecharger la convention en mode PDF en partant du client (donc liste partipant dans le fichier)
|
||||
"""
|
||||
@app.route('/myclass/api/Download_Convention_Stagiaire_PDF_By_Partner_client/<token>/<partner_client_id>/<session_id>/<courrier_template_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Download_Convention_Stagiaire_PDF_By_Partner_client(token, partner_client_id, session_id, courrier_template_id):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary(request.form.to_dict())
|
||||
payload['token'] = str(token)
|
||||
payload['partner_client_id'] = str(partner_client_id)
|
||||
payload['session_id'] = str(session_id)
|
||||
payload['courrier_template_id'] = str(courrier_template_id)
|
||||
|
||||
|
||||
print(" ### Download_Convention_Stagiaire_PDF_By_Partner_client payload = ",payload)
|
||||
|
||||
status, retval = inscription.Download_Convention_Stagiaire_PDF_By_Partner_client(payload)
|
||||
if (status):
|
||||
return retval
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
API qui prend une session id et imprime les differentes conventions associées en pfd
|
||||
"""
|
||||
@app.route('/myclass/api/Download_Convention_Stagiaire_PDF_By_Partner_client/<token>/<partner_client_id>/<session_id>/<courrier_template_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Prepare_Download_Convention_Stagiaire_PDF_By_Session(token, partner_client_id, session_id, courrier_template_id):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary(request.form.to_dict())
|
||||
payload['token'] = str(token)
|
||||
payload['partner_client_id'] = str(partner_client_id)
|
||||
payload['session_id'] = str(session_id)
|
||||
payload['courrier_template_id'] = str(courrier_template_id)
|
||||
|
||||
|
||||
print(" ### Download_Convention_Stagiaire_PDF_By_Partner_client payload = ",payload)
|
||||
|
||||
status, retval = inscription.Download_Convention_Stagiaire_PDF_By_Partner_client(payload)
|
||||
if (status):
|
||||
return retval
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
API qui retourne la liste des adresse email eligibles à la communication
|
||||
|
@ -6082,6 +6149,19 @@ def clean_session_dates():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
Test perso
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Dictionnary_data_For_Template/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Dictionnary_data_For_Template():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### clean_session_dates payload = ",payload)
|
||||
status, retval = mycommon.Get_Dictionnary_data_For_Template(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
|
@ -124,135 +124,137 @@ def Add_Partner_Client(diction):
|
|||
if ("raison_sociale" in diction.keys()):
|
||||
if diction['raison_sociale']:
|
||||
raison_sociale = diction['raison_sociale']
|
||||
data['raison_sociale'] = diction['raison_sociale']
|
||||
data['raison_sociale'] = diction['raison_sociale']
|
||||
|
||||
nom = ""
|
||||
if ("nom" in diction.keys()):
|
||||
if diction['nom']:
|
||||
nom = diction['nom']
|
||||
data['nom'] = diction['nom']
|
||||
data['nom'] = nom
|
||||
|
||||
siret = ""
|
||||
if ("siret" in diction.keys()):
|
||||
if diction['siret']:
|
||||
siret = diction['siret']
|
||||
data['siret'] = diction['siret']
|
||||
data['siret'] = siret
|
||||
|
||||
adr_adresse = ""
|
||||
if ("adr_adresse" in diction.keys()):
|
||||
if diction['adr_adresse']:
|
||||
adr_adresse = diction['adr_adresse']
|
||||
data['adr_adresse'] = diction['adr_adresse']
|
||||
data['adr_adresse'] = adr_adresse
|
||||
|
||||
adr_code_postal = ""
|
||||
if ("adr_code_postal" in diction.keys()):
|
||||
if diction['adr_code_postal']:
|
||||
adr_code_postal = diction['adr_code_postal']
|
||||
data['adr_code_postal'] = diction['adr_code_postal']
|
||||
data['adr_code_postal'] = adr_code_postal
|
||||
|
||||
adr_ville = ""
|
||||
if ("adr_ville" in diction.keys()):
|
||||
if diction['adr_ville']:
|
||||
adr_ville = diction['adr_ville']
|
||||
data['adr_ville'] = diction['adr_ville']
|
||||
data['adr_ville'] = adr_ville
|
||||
|
||||
adr_pays = ""
|
||||
if ("adr_pays" in diction.keys()):
|
||||
if diction['adr_pays']:
|
||||
adr_pays = diction['siret']
|
||||
data['adr_pays'] = diction['adr_pays']
|
||||
data['adr_pays'] = adr_pays
|
||||
|
||||
tva = ""
|
||||
if ("tva" in diction.keys()):
|
||||
if diction['tva']:
|
||||
tva = diction['tva']
|
||||
data['tva'] = diction['tva']
|
||||
data['tva'] = tva
|
||||
|
||||
email = ""
|
||||
if ("email" in diction.keys()):
|
||||
if diction['email']:
|
||||
email = diction['email']
|
||||
data['email'] = diction['email']
|
||||
|
||||
if( mycommon.isEmailValide(email) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
||||
|
||||
return False, " - L'adresse email "+str(email)+" n'est pas valide "
|
||||
data['email'] = email
|
||||
|
||||
|
||||
telephone = ""
|
||||
if ("telephone" in diction.keys()):
|
||||
if diction['telephone']:
|
||||
telephone = diction['telephone']
|
||||
data['telephone'] = diction['telephone']
|
||||
data['telephone'] = telephone
|
||||
|
||||
|
||||
website = ""
|
||||
if ("website" in diction.keys()):
|
||||
if diction['website']:
|
||||
website = diction['website']
|
||||
data['website'] = diction['website']
|
||||
data['website'] = website
|
||||
|
||||
comment = ""
|
||||
if ("comment" in diction.keys()):
|
||||
if diction['comment']:
|
||||
comment = diction['comment']
|
||||
data['comment'] = diction['comment']
|
||||
data['comment'] = comment
|
||||
|
||||
invoice_email = ""
|
||||
if ("invoice_email" in diction.keys()):
|
||||
if diction['invoice_email']:
|
||||
invoice_email = diction['invoice_email']
|
||||
data['invoice_email'] = diction['invoice_email']
|
||||
|
||||
if (mycommon.isEmailValide(invoice_email) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide")
|
||||
|
||||
return False, " - L'adresse email de facturation '" + str(invoice_email) + "' n'est pas valide "
|
||||
data['invoice_email'] = invoice_email
|
||||
|
||||
invoice_nom = ""
|
||||
if ("invoice_nom" in diction.keys()):
|
||||
if diction['invoice_nom']:
|
||||
invoice_nom = diction['invoice_nom']
|
||||
data['invoice_nom'] = diction['invoice_nom']
|
||||
data['invoice_nom'] = invoice_nom
|
||||
|
||||
invoice_siret = ""
|
||||
if ("invoice_siret" in diction.keys()):
|
||||
if diction['invoice_siret']:
|
||||
invoice_siret = diction['invoice_siret']
|
||||
data['invoice_siret'] = diction['invoice_siret']
|
||||
data['invoice_siret'] = invoice_siret
|
||||
|
||||
invoice_tva = ""
|
||||
if ("invoice_tva" in diction.keys()):
|
||||
if diction['invoice_tva']:
|
||||
invoice_tva = diction['invoice_tva']
|
||||
data['invoice_tva'] = diction['invoice_tva']
|
||||
data['invoice_tva'] = invoice_tva
|
||||
|
||||
invoice_adresse = ""
|
||||
if ("invoice_adresse" in diction.keys()):
|
||||
if diction['invoice_adresse']:
|
||||
invoice_adresse = diction['invoice_adresse']
|
||||
data['invoice_adresse'] = diction['invoice_adresse']
|
||||
data['invoice_adresse'] = invoice_adresse
|
||||
|
||||
invoice_ville = ""
|
||||
if ("invoice_ville" in diction.keys()):
|
||||
if diction['invoice_ville']:
|
||||
invoice_ville = diction['invoice_ville']
|
||||
data['invoice_ville'] = diction['invoice_ville']
|
||||
data['invoice_ville'] =invoice_ville
|
||||
|
||||
invoice_code_postal = ""
|
||||
if ("invoice_code_postal" in diction.keys()):
|
||||
if diction['invoice_code_postal']:
|
||||
invoice_code_postal = diction['invoice_code_postal']
|
||||
data['invoice_code_postal'] = diction['invoice_code_postal']
|
||||
data['invoice_code_postal'] = invoice_code_postal
|
||||
|
||||
invoice_pays = ""
|
||||
if ("invoice_pays" in diction.keys()):
|
||||
if diction['invoice_pays']:
|
||||
invoice_pays = diction['invoice_pays']
|
||||
data['invoice_pays'] = diction['invoice_pays']
|
||||
data['invoice_pays'] = invoice_pays
|
||||
|
||||
list_adress = []
|
||||
line = 0
|
||||
|
@ -302,11 +304,12 @@ def Add_Partner_Client(diction):
|
|||
if ("list_contact" in diction.keys()):
|
||||
if diction['list_contact']:
|
||||
list_contact = diction['list_contact']
|
||||
data['list_contact'] = diction['list_contact']
|
||||
data['list_contact'] = list_contact
|
||||
|
||||
data['valide'] = '1'
|
||||
data['locked'] = '0'
|
||||
data['date_update'] = str(datetime.now())
|
||||
data['update_by'] = str(my_partner['_id'])
|
||||
|
||||
# Creation du RecId
|
||||
data['recid'] = mycommon.create_user_recid()
|
||||
|
@ -450,7 +453,7 @@ def Update_Partner_Client(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', "raison_sociale", "nom", "siret", "tva", "email",
|
||||
field_list = ['token', "_id", "raison_sociale", "nom", "siret", "tva", "email",
|
||||
"telephone", "website", "comment", "address", "invoice_address", "list_contact",
|
||||
'adr_adresse', 'adr_code_postal', 'adr_ville', 'adr_pays',
|
||||
'invoice_email', 'invoice_nom', 'invoice_siret',
|
||||
|
@ -467,7 +470,7 @@ def Update_Partner_Client(diction):
|
|||
"""
|
||||
Verification des champs obligatoires
|
||||
"""
|
||||
field_list_obligatoire = ['token', "nom", "email", ]
|
||||
field_list_obligatoire = ['token', "_id" ]
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -484,45 +487,27 @@ def Update_Partner_Client(diction):
|
|||
if diction['token']:
|
||||
token = diction['token']
|
||||
|
||||
# Verifier la validité du token
|
||||
retval = mycommon.check_partner_token_validity("", token)
|
||||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data({'token':str(token)})
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
if retval is False:
|
||||
return "Err_Connexion", " La session de connexion n'est pas valide"
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
||||
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
||||
|
||||
"""
|
||||
Verification s'il n'existe pas un cient du partenaire qui perte le meme
|
||||
nom, ou la meme adresse email
|
||||
"""
|
||||
|
||||
qry_update = { "$or":[{'nom': str(diction['nom']), 'email': str(diction['email']),
|
||||
'valide': '1', 'partner_recid': str(my_partner['recid'])},
|
||||
|
||||
{'email': str(diction['email']),
|
||||
'valide': '1', 'partner_recid': str(my_partner['recid'])}
|
||||
]}
|
||||
qry_update = {"_id":ObjectId(str(diction['_id'])), 'valide':'1', 'locked':'0',
|
||||
'partner_recid':str(my_partner['recid'])}
|
||||
|
||||
|
||||
print(" ### qry_update = ", qry_update)
|
||||
|
||||
#print(" ### qry_update = ", qry_update)
|
||||
tmp_count = MYSY_GV.dbname['partner_client'].count_documents(qry_update)
|
||||
if (tmp_count <= 0):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Ce client n'existe pas: nom = "+str(diction['nom']))
|
||||
|
||||
return False, " - Ce client n'existe pas, mise à jour impossible "
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " L'identifiant du client est invalide ")
|
||||
return False, " L'identifiant du client est invalide "
|
||||
|
||||
|
||||
|
||||
|
@ -543,7 +528,14 @@ def Update_Partner_Client(diction):
|
|||
nom = ""
|
||||
if ("nom" in diction.keys()):
|
||||
nom = diction['nom']
|
||||
# data_update['nom'] = diction['nom'] - on ne modifie pas le nom
|
||||
data_update['nom'] = diction['nom']
|
||||
|
||||
# Le nom est un champ obligatoire
|
||||
if( str(nom).strip() == ""):
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " Le nom du client est vide ")
|
||||
return False, " Le nom du client est vide "
|
||||
|
||||
|
||||
siret = ""
|
||||
if ("siret" in diction.keys()):
|
||||
|
@ -585,7 +577,20 @@ def Update_Partner_Client(diction):
|
|||
email = ""
|
||||
if ("email" in diction.keys()):
|
||||
email = diction['email']
|
||||
# data_update['email'] = diction['email'] - on ne modifie pas le mail
|
||||
data_update['email'] = diction['email']
|
||||
# L'adresse email est obligatoire
|
||||
if (str(email).strip() == ""):
|
||||
mycommon.myprint(str(inspect.stack()[0][
|
||||
3]) + " L'adresse email du client est vide ")
|
||||
return False, " L'adresse email du client est vide "
|
||||
|
||||
if (mycommon.isEmailValide(email) is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - L'adresse email " + str(email) + " n'est pas valide")
|
||||
|
||||
return False, " - L'adresse email " + str(email) + " n'est pas valide "
|
||||
|
||||
|
||||
invoice_email = ""
|
||||
if ("invoice_email" in diction.keys()):
|
||||
|
@ -686,14 +691,14 @@ def Update_Partner_Client(diction):
|
|||
data_update['valide'] = '1'
|
||||
data_update['locked'] = '0'
|
||||
data_update['date_update'] = str(datetime.now())
|
||||
data_update['update_by'] = str(my_partner['_id'])
|
||||
|
||||
"""
|
||||
Clés de mise à jour
|
||||
"""
|
||||
data_cle = {}
|
||||
data_cle['partner_recid'] = str(my_partner['recid'])
|
||||
data_cle['email'] = str(diction['email'])
|
||||
data_cle['nom'] = str(diction['nom'])
|
||||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||||
data_cle['valide'] = "1"
|
||||
data_cle['locked'] = "0"
|
||||
|
||||
|
@ -704,12 +709,14 @@ def Update_Partner_Client(diction):
|
|||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
if ("_id" not in result.keys()):
|
||||
|
||||
print(" ###result = ", result)
|
||||
if (result is None):
|
||||
mycommon.myprint(
|
||||
" Impossible de mettre à jour le client : email = " + str(diction['email']))
|
||||
return False, " Impossible de mettre à jour le client "
|
||||
|
||||
return True, " Le client a été correctement mise à jour"
|
||||
return True, " Le client a été correctement mis à jour"
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
|
@ -857,7 +864,7 @@ def Get_Given_Partner_Client(diction):
|
|||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
print(" ### data_cle = ", data_cle)
|
||||
print(" ### data_cle 1 = ", data_cle)
|
||||
for retval in MYSY_GV.dbname['partner_client'].find(data_cle):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
|
@ -935,7 +942,7 @@ def Get_Given_Partner_Client_From_Id(diction):
|
|||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
print(" ### data_cle = ", data_cle)
|
||||
print(" ### data_cle 2= ", data_cle)
|
||||
for retval in MYSY_GV.dbname['partner_client'].find(data_cle):
|
||||
user = retval
|
||||
user['id'] = str(val_tmp)
|
||||
|
|
267
prj_common.py
267
prj_common.py
|
@ -3928,3 +3928,270 @@ def clean_session_dates():
|
|||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " impossible de faire clean_date"
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction retourne les champs a utiliser pour les template de document/
|
||||
Cette fonction retour un json de ce type :
|
||||
|
||||
convention_dictionnary_data =
|
||||
{
|
||||
{'connected_user_data':{'email':'toto@.fr', 'contact_nom':'balde'}}
|
||||
{'company_data':{'num_nda':'1234', 'website':'www.ssds.fr'}
|
||||
{'class_data':{....}}
|
||||
{'list_session_data':{....}}
|
||||
{'list_stagiaire_data':[{...}]}
|
||||
{'systeme':{'date_jour':'11/02/2023'}}
|
||||
|
||||
}
|
||||
Elle prend en argument : token, stagiaire_id, session_id, class_id
|
||||
|
||||
"""
|
||||
def Get_Dictionnary_data_For_Template(diction):
|
||||
try:
|
||||
diction = strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'list_stagiaire_id', 'list_session_id', 'list_class_id', 'list_client_id']
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list and val.startswith('my_') is False:
|
||||
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', 'list_stagiaire_id', 'list_session_id', 'list_class_id', 'list_client_id']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
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 = Check_Connexion_And_Return_Partner_Data(diction)
|
||||
if (local_status is not True):
|
||||
return local_status, my_partner
|
||||
|
||||
dictionnary_data = {}
|
||||
connected_user_data = {}
|
||||
|
||||
"""
|
||||
Traitement des données du : connected_user_data
|
||||
"""
|
||||
connected_user_liste_champ = ['email', 'contact_nom', 'contact_prenom']
|
||||
for champ in connected_user_liste_champ:
|
||||
if (champ in my_partner):
|
||||
new_champ_name = "connected_user_" + str(champ)
|
||||
new_field = {new_champ_name: str(my_partner[champ])}
|
||||
connected_user_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "connected_user_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
connected_user_data.update(new_field)
|
||||
|
||||
dictionnary_data['connected_user_data'] = connected_user_data
|
||||
|
||||
"""
|
||||
Recuperartion des champs de la société à laquelle est rattaché l'utilisateur
|
||||
"""
|
||||
# Recuperation des données du partenaire associé à l'utilisateur connecté
|
||||
local_status, local_retval = Get_Connected_User_Partner_Data_From_RecID(my_partner['recid'])
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
|
||||
local_company_data = local_retval
|
||||
company_data = {}
|
||||
|
||||
company_liste_champ = ['nom', 'email', 'num_nda', 'website', 'adr_street', 'adr_zip', 'adr_city', 'adr_country']
|
||||
for champ in company_liste_champ:
|
||||
if (champ in local_company_data):
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: str(local_company_data[champ])}
|
||||
company_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "societe_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
company_data.update(new_field)
|
||||
|
||||
dictionnary_data['company_data'] = company_data
|
||||
|
||||
"""
|
||||
Recuperartion des champs des stagiaires
|
||||
"""
|
||||
session_liste_champ = ['code_session', 'class_internal_url', 'date_debut', 'session_etape', 'date_fin',
|
||||
'distantiel', 'presentiel', 'session_ondemande', 'nb_participant',
|
||||
'prix_session', 'titre', 'location_type', 'is_bpf', 'formateur_id', 'adresse',
|
||||
'code_postal', 'ville', 'pays', 'date_debut_inscription', 'date_fin_inscription',
|
||||
'formateur_nom_prenom']
|
||||
list_session_data = []
|
||||
tab_session_id = diction['list_session_id']
|
||||
|
||||
for session_data in MYSY_GV.dbname['session_formation'].find( {'_id': {'$in': tab_session_id, } ,
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])
|
||||
}):
|
||||
|
||||
formateur_nom_prenom = ""
|
||||
# Si il y a un code formateur_id, alors on va recuperer les nom et prenom du formation
|
||||
if ("formateur_id" in session_data.keys() and session_data['formateur_id']):
|
||||
|
||||
formateur_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||||
{'_id': ObjectId(str(session_data['formateur_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_recid': str(my_partner['recid'])
|
||||
})
|
||||
|
||||
if (formateur_data and "nom" in formateur_data.keys() and "prenom" in formateur_data.keys()):
|
||||
formateur_nom_prenom = str(formateur_data['nom']) + " " + str(formateur_data['prenom'])
|
||||
|
||||
session_data['formateur_nom_prenom'] = formateur_nom_prenom
|
||||
|
||||
new_session_data = {}
|
||||
for champ in session_liste_champ:
|
||||
if (champ in session_data):
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: str(session_data[champ])}
|
||||
new_session_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "session_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
new_session_data.update(new_field)
|
||||
|
||||
list_session_data.append(new_session_data)
|
||||
|
||||
dictionnary_data['list_session_data'] = list_session_data
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Recuperartion des champs des stagiaire
|
||||
"""
|
||||
list_stagiaire_data = []
|
||||
tab_stagiaire_id = diction['list_stagiaire_id']
|
||||
|
||||
|
||||
stagiaire_liste_champ = ['email', 'nom', 'prenom', 'telephone', 'client_rattachement_id', 'employeur',
|
||||
'modefinancement', 'tuteur1_adresse', 'tuteur1_cp', 'tuteur1_email', 'tuteur1_nom',
|
||||
'tuteur1_pays', 'tuteur1_telephone', 'tuteur1_ville', 'tuteur1_prenom',
|
||||
'tuteur2_adresse', 'tuteur2_cp', 'tuteur2_email', 'tuteur2_nom', 'tuteur2_pays',
|
||||
'tuteur2_prenom',
|
||||
'tuteur2_telephone', 'tuteur2_ville','adresse', 'code_postal', 'ville', 'pays']
|
||||
|
||||
|
||||
for stagiaire_data in MYSY_GV.dbname['inscription'].find({'_id': {'$in': tab_stagiaire_id, },
|
||||
'status': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])
|
||||
}):
|
||||
|
||||
new_stagiaire_data = {}
|
||||
for champ in stagiaire_liste_champ:
|
||||
if (champ in stagiaire_data):
|
||||
new_champ_name = "stagiaire_" + str(champ)
|
||||
new_field = {new_champ_name: str(stagiaire_data[champ])}
|
||||
new_stagiaire_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "stagiaire_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
new_stagiaire_data.update(new_field)
|
||||
|
||||
list_stagiaire_data.append(new_stagiaire_data)
|
||||
|
||||
dictionnary_data['list_stagiaire_data'] = list_stagiaire_data
|
||||
|
||||
|
||||
"""
|
||||
Recuperartion des champs des formation
|
||||
"""
|
||||
list_myclass_data = []
|
||||
tab_myclass_id = diction['list_class_id']
|
||||
|
||||
myclass_liste_champ = ['certif', 'cpf', 'metier', 'objectif', 'title', 'duration', 'duration_unit']
|
||||
|
||||
for myclass_data in MYSY_GV.dbname['myclass'].find({'_id': {'$in': tab_myclass_id, },
|
||||
'valide': '1',
|
||||
'partner_owner_recid': str(my_partner['recid'])
|
||||
}):
|
||||
|
||||
new_myclass_data = {}
|
||||
for champ in myclass_liste_champ:
|
||||
if (champ in myclass_data):
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: str(myclass_data[champ])}
|
||||
new_myclass_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "formation_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
new_myclass_data.update(new_field)
|
||||
|
||||
list_myclass_data.append(new_myclass_data)
|
||||
|
||||
|
||||
dictionnary_data['list_class_data'] = list_myclass_data
|
||||
|
||||
"""
|
||||
Recuperartion des champs des clients
|
||||
"""
|
||||
list_client_data = []
|
||||
tab_client_id = diction['list_client_id']
|
||||
|
||||
client_liste_champ = ['raison_sociale', 'nom', 'email', 'adr_adresse', 'adr_code_postal', 'adr_code_postal', 'adr_pays']
|
||||
|
||||
for client_data in MYSY_GV.dbname['partner_client'].find({'_id': {'$in': tab_client_id, },
|
||||
'valide': '1',
|
||||
'partner_recid': str(my_partner['recid'])
|
||||
}):
|
||||
|
||||
new_client_data = {}
|
||||
for champ in client_liste_champ:
|
||||
if (champ in client_data):
|
||||
new_champ_name = "client_" + str(champ)
|
||||
new_field = {new_champ_name: str(client_data[champ])}
|
||||
new_client_data.update(new_field)
|
||||
else:
|
||||
new_champ_name = "client_" + str(champ)
|
||||
new_field = {new_champ_name: ""}
|
||||
new_client_data.update(new_field)
|
||||
|
||||
list_client_data.append(new_client_data)
|
||||
|
||||
dictionnary_data['list_client_data'] = list_client_data
|
||||
|
||||
|
||||
# Recuperation des données système
|
||||
# Ajout des champs système comme la date du jour
|
||||
systeme_data = {}
|
||||
|
||||
ct = datetime.now()
|
||||
ts = ct.timestamp()
|
||||
date_jour = ct.strftime("%d/%m/%Y")
|
||||
new_field = {"date_jour": str(date_jour)}
|
||||
systeme_data.update(new_field)
|
||||
dictionnary_data['systeme_data'] = systeme_data
|
||||
|
||||
|
||||
return True, dictionnary_data
|
||||
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récupérer le dictionnaire pour les template"
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue