4827 lines
204 KiB
Python
4827 lines
204 KiB
Python
"""
|
||
Ce fichier permet de gerer les jurys qui delibere sur l'optention des diplome
|
||
|
||
use case cherif :
|
||
Le jury affiche les note de l'apprenant a l'ecran, discute, donne un avis et modifie la note si besoin
|
||
|
||
memo :
|
||
0 - Le Président du jury et un suppléant sont clairement designés
|
||
1 - un jury, en examinant un candidat doit voir les evaluations concernée
|
||
2 - Il est compétent pour modifier, à la hausse ou à la baisse, les notes proposées par les correcteurs. Seules les notes arrêtées par le jury sont définitives.
|
||
3 - À l’issue de la délibération, le président et les membres du jury présents, signent le procès-verbal de délibération. (PV de sceance doit etre securisé)
|
||
4 - Il faudra jouter le seceancs planifié avec session concernées (une vue agenda serait sympa)
|
||
|
||
"""
|
||
import ast
|
||
from zipfile import ZipFile
|
||
import Inscription_mgt as Inscription_mgt
|
||
import bson
|
||
import pymongo
|
||
import xlsxwriter
|
||
from pymongo import MongoClient
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
from datetime import datetime, date
|
||
|
||
import module_editique
|
||
import partner_client
|
||
import prj_common as mycommon
|
||
import secrets
|
||
import inspect
|
||
import sys, os
|
||
import csv
|
||
import pandas as pd
|
||
from pymongo import ReturnDocument
|
||
import GlobalVariable as MYSY_GV
|
||
from math import isnan
|
||
import GlobalVariable as MYSY_GV
|
||
import ela_index_bdd_classes as eibdd
|
||
import email_mgt as email
|
||
import jinja2
|
||
from flask import send_file
|
||
from xhtml2pdf import pisa
|
||
from email.message import EmailMessage
|
||
from email.mime.text import MIMEText
|
||
from email import encoders
|
||
import smtplib
|
||
from email.mime.multipart import MIMEMultipart
|
||
from email.mime.text import MIMEText
|
||
from email.mime.base import MIMEBase
|
||
from email import encoders
|
||
import attached_file_mgt
|
||
|
||
"""
|
||
Ajout d'un jury
|
||
"""
|
||
def Add_Jury(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'code', 'description', 'comment', 'responsable_id',
|
||
'session_id', 'email_jury', 'chef_jury_id', 'session_id',
|
||
'ue_id', 'cible', 'adresse', 'code_postal', 'ville', 'pays',
|
||
'site_formation_id', 'jury_salle']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'code', ]
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
"""
|
||
Si responsable_id, alors verifier la validité
|
||
"""
|
||
if( 'responsable_id' in diction.keys() and diction['responsable_id']):
|
||
is_valide_responsable = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
||
{'_id': ObjectId(str(diction['responsable_id'])),
|
||
'partner_recid': my_partner[
|
||
'recid'],
|
||
'valide': '1',
|
||
'locked': '0'})
|
||
|
||
if (is_valide_responsable != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du responsable de l'évaluation est invalide ")
|
||
return False, " L'identifiant du responsable de l'évaluation est invalide "
|
||
|
||
|
||
"""
|
||
Si session_id, verifier la validité de la session
|
||
"""
|
||
if ('session_id' in diction.keys() and diction['session_id']):
|
||
is_valide_session_id = MYSY_GV.dbname['session_formation'].count_documents(
|
||
{'_id': ObjectId(str(diction['session_id'])),
|
||
'partner_owner_recid': my_partner[
|
||
'recid'],
|
||
'valide': '1',
|
||
})
|
||
|
||
if (is_valide_session_id != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la session (class) est invalide ")
|
||
return False, " L'identifiant de la session (class) est invalide "
|
||
|
||
|
||
# Verifier si le chef d'equipe existe
|
||
if ("chef_jury_id" in diction.keys() and diction['chef_jury_id']):
|
||
# Verifier que l'id du chef d'equipe est valide
|
||
|
||
|
||
|
||
is_chef_equipe_id_count = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
||
{'_id': ObjectId(str(diction['chef_jury_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_chef_equipe_id_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du chef du jury est invalide ")
|
||
return False, " L'identifiant du chef du jury est invalide "
|
||
|
||
# Verifier si l'UE existe
|
||
if ("ue_id" in diction.keys() and diction['ue_id']):
|
||
# Verifier que l'id du chef d'equipe est valide
|
||
|
||
is_ue_id_id_count = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
||
{'_id': ObjectId(str(diction['ue_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_ue_id_id_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'UE est invalide ")
|
||
return False, " L'identifiant de l'UE est invalide "
|
||
|
||
|
||
if ("email_jury" in diction.keys() and diction['email_jury']):
|
||
if (mycommon.isEmailValide(str(diction['email_jury'])) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'adresse email du jury est invalide ")
|
||
return False, " L'adresse email du jury est invalide "
|
||
|
||
mytoken = diction['token']
|
||
new_data = diction
|
||
del diction['token']
|
||
|
||
# Initialisation des champs non envoyés à vide
|
||
for val in field_list:
|
||
if val not in diction.keys():
|
||
new_data[str(val)] = ""
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
|
||
new_data['create_date'] = str(datetime.now())
|
||
new_data['created_by'] = str(my_partner['_id'])
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
inserted_id = MYSY_GV.dbname['jury'].insert_one(new_data).inserted_id
|
||
if (not inserted_id):
|
||
mycommon.myprint(
|
||
" Impossible de créer le jury (2) ")
|
||
return False, " Impossible de créer le jury (2) "
|
||
|
||
|
||
|
||
"""
|
||
Après la création du jury, on ajoute le chef d'équipe dans liste de membres
|
||
"""
|
||
if( "chef_jury_id" in diction.keys() and diction['chef_jury_id']):
|
||
new_data = {}
|
||
new_data['jury_id'] = str(inserted_id)
|
||
new_data['rh_id'] = str(diction['chef_jury_id'])
|
||
|
||
now = str(datetime.now())
|
||
mytoday = datetime.today()
|
||
new_data['date_ajout_jury'] = str(mytoday)
|
||
|
||
new_data['date_update'] = now
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['leader'] = "1"
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['jury_id'] = str(diction['_id'])
|
||
data_cle['rh_id'] = str(diction['chef_jury_id'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
result = MYSY_GV.dbname['jury_membre'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (result is None or "_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" WARNING : Impossible d'ajouter le chef d'équipe")
|
||
|
||
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = mytoken
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(inserted_id)
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Creation jury "
|
||
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, " Le jury a été correctement ajoutée"
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de créer le jury "
|
||
|
||
|
||
"""
|
||
Ajouter une liste de membres à un jury
|
||
"""
|
||
def Add_Update_Jury_Membres(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id', 'tab_ressource_humaine_ids', 'role']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que l'équipe existe et est valide
|
||
|
||
qry = {'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])}
|
||
|
||
|
||
|
||
is_existe_groupe = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_groupe != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide "
|
||
|
||
|
||
tab_ressource_humaine_ids = ""
|
||
if ("tab_ressource_humaine_ids" in diction.keys()):
|
||
if diction['tab_ressource_humaine_ids']:
|
||
tab_ressource_humaine_ids = diction['tab_ressource_humaine_ids']
|
||
|
||
tab_ressource_humaine_ids_splited = str(tab_ressource_humaine_ids).split(",")
|
||
|
||
# Controle de validité des ressource_humaine
|
||
for my_ressource_humaine in tab_ressource_humaine_ids_splited:
|
||
# Verifier que l'inscription est valide
|
||
|
||
my_ressource_humaine_is_valide = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
||
{'_id': ObjectId(str(my_ressource_humaine)), 'valide': '1', 'locked':'0',
|
||
'partner_recid': str(my_partner['recid'])})
|
||
|
||
if (my_ressource_humaine_is_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la ressource humaine '" + my_ressource_humaine + "' est invalide ")
|
||
return False, " L'identifiant de la ressource humaine '" + my_ressource_humaine + "' est invalide "
|
||
|
||
cpt = 0
|
||
|
||
for my_ressource_humaine in tab_ressource_humaine_ids_splited:
|
||
new_data = {}
|
||
new_data['jury_id'] = str(diction['_id'])
|
||
new_data['rh_id'] = str(my_ressource_humaine)
|
||
|
||
if( "role" in diction.keys()):
|
||
new_data['role'] = str(diction['role'])[0:255]
|
||
else:
|
||
new_data['role'] = ""
|
||
|
||
now = str(datetime.now())
|
||
mytoday = datetime.today()
|
||
new_data['date_ajout_jury'] = str(mytoday)
|
||
|
||
new_data['date_update'] = now
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['jury_id'] = str(diction['_id'])
|
||
data_cle['rh_id'] = str(my_ressource_humaine)
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
result = MYSY_GV.dbname['jury_membre'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (result is None or "_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible d'inscrire les personnes au jury (2) ")
|
||
return False, " Impossible d'inscrire les personnes au jury (2) "
|
||
|
||
|
||
cpt = cpt + 1
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
|
||
history_event_dict['action_description'] = "Mise à jour des membres "
|
||
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, str(cpt)+ " Membre(s) inscrit(s)"
|
||
|
||
|
||
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'inscrire les personnes du jury "
|
||
|
||
|
||
"""
|
||
Cette fonction permet de supprimer des membres d'un jury
|
||
"""
|
||
def Delete_Jury_Membre(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'tab_ids']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'tab_ids']
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que l'equipe existe et est valide
|
||
is_existe_groupe = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_groupe != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'équipe est invalide ")
|
||
return False, " L'identifiant de l'équipe est invalide "
|
||
|
||
is_existe_groupe = MYSY_GV.dbname['jury'].find_one(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
update_team_leader = "0"
|
||
jury_chef_jury_id = ""
|
||
if (is_existe_groupe and "chef_jury_id" in is_existe_groupe):
|
||
jury_chef_jury_id = is_existe_groupe['chef_jury_id']
|
||
|
||
tab_jury_membre_ids = ""
|
||
if ("tab_ids" in diction.keys()):
|
||
if diction['tab_ids']:
|
||
tab_jury_membre_ids = diction['tab_ids']
|
||
|
||
tab_jury_membre_ids_splited = str(tab_jury_membre_ids).split(",")
|
||
|
||
tab_jury_membre_ids_splited_ObjectID = []
|
||
|
||
for tmp in tab_jury_membre_ids_splited:
|
||
if( tmp ):
|
||
tab_jury_membre_ids_splited_ObjectID.append(ObjectId(str(tmp)))
|
||
|
||
qery_delete = {'_id': {'$in': tab_jury_membre_ids_splited_ObjectID},
|
||
'jury_id': str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
'locked': '0'}
|
||
|
||
"""
|
||
Pour les log d'historique, recuperation des information sur les membres supprimés
|
||
- rh_id,
|
||
- email
|
||
|
||
et
|
||
Si la personne supprimée est le responsable, il faut alors mettre à vide le champ responsable sur la formation
|
||
"""
|
||
tab_delete_rh = []
|
||
for val in MYSY_GV.dbname['jury_membre'].find(qery_delete):
|
||
if (val and "rh_id" in val.keys()):
|
||
rh_id_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id': ObjectId(val['rh_id']),
|
||
'valide': '1', 'locked': '0',
|
||
'partner_recid': str(my_partner['recid']), })
|
||
node_delete_rh_id_data = {}
|
||
|
||
if (rh_id_data and '_id' in rh_id_data.keys() and 'email' in rh_id_data.keys()):
|
||
node_delete_rh_id_data['rh_id'] = rh_id_data['_id']
|
||
node_delete_rh_id_data['email'] = rh_id_data['email']
|
||
|
||
if (rh_id_data and 'nom' in rh_id_data.keys()):
|
||
node_delete_rh_id_data['nom'] = rh_id_data['nom']
|
||
|
||
if (rh_id_data and 'prenom' in rh_id_data.keys()):
|
||
node_delete_rh_id_data['prenom'] = rh_id_data['prenom']
|
||
|
||
tab_delete_rh.append(node_delete_rh_id_data)
|
||
|
||
"""
|
||
Si la personne supprimée est le responsable, il faut alors mettre à vide le champ responsable sur la formation
|
||
"""
|
||
if (str(rh_id_data['_id']) == jury_chef_jury_id):
|
||
result = MYSY_GV.dbname['jury'].find_one_and_update(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
|
||
{"$set": {"chef_jury_id": ""}},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
history_massage_light = ""
|
||
for val in tab_delete_rh:
|
||
if ("email" in val):
|
||
history_massage_light = str(val['email']) + ", " + str(history_massage_light)
|
||
|
||
# print(" ### qery_delete = ", qery_delete)
|
||
|
||
delete = MYSY_GV.dbname['jury_membre'].delete_many(qery_delete)
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['technical_comment'] = "Suppression membre(s) " + str(tab_delete_rh)
|
||
history_event_dict['action_description'] = "Suppression membre(s) " + str(history_massage_light)
|
||
|
||
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, str(delete.deleted_count) + " Membre(s) désinscrit(s)"
|
||
|
||
|
||
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ésinscrire les personnes du jury "
|
||
|
||
|
||
"""
|
||
Mise à jour d'un jury
|
||
"""
|
||
def Update_Jury(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'code', 'description', 'email_jury', 'chef_jury_id', '_id',
|
||
'session_id', 'cible', 'ue_id', 'adresse', 'code_postal', 'ville', 'pays',
|
||
'site_formation_id', 'jury_salle']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que l'équipe existe
|
||
is_existe_cdtion_paiement = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_cdtion_paiement != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'équipe est invalide ")
|
||
return False, " L'identifiant l'équipe est invalide "
|
||
|
||
|
||
# Verifier que ce code n'existe pas déjà
|
||
is_existe_jury = MYSY_GV.dbname['jury'].count_documents({'code': str(diction['code']),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(
|
||
my_partner['recid']),
|
||
"_id": {"$ne": ObjectId(str(diction['_id']))}
|
||
})
|
||
|
||
if (is_existe_jury > 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Une équipe avec le code '" + str(diction['code']) + "' existe déjà ")
|
||
return False, " Une équipe avec le code '" + str(diction['code']) + "' existe déjà "
|
||
|
||
# Verifier si le chef d'equipe existe
|
||
if ("chef_jury_id" in diction.keys() and diction['chef_jury_id']):
|
||
# Verifier que l'id du chef d'equipe est valide
|
||
is_chef_jury_id_count = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
||
{'_id': ObjectId(str(diction['chef_jury_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_chef_jury_id_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du chef d'équipe est invalide ")
|
||
return False, " L'identifiant du chef d'équipe est invalide "
|
||
|
||
# Verifier si l'UE existe
|
||
if ("ue_id" in diction.keys() and diction['ue_id']):
|
||
# Verifier que l'id du chef d'equipe est valide
|
||
|
||
is_ue_id_id_count = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
||
{'_id': ObjectId(str(diction['ue_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_ue_id_id_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'UE est invalide ")
|
||
return False, " L'identifiant de l'UE est invalide "
|
||
|
||
|
||
if ("email_jury" in diction.keys() and diction['email_jury']):
|
||
if (mycommon.isEmailValide(str(diction['email_jury'])) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'adresse email du jury est invalide ")
|
||
return False, " L'adresse email du jury est invalide "
|
||
|
||
"""
|
||
Si session_id, verifier la validité de la session
|
||
"""
|
||
if ('session_id' in diction.keys() and diction['session_id']):
|
||
is_valide_session_id = MYSY_GV.dbname['session_formation'].count_documents(
|
||
{'_id': ObjectId(str(diction['session_id'])),
|
||
'partner_owner_recid': my_partner[
|
||
'recid'],
|
||
'valide': '1',
|
||
})
|
||
|
||
if (is_valide_session_id != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la session (class) est invalide ")
|
||
return False, " L'identifiant de la session (class) est invalide "
|
||
|
||
|
||
local_id = str(diction['_id'])
|
||
mytoken = diction['token']
|
||
|
||
|
||
del diction['token']
|
||
del diction['_id']
|
||
|
||
new_data['date_update'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['_id'] = ObjectId(local_id)
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
result = MYSY_GV.dbname['jury'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if ("_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible de mettre à jour le jury (2) ")
|
||
return False, " Impossible de mettre à jour le jury (2) "
|
||
|
||
"""
|
||
Après la création du jury, on ajoute le chef d'équipe dans liste de membres
|
||
"""
|
||
if ("chef_jury_id" in diction.keys() and diction['chef_jury_id']):
|
||
new_data = {}
|
||
new_data['jury_id'] = str(local_id)
|
||
new_data['rh_id'] = str(diction['chef_jury_id'])
|
||
|
||
now = str(datetime.now())
|
||
mytoday = datetime.today()
|
||
new_data['date_ajout_jury'] = str(mytoday)
|
||
|
||
new_data['date_update'] = now
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['leader'] = "1"
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['jury_id'] = str(local_id)
|
||
data_cle['rh_id'] = str(diction['chef_jury_id'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
"""
|
||
D'abord enlever le statut de leader si qq'un d'autre l'avait
|
||
"""
|
||
update = MYSY_GV.dbname['jury_membre'].update_many(
|
||
{ "partner_owner_recid": str(my_partner['recid']), "jury_id": str(local_id) },
|
||
{"$unset": {'leader':''}},
|
||
)
|
||
|
||
"""
|
||
A présent mise à jour du leader, avec potentiel ajout s'il n'existe pas
|
||
"""
|
||
|
||
result = MYSY_GV.dbname['jury_membre'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (result is None or "_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" WARNING : Impossible d'ajouter le chef d'équipe")
|
||
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = mytoken
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(local_id)
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
|
||
history_event_dict['action_description'] = "Mise à jour "
|
||
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, " Le jury a été correctement mis à jour"
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de mettre à jour le jury "
|
||
|
||
|
||
|
||
"""
|
||
Suppression d'une équipe
|
||
regles :
|
||
Si la condition (_id) n'est pas utiliser dans les collections
|
||
- jury a deja fait une deliberation
|
||
- pas de suppression si groupe à des membres. L'utilisateur devra supprimer les membres d'abord
|
||
"""
|
||
|
||
def Delete_Jury(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id',]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
|
||
is_existe_jury = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_jury != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide "
|
||
|
||
nb_membres = MYSY_GV.dbname['jury_membre'].count_documents({'jury_id': str(diction['_id']),
|
||
'partner_owner_recid': str(
|
||
my_partner['recid']),
|
||
}, )
|
||
|
||
if( nb_membres > 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Ce groupe à "+str(nb_membres)+" membre(s) actif(s). Vous devez supprimer les membres avant de supprimer le jury ")
|
||
return False, " Ce groupe à "+str(nb_membres)+" membre(s) actif(s). Vous devez supprimer les membres avant de supprimer le jury "
|
||
|
||
|
||
|
||
is_existe_jury_date = MYSY_GV.dbname['jury'].find_one(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
"""
|
||
Verifier que le domaine de formation n'est pas utilisé (collection : myclass)
|
||
"" "
|
||
is_domaine_in_myclass = MYSY_GV.dbname['myclass'].count_documents({'partner_owner_recid':my_partner['recid'],
|
||
'valide':'1',
|
||
'class_domaine_id':str(diction['_id'])})
|
||
|
||
|
||
if( is_domaine_in_myclass > 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Cette catégorie de formation est utilisée dans "+str(is_domaine_in_myclass)+" formations ")
|
||
return False, " Cette catégorie de formation est utilisée dans "+str(is_domaine_in_myclass)+" formations "
|
||
|
||
|
||
"""
|
||
|
||
# Suppression des membres
|
||
|
||
delete_membres = MYSY_GV.dbname['jury_membre'].delete_one({'jury_id': str(diction['_id']),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
}, )
|
||
|
||
|
||
delete = MYSY_GV.dbname['jury'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
}, )
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
|
||
history_event_dict['action_description'] = "Suppression du jury : _id = " + str(is_existe_jury_date['_id'])+", code = "+ str(is_existe_jury_date['code'])
|
||
|
||
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, " Le jury a été correctement supprimée"
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de supprimer le jury "
|
||
|
||
|
||
"""
|
||
Cette fonction supprime une séance du jury
|
||
elle desinscrit egalement les membre
|
||
"""
|
||
def Delete_Jury_Seance(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'jury_soutenance_id', ]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'jury_soutenance_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
|
||
is_existe_jury = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_jury != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide "
|
||
|
||
# Supprenant des apprenants associée à cette seance du jury
|
||
jury_seance_apprenant = MYSY_GV.dbname['jury_apprenant'].delete_many({'jury_id': str(diction['jury_id']),
|
||
'jury_soutenance_id': str(diction['jury_soutenance_id']),
|
||
'partner_owner_recid': str(
|
||
my_partner['recid']),
|
||
}, )
|
||
|
||
# Suppression de l'entrée agenda associée
|
||
jury_seance_agenda_data = MYSY_GV.dbname['agenda'].find_one({'related_collection': 'jury_soutenance',
|
||
'related_collection_recid': str(diction['jury_soutenance_id']),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
}, )
|
||
|
||
|
||
jury_seance_agenda = MYSY_GV.dbname['agenda'].delete_one({'related_collection':'jury_soutenance',
|
||
'related_collection_recid': str(diction['jury_soutenance_id']),
|
||
'partner_owner_recid': str( my_partner['recid']),
|
||
}, )
|
||
|
||
jury_soutenance = MYSY_GV.dbname['jury_soutenance'].delete_one({'_id': ObjectId(str(diction['jury_soutenance_id'])),
|
||
'jury_id': str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
}, )
|
||
|
||
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = diction['token']
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
|
||
history_event_dict['action_description'] = "Suppression de la soutenance du jury du " + str(jury_seance_agenda_data['event_start'])+", au = "+ str(jury_seance_agenda_data['event_end'])
|
||
|
||
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, " La séance du jury a été correctement supprimée"
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de supprimer la séance du jury "
|
||
|
||
|
||
|
||
|
||
"""
|
||
Recuperer la liste des jury d'un partenaire
|
||
"""
|
||
def Get_List_Jury(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', ]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', ]
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['jury'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
# Recuperer le nombre de membre
|
||
nb_membre = MYSY_GV.dbname['jury_membre'].count_documents({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'jury_id':str(retval['_id'])})
|
||
user['nb_membre'] = str(nb_membre)
|
||
|
||
|
||
#Recuperation des nom et prenom du responsable (chef d'equipe)
|
||
chef_jury_nom_prenom = ""
|
||
if( "chef_jury_id" in retval.keys() and retval['chef_jury_id']):
|
||
chef_jury_id_data = MYSY_GV.dbname['ressource_humaine'].find_one({'partner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'_id':ObjectId(str(retval['chef_jury_id']))})
|
||
|
||
if( chef_jury_id_data and 'nom' in chef_jury_id_data.keys()):
|
||
chef_jury_nom_prenom = chef_jury_id_data['nom']
|
||
|
||
if (chef_jury_id_data and 'prenom' in chef_jury_id_data.keys()):
|
||
chef_jury_nom_prenom = chef_jury_nom_prenom+ " "+chef_jury_id_data['prenom']
|
||
|
||
user['chef_jury_nom_prenom'] = str(chef_jury_nom_prenom)
|
||
|
||
if( "cible" not in user.keys() ):
|
||
user['cible'] = ""
|
||
|
||
if ("ue_id" not in user.keys()):
|
||
user['ue_id'] = ""
|
||
user['ue_code'] = ""
|
||
elif ( user['ue_id']):
|
||
ue_id_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id':ObjectId(str(user['ue_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( ue_id_data and "code" in ue_id_data.keys() ):
|
||
user['ue_code'] = ue_id_data['code']
|
||
|
||
code_session = ""
|
||
if( "session_id" in user.keys() and user['session_id'] ):
|
||
session_id_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(user['session_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(
|
||
my_partner['recid'])})
|
||
|
||
if (session_id_data and "code_session" in session_id_data.keys()):
|
||
code_session= session_id_data['code_session']
|
||
|
||
user['code_session'] = code_session
|
||
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste des équipes "
|
||
|
||
|
||
"""
|
||
Recuperer les données d'un donné, y compris les membres
|
||
"""
|
||
def Get_Given_Jury_With_Members(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['jury'].find(data_cle):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
|
||
if( "adresse" not in user.keys() ):
|
||
user['adresse'] = ""
|
||
|
||
if ("code_postal" not in user.keys()):
|
||
user['code_postal'] = ""
|
||
|
||
if ("ville" not in user.keys()):
|
||
user['ville'] = ""
|
||
|
||
if ("pays" not in user.keys()):
|
||
user['pays'] = ""
|
||
|
||
if ("site_formation_id" not in user.keys()):
|
||
user['site_formation_id'] = ""
|
||
|
||
if ("jury_salle" not in user.keys()):
|
||
user['jury_salle'] = ""
|
||
|
||
|
||
|
||
# Aller chercher les membres
|
||
list_membre = []
|
||
|
||
|
||
for team_membre in MYSY_GV.dbname['jury_membre'].find({"partner_owner_recid": str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'jury_id':str(diction['_id'])}):
|
||
|
||
|
||
membre_rh_data = MYSY_GV.dbname['ressource_humaine'].find_one({'partner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'_id':ObjectId(str(team_membre['rh_id']))})
|
||
|
||
if(membre_rh_data and '_id' in membre_rh_data.keys() ):
|
||
node_membre = {}
|
||
node_membre['_id'] = str(team_membre['_id'])
|
||
node_membre['jury_id'] = str(retval['_id'])
|
||
node_membre['rh_id'] = str(membre_rh_data['_id'])
|
||
|
||
if( "nom" in membre_rh_data.keys()):
|
||
node_membre['nom'] = str(membre_rh_data['nom'])
|
||
else:
|
||
node_membre['nom'] = ""
|
||
|
||
if ("prenom" in membre_rh_data.keys()):
|
||
node_membre['prenom'] = str(membre_rh_data['prenom'])
|
||
else:
|
||
node_membre['prenom'] = ""
|
||
|
||
if ("civilite" in membre_rh_data.keys()):
|
||
node_membre['civilite'] = str(membre_rh_data['civilite'])
|
||
else:
|
||
node_membre['civilite'] = ""
|
||
|
||
if ("email" in membre_rh_data.keys()):
|
||
node_membre['email'] = str(membre_rh_data['email'])
|
||
else:
|
||
node_membre['email'] = ""
|
||
|
||
if ("telephone" in membre_rh_data.keys()):
|
||
node_membre['telephone'] = str(membre_rh_data['telephone'])
|
||
else:
|
||
node_membre['telephone'] = ""
|
||
|
||
if ("comment" in membre_rh_data.keys()):
|
||
node_membre['comment'] = str(membre_rh_data['comment'])
|
||
else:
|
||
node_membre['comment'] = ""
|
||
|
||
|
||
|
||
if ("role" in team_membre.keys()):
|
||
node_membre['role'] = str(team_membre['role'])
|
||
else:
|
||
node_membre['role'] = ""
|
||
|
||
if ("leader" in team_membre.keys()):
|
||
node_membre['leader'] = str(team_membre['leader'])
|
||
else:
|
||
node_membre['leader'] = ""
|
||
|
||
list_membre.append(node_membre)
|
||
|
||
user['list_membre'] = list_membre
|
||
val_tmp = val_tmp + 1
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer les données du jury "
|
||
|
||
"""
|
||
Recuperer la liste des équipes d'un partenaire avec des filtres sur :
|
||
|
||
- code
|
||
- description
|
||
- membre (nom ou prenom ) equipe
|
||
"""
|
||
def Get_List_jury_With_Filter(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'code', 'description', 'membre', ]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', ]
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
filt_description = {}
|
||
if ("description" in diction.keys()):
|
||
filt_description = {'description': {'$regex': str(diction['description']), "$options": "i"}}
|
||
|
||
|
||
filt_code = {}
|
||
if ("code" in diction.keys()):
|
||
filt_code = {
|
||
'code': {'$regex': str(diction['code']), "$options": "i"}}
|
||
|
||
|
||
filt_membre_ressource_humaine_id = {}
|
||
list_membre_ressource_humaine_id = []
|
||
if ("membre" in diction.keys()):
|
||
filt_membre_qry = { '$or': [
|
||
{ 'nom': {'$regex': str(diction['membre']), "$options": "i"}, 'partner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0' },
|
||
{ 'prenom': {'$regex': str(diction['membre']), "$options": "i"}, 'partner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0' }
|
||
|
||
] }
|
||
|
||
for tmp_val in MYSY_GV.dbname['ressource_humaine'].find(filt_membre_qry):
|
||
list_membre_ressource_humaine_id.append(str(tmp_val['_id']))
|
||
|
||
|
||
#print(" ### liste des Id des ressources humaine sont = ", list_membre_ressource_humaine_id)
|
||
filt_membre_ressource_humaine_id = {'rh_id': {'$in': list_membre_ressource_humaine_id, }}
|
||
|
||
|
||
|
||
####
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
find_qry = {
|
||
'$and': [{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'}, filt_description,
|
||
filt_code, ]}
|
||
local_new_myquery_find_team = ""
|
||
|
||
if ("membre" in diction.keys()):
|
||
local_new_myquery_find_team = [{'$match': find_qry},
|
||
{'$sort': {'_id': -1}},
|
||
{"$addFields": {"jury_header_id": {"$toString": "$_id"}}},
|
||
{'$lookup':
|
||
{
|
||
'from': 'jury_membre',
|
||
'localField': "jury_header_id",
|
||
'foreignField': 'jury_id',
|
||
'pipeline': [
|
||
{'$match':
|
||
{'$and':
|
||
[
|
||
filt_membre_ressource_humaine_id,
|
||
{'partner_owner_recid': str(my_partner['recid']),'valide': '1', 'locked':'0' },
|
||
]
|
||
|
||
}
|
||
|
||
}, ],
|
||
'as': 'jury_membre_collection'
|
||
}
|
||
},
|
||
{
|
||
"$unwind": "$jury_membre_collection"
|
||
}
|
||
]
|
||
|
||
else:
|
||
local_new_myquery_find_team = [{'$match': find_qry},
|
||
{'$sort': {'_id': -1}},
|
||
{"$addFields": {"jury_header_id": {"$toString": "$_id"}}},
|
||
{'$lookup':
|
||
{
|
||
'from': 'jury_membre',
|
||
'localField': "jury_header_id",
|
||
'foreignField': 'jury_id',
|
||
'pipeline': [
|
||
{'$match':
|
||
{'$and':
|
||
[
|
||
filt_membre_ressource_humaine_id,
|
||
{'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1', 'locked': '0'},
|
||
]
|
||
|
||
}
|
||
|
||
}, ],
|
||
'as': 'jury_membre_collection'
|
||
}
|
||
},
|
||
|
||
]
|
||
|
||
print(" ### local_new_myquery_find_team = ", local_new_myquery_find_team)
|
||
|
||
###
|
||
|
||
for local_New_retVal in MYSY_GV.dbname['jury'].aggregate(local_new_myquery_find_team):
|
||
user = {}
|
||
user['id'] = str(val_tmp)
|
||
user['_id'] = str(local_New_retVal['_id'])
|
||
|
||
if( "code" in local_New_retVal.keys()):
|
||
user['code'] = local_New_retVal['code']
|
||
else:
|
||
user['code'] = ""
|
||
|
||
if ("description" in local_New_retVal.keys()):
|
||
user['description'] = local_New_retVal['description']
|
||
else:
|
||
user['description'] = ""
|
||
|
||
if ("email_jury" in local_New_retVal.keys()):
|
||
user['email_jury'] = local_New_retVal['email_jury']
|
||
else:
|
||
user['email_jury'] = ""
|
||
|
||
if ("chef_jury_id" in local_New_retVal.keys()):
|
||
user['chef_jury_id'] = local_New_retVal['chef_jury_id']
|
||
else:
|
||
user['chef_jury_id'] = ""
|
||
|
||
|
||
if ("cible" in local_New_retVal.keys()):
|
||
user['cible'] = local_New_retVal['cible']
|
||
else:
|
||
user['cible'] = ""
|
||
|
||
|
||
if ("ue_id" in local_New_retVal.keys()):
|
||
user['ue_id'] = local_New_retVal['ue_id']
|
||
else:
|
||
user['ue_id'] = ""
|
||
|
||
nb_membre = "0"
|
||
if( "jury_membre_collection" in local_New_retVal.keys() ):
|
||
nb_membre = len(local_New_retVal['jury_membre_collection'])
|
||
|
||
user['nb_membre'] = str(nb_membre)
|
||
|
||
# Recuperation des nom et prenom du responsable (chef d'equipe)
|
||
chef_jury_nom_prenom = ""
|
||
if ("chef_jury_id" in local_New_retVal.keys() and local_New_retVal['chef_jury_id']):
|
||
chef_jury_id_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||
{'partner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'_id': ObjectId(str(local_New_retVal['chef_jury_id']))})
|
||
|
||
if (chef_jury_id_data and 'nom' in chef_jury_id_data.keys()):
|
||
chef_jury_nom_prenom = chef_jury_id_data['nom']
|
||
|
||
if (chef_jury_id_data and 'prenom' in chef_jury_id_data.keys()):
|
||
chef_jury_nom_prenom = chef_jury_nom_prenom + " " + chef_jury_id_data['prenom']
|
||
|
||
user['chef_jury_nom_prenom'] = str(chef_jury_nom_prenom)
|
||
|
||
val_tmp = val_tmp + 1
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste jury "
|
||
|
||
|
||
|
||
"""
|
||
|
||
principe de base :
|
||
- Si l'agenda_id et jury_soutenance_id = "new", alors on souhaite créer 3 choses en meme tmps :
|
||
=> la soutenance
|
||
=> l'agenda
|
||
=> inscrire en meme tps les personnes
|
||
|
||
Cette fonction permet d'inscrire un apprenant 'inscrit_id' à un jury
|
||
|
||
/!\ : A un jury peux etre inscrit un apprenant dont l'inscription n'est pas totalement validé
|
||
par exemple le cas de jury d'admission
|
||
|
||
Les jury etant liée à des aganda, on va ajouté l'id de l'agenda a 'jury_apprenant'
|
||
|
||
|
||
/!\ : Cette fonction permet de gerer aussi l'entrée dans l'agenda
|
||
"""
|
||
|
||
def Add_Update_Apprenant_To_Jury(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id', 'tab_inscriptions_ids', 'agenda_id', 'jury_seance_ue_id',
|
||
'event_start', 'event_end', 'jury_soutenance_id', 'jury_soutenance_salle',
|
||
'jury_soutenance_adresse', 'jury_soutenance_code_postal', 'jury_soutenance_ville',
|
||
'jury_soutenance_pays']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes", False, False
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_id', 'agenda_id', 'jury_soutenance_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes", False, False
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner, False, False
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que le groupe existe et est valide
|
||
qry = {'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])}
|
||
|
||
|
||
|
||
is_existe_groupe = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_groupe != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide ", False, False
|
||
|
||
jury_data = MYSY_GV.dbname['jury'].find_one(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
tab_inscriptions_ids = ""
|
||
if ("tab_inscriptions_ids" in diction.keys()):
|
||
if diction['tab_inscriptions_ids']:
|
||
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
||
|
||
|
||
|
||
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
||
# Controle de validité des inscriptions
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
if(my_inscription ):
|
||
# Verifier que l'inscription est valide
|
||
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'_id': ObjectId(str(my_inscription)),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (my_inscription_is_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' est invalide ")
|
||
return False, " L'inscription_id '" + my_inscription + "' est invalide ", False, False
|
||
|
||
soutenance_inserted_id = str(diction['jury_soutenance_id'])
|
||
agenda_inserted_id = str(diction['agenda_id'])
|
||
|
||
is_fisrt_aganda_creation = ""
|
||
# Verfifier la validité de l'agenda
|
||
if( "agenda_id" in diction.keys() and diction['agenda_id']):
|
||
|
||
if( str(diction['agenda_id']).lower() == "new" and str(diction['jury_soutenance_id']).lower() == "new" ):
|
||
is_fisrt_aganda_creation = "1"
|
||
|
||
# Il s'agit d'un primo creation, il faut créer l'agenda et la soutenance
|
||
new_soutenance_data = {}
|
||
new_soutenance_data['jury_id'] = str(diction['_id'])
|
||
new_soutenance_data['locked'] = "0"
|
||
new_soutenance_data['valide'] = "1"
|
||
new_soutenance_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_soutenance_data['sujet'] = ""
|
||
new_soutenance_data['observation'] = ""
|
||
new_soutenance_data['note'] = ""
|
||
|
||
if( "jury_soutenance_salle" in diction.keys() ):
|
||
new_soutenance_data['jury_soutenance_salle'] = str(diction['jury_soutenance_salle'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_salle'] = ""
|
||
|
||
if ("jury_soutenance_adresse" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_adresse'] = str(diction['jury_soutenance_adresse'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_adresse'] = ""
|
||
|
||
if ("jury_soutenance_code_postal" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_code_postal'] = str(diction['jury_soutenance_code_postal'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_code_postal'] = ""
|
||
|
||
if ("jury_soutenance_ville" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_ville'] = str(diction['jury_soutenance_ville'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_ville'] = ""
|
||
|
||
if ("jury_soutenance_pays" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_pays'] = str(diction['jury_soutenance_pays'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_pays'] = ""
|
||
|
||
|
||
new_soutenance_data['convocation_apprenant_send'] = "0"
|
||
new_soutenance_data['convocation_apprenant_date_sending'] = ""
|
||
new_soutenance_data['create_date'] = str(datetime.now())
|
||
new_soutenance_data['created_by'] = str(my_partner['_id'])
|
||
|
||
|
||
soutenance_inserted_id = MYSY_GV.dbname['jury_soutenance'].insert_one(new_soutenance_data).inserted_id
|
||
if (not soutenance_inserted_id):
|
||
mycommon.myprint(
|
||
" Impossible de créer la soutenance (2) ")
|
||
return False, " Impossible de créer la soutenance (2) ", False, False
|
||
|
||
# Creation de l'entrée agenda
|
||
if (datetime.strptime(str(diction['event_start'])[0:16], '%Y-%m-%dT%H:%M') >= datetime.strptime(
|
||
str(diction['event_end'])[0:16],
|
||
'%Y-%m-%dT%H:%M')):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La date de fin " + str(
|
||
diction['event_end']) + " doit être postérieure à la date de début " + str(
|
||
diction['event_start']) + " ")
|
||
return False, " La date de fin " + str(
|
||
diction['event_end']) + " doit être postérieure à la date de début " + str(
|
||
diction['event_start']) + " ", False, False
|
||
|
||
my_even_data = {}
|
||
my_even_data['related_collection'] = "jury_soutenance"
|
||
my_even_data['related_collection_recid'] = str(soutenance_inserted_id)
|
||
my_even_data['event_title'] = "Jury : " + str(jury_data['code'])
|
||
my_even_data['event_start'] = str(diction['event_start'])
|
||
my_even_data['event_end'] = str(diction['event_end'])
|
||
|
||
my_even_data['valide'] = "1"
|
||
my_even_data['locked'] = "0"
|
||
my_even_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
|
||
my_even_data['create_date'] = str(datetime.now())
|
||
my_even_data['created_by'] = str(my_partner['_id'])
|
||
agenda_inserted_id = MYSY_GV.dbname['agenda'].insert_one(my_even_data).inserted_id
|
||
|
||
|
||
### Mettre à jour la soutenance avec l'id de l'agenda
|
||
|
||
|
||
MYSY_GV.dbname['jury_soutenance'].find_one_and_update({'_id':ObjectId(soutenance_inserted_id), 'partner_owner_recid':str(my_partner['recid'])},
|
||
{"$set": {'agenda_id': str( agenda_inserted_id), }},
|
||
return_document=ReturnDocument.AFTER,
|
||
upsert=False,
|
||
)
|
||
|
||
else:
|
||
# Il s'agit d'une mise à jour à faire.
|
||
is_agenda_valide = MYSY_GV.dbname['agenda'].count_documents(
|
||
{'_id': ObjectId(str(diction['agenda_id'])),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_agenda_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'agenda est invalide ")
|
||
return False, " L'identifiant de l'agenda est invalide ", False, False
|
||
|
||
is_soutenance_valide = MYSY_GV.dbname['jury_soutenance'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_soutenance_id'])),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_soutenance_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide ", False, False
|
||
|
||
# Verifier si l'id de la soutenance est valide
|
||
is_jury_soutenance_valide = MYSY_GV.dbname['jury_soutenance'].count_documents({'_id':ObjectId(str(diction['jury_soutenance_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (is_jury_soutenance_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide ", False, False
|
||
|
||
# Mise à jour de la soutenance
|
||
new_soutenance_data = {}
|
||
|
||
if ("jury_soutenance_salle" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_salle'] = str(diction['jury_soutenance_salle'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_salle'] = ""
|
||
|
||
if ("jury_soutenance_adresse" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_adresse'] = str(diction['jury_soutenance_adresse'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_adresse'] = ""
|
||
|
||
if ("jury_soutenance_code_postal" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_code_postal'] = str(diction['jury_soutenance_code_postal'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_code_postal'] = ""
|
||
|
||
if ("jury_soutenance_ville" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_ville'] = str(diction['jury_soutenance_ville'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_ville'] = ""
|
||
|
||
if ("jury_soutenance_pays" in diction.keys()):
|
||
new_soutenance_data['jury_soutenance_pays'] = str(diction['jury_soutenance_pays'])
|
||
else:
|
||
new_soutenance_data['jury_soutenance_pays'] = ""
|
||
|
||
|
||
new_soutenance_data['date_update'] = str(datetime.now())
|
||
new_soutenance_data['update_by'] = str(my_partner['_id'])
|
||
|
||
ret_val2 = MYSY_GV.dbname['jury_soutenance'].find_one_and_update(
|
||
{'_id': ObjectId(str(diction['jury_soutenance_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
{"$set": new_soutenance_data},
|
||
return_document=ReturnDocument.AFTER,
|
||
upsert=False,
|
||
)
|
||
|
||
|
||
|
||
# Verfifier la validité de l'unité d'enseignement
|
||
if ("jury_seance_ue_id" in diction.keys() and diction['jury_seance_ue_id']):
|
||
is_ue_valide = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_seance_ue_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_ue_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'unité d'enseignement est invalide ")
|
||
return False, " L'identifiant de l'unité d'enseignement est invalide ", False, False
|
||
|
||
final_agenda_id = ""
|
||
|
||
|
||
# Vu que l'ID de l'agenda est valide, on va faire une mise à jour du creneau (on le fait dans tous les cas)
|
||
if( is_fisrt_aganda_creation != "1"):
|
||
if (datetime.strptime(str(diction['event_start'])[0:16], '%Y-%m-%dT%H:%M') >= datetime.strptime(
|
||
str(diction['event_end'])[0:16],
|
||
'%Y-%m-%dT%H:%M')):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La date de fin " + str(
|
||
diction['event_end']) + " doit être postérieure à la date de début " + str(
|
||
diction['event_start']) + " ")
|
||
return False, " La date de fin " + str(
|
||
diction['event_end']) + " doit être postérieure à la date de début " + str(
|
||
diction['event_start']) + " ", False
|
||
|
||
my_even_data = {}
|
||
my_even_data['related_collection'] = "jury"
|
||
my_even_data['related_collection_recid'] = str(diction['_id'])
|
||
my_even_data['event_title'] = "Jury : " + str(jury_data['code'])
|
||
my_even_data['event_start'] = str(diction['event_start'])
|
||
my_even_data['event_end'] = str(diction['event_end'])
|
||
|
||
my_even_data['valide'] = "1"
|
||
my_even_data['locked'] = "0"
|
||
my_even_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
if ("agenda_id" in diction.keys() and diction['agenda_id']):
|
||
my_even_data['date_update'] = str(datetime.now())
|
||
my_even_data['update_by'] = str(my_partner['_id'])
|
||
|
||
update_agenda = MYSY_GV.dbname['agenda'].find_one_and_update(
|
||
{'_id': ObjectId(str(diction['agenda_id'])), 'partner_owner_recid': str(my_partner['recid'])},
|
||
{"$set": my_even_data},
|
||
return_document=ReturnDocument.AFTER,
|
||
upsert=False,
|
||
)
|
||
final_agenda_id = str(diction['agenda_id'])
|
||
|
||
|
||
cpt = 0
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
new_data = {}
|
||
new_data['jury_id'] = str(diction['_id'])
|
||
new_data['inscription_id'] = str(my_inscription)
|
||
new_data['agenda_id'] = str(agenda_inserted_id)
|
||
new_data['jury_soutenance_id'] = str(soutenance_inserted_id)
|
||
|
||
|
||
|
||
now = str(datetime.now())
|
||
mytoday = datetime.today()
|
||
new_data['date_ajout_jury'] = str(mytoday)
|
||
|
||
new_data['date_update'] = now
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['jury_id'] = str(diction['_id'])
|
||
data_cle['inscription_id'] = str(my_inscription)
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
if( "agenda_id" in diction.keys() and diction['agenda_id']):
|
||
data_cle['agenda_id'] = str(diction['agenda_id'])
|
||
|
||
result = MYSY_GV.dbname['jury_apprenant'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (result is None or "_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible créer la soutenance et/ou inscrire les personnes (2) ")
|
||
return False, " Impossible créer la soutenance et/ou inscrire les personnes (2) ", False, False
|
||
|
||
cpt = cpt + 1
|
||
|
||
return True, "Ajout / Mise à jour soutenance ", str(agenda_inserted_id), str(soutenance_inserted_id)
|
||
|
||
|
||
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 créer la soutenance et/ou mettre à jour la soutenance ", False , False
|
||
|
||
|
||
|
||
"""
|
||
Recuperer les apprenants inscrit à un jury
|
||
"""
|
||
def Get_Given_Jury_Apprenant_With_Filter(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id', 'agenda_id', 'ue_id', 'jury_soutenance_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
qry = {}
|
||
qry['jury_id'] = str(diction['_id'])
|
||
qry['valide'] = "1"
|
||
qry['locked'] = "0"
|
||
qry['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
|
||
if( "agenda_id" in diction.keys() and diction['agenda_id']):
|
||
qry["agenda_id"] = str(diction['agenda_id'])
|
||
|
||
if ("ue_id" in diction.keys() and diction['ue_id']):
|
||
qry["ue_id"] = str(diction['ue_id'])
|
||
|
||
if ("jury_soutenance_id" in diction.keys() and diction['jury_soutenance_id']):
|
||
qry["jury_soutenance_id"] = str(diction['jury_soutenance_id'])
|
||
|
||
|
||
|
||
#print(" ### Get_Given_Jury_Apprenant_With_Filter QRY = ",qry )
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['jury_apprenant'].find(qry):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
nom = ""
|
||
prenom = ""
|
||
email = ""
|
||
|
||
if(retval['inscription_id'] ):
|
||
local_new_dict = {}
|
||
local_new_dict['token'] = diction['token']
|
||
local_new_dict['inscrit_id'] = retval['inscription_id']
|
||
|
||
local_inscrit_data_status, local_inscrit_data_retval = mycommon.Get_Inscrit_And_Apprenant_Data(
|
||
local_new_dict)
|
||
if (local_inscrit_data_status is False):
|
||
return local_inscrit_data_status, local_inscrit_data_retval
|
||
|
||
if ("inscrit_data" in local_inscrit_data_retval.keys()):
|
||
user['inscrit_data'] = local_inscrit_data_retval['inscrit_data']
|
||
|
||
nom = local_inscrit_data_retval['inscrit_data']['nom']
|
||
prenom = local_inscrit_data_retval['inscrit_data']['prenom']
|
||
email = local_inscrit_data_retval['inscrit_data']['email']
|
||
|
||
|
||
if ("apprenant_data" in local_inscrit_data_retval.keys()):
|
||
user['apprenant_data'] = local_inscrit_data_retval['apprenant_data']
|
||
|
||
# Si on a un dossier apprenant, alors on écrase les variables ci-dessous
|
||
nom = local_inscrit_data_retval['apprenant_data']['nom']
|
||
prenom = local_inscrit_data_retval['apprenant_data']['prenom']
|
||
email = local_inscrit_data_retval['apprenant_data']['email']
|
||
|
||
|
||
user['nom'] = nom
|
||
user['prenom'] = prenom
|
||
user['email'] = email
|
||
|
||
ue_code = ""
|
||
# Recuperation du code d'unite d'enseignement
|
||
if( "jury_seance_ue_id" in retval.keys() and retval['jury_seance_ue_id']):
|
||
ue_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id':ObjectId(str(retval['jury_seance_ue_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid': str(my_partner['recid'])
|
||
})
|
||
if( ue_data and "code" in ue_data.keys() ):
|
||
ue_code = str(ue_data['code'])
|
||
|
||
user['ue_code'] = ue_code
|
||
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste des membres du groupe "
|
||
|
||
|
||
"""
|
||
Cette fonction permet de supprimer des inscrits à un jury (membre d'un groupe)
|
||
"""
|
||
|
||
def Delete_Jury_Apprenant_Membres(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'tab_ids']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'tab_ids' ]
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que le groupe existe et est valide
|
||
|
||
is_existe_groupe = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_groupe != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide 77 ")
|
||
return False, " L'identifiant du jury est invalide "
|
||
|
||
tab_inscriptions_ids = ""
|
||
if ("tab_ids" in diction.keys()):
|
||
if diction['tab_ids']:
|
||
tab_inscriptions_ids = diction['tab_ids']
|
||
|
||
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
||
|
||
tab_inscriptions_ids_splited_ObjectID = []
|
||
for tmp in tab_inscriptions_ids_splited :
|
||
if( tmp ):
|
||
tab_inscriptions_ids_splited_ObjectID.append(ObjectId(str(tmp)))
|
||
|
||
qery_delete = {'_id': {'$in': tab_inscriptions_ids_splited_ObjectID},
|
||
'jury_id':str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
'locked': '0'}
|
||
|
||
#print(" ### qery_delete = ", qery_delete)
|
||
|
||
delete = MYSY_GV.dbname['jury_apprenant'].delete_many(qery_delete )
|
||
|
||
return True, str(delete.deleted_count) + " Membre(s) désinscrit(s)"
|
||
|
||
|
||
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ésinscrire les personnes au jury "
|
||
|
||
|
||
"""
|
||
Cette fonction permet de gerer les jury de type non examen, c'est a dire
|
||
les jury d'admission, les jury pour une UE....
|
||
|
||
En gros tous les jury pour lequel il a un sujet et un deliberation
|
||
Ici on a pas besoin des antécedents, donc les jury a SOUTENANCE
|
||
"""
|
||
def Add_Update_Jury_Soutenance(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'jury_soutenance_id',
|
||
'agenda_id', 'sujet', 'note', 'observation',
|
||
'jury_soutenance_salle',
|
||
'jury_soutenance_adresse', 'jury_soutenance_code_postal', 'jury_soutenance_ville',
|
||
'jury_soutenance_pays'
|
||
]
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'jury_soutenance_id',
|
||
'agenda_id', 'sujet', 'note', 'observation']
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner, False
|
||
|
||
|
||
# Verfier la validité du jury
|
||
is_jury_valide_count = MYSY_GV.dbname['jury'].count_documents({'_id':ObjectId(str(diction['jury_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( is_jury_valide_count != 1 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide"
|
||
|
||
# Verfier la validité de la soutenance de jury
|
||
is_jury_soutenance_valide_count = MYSY_GV.dbname['jury_soutenance'].count_documents({'_id': ObjectId(str(diction['jury_soutenance_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_jury_soutenance_valide_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide "
|
||
|
||
|
||
# Verfier la validité de la séance (agenda)
|
||
is_jury_agenda_valide_count = MYSY_GV.dbname['agenda'].count_documents({'_id': ObjectId(str(diction['agenda_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'related_collection':'jury_soutenance',
|
||
'related_collection_recid':str(diction['jury_soutenance_id']),
|
||
'partner_owner_recid': str( my_partner['recid'])})
|
||
|
||
|
||
if (is_jury_agenda_valide_count != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'agenda de la soutenance du jury est invalide ")
|
||
return False, " L'identifiant de l'agenda de la soutenance du jury est invalide "
|
||
|
||
|
||
my_token = str(diction['token'])
|
||
local_jury_soutenance_id = diction['jury_soutenance_id']
|
||
new_data = diction
|
||
del new_data['token']
|
||
del new_data['jury_soutenance_id']
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['date_update'] = str(datetime.now())
|
||
|
||
result = MYSY_GV.dbname['jury_soutenance'].find_one_and_update(
|
||
{'_id':ObjectId(str(local_jury_soutenance_id)),
|
||
'jury_id':str(diction['jury_id']),
|
||
'partner_owner_recid':str(my_partner['recid'])
|
||
},
|
||
{"$set": new_data},
|
||
upsert=True,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if (result is None or "_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible de mettre à jour la soutenance (2) ")
|
||
return False, " Impossible de mettre à jour la soutenance (2) ", False
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(my_token)
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = " Mise à jour de la soutenance "
|
||
|
||
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, "La soutenance a été correctement mise à jour"
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de mettre à jour la soutenance "
|
||
|
||
|
||
"""
|
||
Recuperation de la liste des soutenances
|
||
"""
|
||
def Get_List_Jury_Soutenenace(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
is_jury_valide = MYSY_GV.dbname['jury'].count_documents({'_id':ObjectId(str(diction['jury_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( is_jury_valide != 1 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide ",
|
||
|
||
jury_data = MYSY_GV.dbname['jury'].find_one({'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
data_cle['jury_id'] = str(diction['jury_id'])
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['jury_soutenance'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
|
||
if( "session_id" in jury_data.keys() ):
|
||
user['session_id'] = jury_data['session_id']
|
||
else:
|
||
user['session_id'] = ""
|
||
|
||
if( "convocation_apprenant_send" not in retval.keys() ):
|
||
user["convocation_apprenant_send"] = ""
|
||
|
||
if ("convocation_apprenant_date_sending" not in retval.keys()):
|
||
user["convocation_apprenant_date_sending"] = ""
|
||
|
||
|
||
# Recuperation des agenda associés
|
||
soutenance_agenda_id = ""
|
||
soutenance_agenda_event_title = ""
|
||
soutenance_agenda_event_start = ""
|
||
soutenance_agenda_event_end = ""
|
||
if( "agenda_id" in retval.keys() and retval['agenda_id'] ):
|
||
agenda_data = MYSY_GV.dbname['agenda'].find_one({'_id':ObjectId(str(retval['agenda_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])},
|
||
{'_id':1, 'event_start':1, 'event_end':1, 'event_title':1})
|
||
|
||
|
||
|
||
soutenance_agenda_id = str(agenda_data['_id'])
|
||
soutenance_agenda_event_start = str(agenda_data['event_start'])
|
||
soutenance_agenda_event_end = str(agenda_data['event_end'])
|
||
soutenance_agenda_event_title = str(agenda_data['event_title'])
|
||
|
||
user['soutenance_agenda_id'] = soutenance_agenda_id
|
||
user['soutenance_agenda_event_start'] = soutenance_agenda_event_start
|
||
user['soutenance_agenda_event_end'] = soutenance_agenda_event_end
|
||
user['soutenance_agenda_event_title'] = soutenance_agenda_event_title
|
||
|
||
|
||
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
jury_apprenant = []
|
||
|
||
# Recuperer le nombre de membre
|
||
nb_jury_apprenant = MYSY_GV.dbname['jury_apprenant'].count_documents({'partner_owner_recid':str(my_partner['recid']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'jury_id':str(retval['jury_id'])})
|
||
user['nb_apprenant'] = str(nb_jury_apprenant)
|
||
|
||
for inscrit in MYSY_GV.dbname['jury_apprenant'].find({'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'jury_id': str(retval['jury_id'])}):
|
||
|
||
if( inscrit and "inscription_id" in inscrit.keys() and inscrit['inscription_id']):
|
||
jury_inscri_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(inscrit['inscription_id'])),
|
||
'valide':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])},
|
||
{'email':1,
|
||
'nom':1,
|
||
'prenom':1})
|
||
|
||
jury_apprenant.append(jury_inscri_data)
|
||
|
||
|
||
|
||
user['list_inscrit'] = jury_apprenant
|
||
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste des soutenances "
|
||
|
||
|
||
"""
|
||
Recuperation de la liste des soutenances avec des filtre sur
|
||
- sur la salle
|
||
- l'inscrit (list)
|
||
- l'apprenant (list)
|
||
|
||
"""
|
||
def Get_List_Jury_Soutenenace_With_Filter(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'jury_salle_nom',
|
||
'tab_inscrit_ids', 'inscrit_email',
|
||
'tab_apprenant_ids', 'apprenant_email',
|
||
'session_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token',]
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
filt_jury_apprenant_inscrit_ids = {}
|
||
tab_inscriptions_ids = ""
|
||
if ("tab_inscrit_ids" in diction.keys()):
|
||
if diction['tab_inscrit_ids']:
|
||
tab_inscriptions_ids = diction['tab_inscrit_ids']
|
||
|
||
tab_inscriptions_ids_splited_work = str(tab_inscriptions_ids).split(",")
|
||
|
||
tab_inscriptions_ids_splited = []
|
||
for tmp in tab_inscriptions_ids_splited_work :
|
||
if( tmp ):
|
||
tab_inscriptions_ids_splited.append(str(tmp))
|
||
|
||
filt_jury_apprenant_inscrit_ids = {'inscription_id': {'$in': tab_inscriptions_ids_splited},}
|
||
|
||
#------------
|
||
filt_jury_apprenant_apprenant_ids = {}
|
||
tab_apprenant_ids = ""
|
||
if ("tab_apprenant_ids" in diction.keys()):
|
||
if diction['tab_apprenant_ids']:
|
||
tab_apprenant_ids = diction['tab_apprenant_ids']
|
||
|
||
tab_apprenant_ids_splited_work = str(tab_apprenant_ids).split(",")
|
||
|
||
tab_apprenant_ids_splited = []
|
||
for tmp in tab_apprenant_ids_splited_work:
|
||
if (tmp):
|
||
tab_apprenant_ids_splited.append(str(tmp))
|
||
|
||
|
||
tab_inscription_apprenant = []
|
||
|
||
# Recuperer la liste des inscription_id associé à cet apprenant
|
||
for val in MYSY_GV.dbname['inscription'].find({'partner_owner_recid':str(my_partner['recid']),
|
||
'apprenant_id':{'$in':tab_apprenant_ids_splited} }):
|
||
tab_inscription_apprenant.append(str(val['_id']))
|
||
|
||
filt_jury_apprenant_apprenant_ids = {'inscription_id': {'$in': tab_inscription_apprenant},}
|
||
|
||
filt_final_on_inscription = {}
|
||
if(len(tab_inscription_apprenant) > 0 and len(tab_inscriptions_ids_splited) > 0):
|
||
filt_final_on_inscription = {}
|
||
tab_work = []
|
||
|
||
for tmp in tab_inscription_apprenant:
|
||
if( tmp and tmp not in tab_work):
|
||
tab_work.append(tmp)
|
||
|
||
for tmp in tab_inscriptions_ids_splited:
|
||
if( tmp and tmp not in tab_work):
|
||
tab_work.append(tmp)
|
||
|
||
filt_final_on_inscription = {'inscription_id': {'$in': tab_work},}
|
||
|
||
|
||
elif ( len(tab_inscription_apprenant) > 0 ):
|
||
filt_final_on_inscription = filt_jury_apprenant_apprenant_ids
|
||
|
||
|
||
elif ( len(tab_inscriptions_ids_splited) > 0 ):
|
||
filt_final_on_inscription = filt_jury_apprenant_inscrit_ids
|
||
|
||
|
||
#print(" ### filt_final_on_inscription = ", filt_final_on_inscription)
|
||
|
||
#-----------
|
||
"""
|
||
filt_jury_apprenant_inscription_apprenant_id = {}
|
||
tab_apprenant_id = ""
|
||
if ("apprenant_id" in diction.keys() and diction['apprenant_id']):
|
||
filt_jury_apprenant_inscription_apprenant_id = {'$eq': ["$apprenant_id", str(diction['apprenant_id'])]},
|
||
|
||
"""
|
||
|
||
filt_jury_salle_nom = {}
|
||
if ("jury_salle_nom" in diction.keys() and diction['jury_salle_nom']):
|
||
filt_jury_salle_nom = {'jury_salle': {'$regex': str(diction['jury_salle_nom']), "$options": "i"}}
|
||
|
||
|
||
filt_session_id = {}
|
||
if( 'session_id' in diction.keys() and diction['session_id']):
|
||
filt_session_id = {'$eq': ["$session_id", str(diction['session_id'])]},
|
||
|
||
qry_filter = {'$and': [{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'}, filt_jury_salle_nom,
|
||
filt_final_on_inscription]}
|
||
|
||
|
||
|
||
pipe_qry = [{'$match': qry_filter},
|
||
{'$lookup': {
|
||
'from': 'jury_soutenance',
|
||
"let": {'jury_soutenance_id': "$jury_soutenance_id",
|
||
'partner_owner_recid': '$partner_owner_recid'},
|
||
'pipeline': [
|
||
{'$match':
|
||
{'$expr':
|
||
{'$and':
|
||
[
|
||
|
||
{'$eq': ["$_id", {'$convert': {
|
||
'input': "$$jury_soutenance_id",
|
||
'to': "objectId",
|
||
'onError': {'error': 'true'},
|
||
'onNull': {'isnull': 'true'}
|
||
}}]},
|
||
|
||
{'$eq': ["$valide", "1"]},
|
||
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
||
|
||
]
|
||
}
|
||
}
|
||
},
|
||
|
||
],
|
||
'as': 'jury_soutenance_collection'
|
||
}
|
||
},
|
||
|
||
{'$lookup': {
|
||
'from': 'inscription',
|
||
"let": {'inscription_id': "$inscription_id", 'partner_owner_recid': '$partner_owner_recid',
|
||
|
||
},
|
||
'pipeline': [
|
||
{'$match':
|
||
{'$expr':
|
||
{'$and':
|
||
[
|
||
|
||
{'$eq': ["$_id", {'$convert': {
|
||
'input': "$$inscription_id",
|
||
'to': "objectId",
|
||
'onError': {'error': 'true'},
|
||
'onNull': {'isnull': 'true'}
|
||
}}]},
|
||
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']},
|
||
{'$eq': ["$valide", '1']},
|
||
filt_session_id
|
||
|
||
]
|
||
}
|
||
}
|
||
},
|
||
|
||
],
|
||
'as': 'inscription_collection'
|
||
}
|
||
},
|
||
]
|
||
|
||
|
||
print(" ### pipe_qry = ", pipe_qry)
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
for New_retVal in MYSY_GV.dbname['jury_apprenant'].aggregate(pipe_qry):
|
||
new_node = {}
|
||
new_node['_id'] = New_retVal['_id']
|
||
new_node['agenda_id'] = New_retVal['agenda_id']
|
||
new_node['inscription_id'] = New_retVal['inscription_id']
|
||
new_node['jury_id'] = New_retVal['jury_id']
|
||
new_node['jury_soutenance_id'] = New_retVal['jury_soutenance_id']
|
||
|
||
soutenance_sujet = ""
|
||
soutenance_note = ""
|
||
soutenance_observation = ""
|
||
soutenance_adresse = ""
|
||
soutenance_code_postal = ""
|
||
soutenance_ville = ""
|
||
soutenance_pays = ""
|
||
soutenance_convocation_apprenant_date_sending = ""
|
||
soutenance_convocation_apprenant_send = ""
|
||
|
||
if( "jury_soutenance_collection" in New_retVal.keys() and len(New_retVal["jury_soutenance_collection"]) > 0 ):
|
||
if( "sujet" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_sujet = New_retVal["jury_soutenance_collection"][0]['sujet']
|
||
|
||
if ("note" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_note = New_retVal["jury_soutenance_collection"][0]['note']
|
||
|
||
if ("observation" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_observation = New_retVal["jury_soutenance_collection"][0]['observation']
|
||
|
||
if ("adresse" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_adresse = New_retVal["jury_soutenance_collection"][0]['adresse']
|
||
|
||
if ("code_postal" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_code_postal = New_retVal["jury_soutenance_collection"][0]['code_postal']
|
||
|
||
if ("ville" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_ville = New_retVal["jury_soutenance_collection"][0]['ville']
|
||
|
||
if ("pays" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_pays = New_retVal["jury_soutenance_collection"][0]['pays']
|
||
|
||
if ("convocation_apprenant_date_sending" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_convocation_apprenant_date_sending = New_retVal["jury_soutenance_collection"][0]['convocation_apprenant_date_sending']
|
||
|
||
if ("convocation_apprenant_send" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
soutenance_convocation_apprenant_send = New_retVal["jury_soutenance_collection"][0]['convocation_apprenant_send']
|
||
|
||
new_node['soutenance_sujet'] = str(soutenance_sujet)
|
||
new_node['soutenance_note'] = str(soutenance_note)
|
||
new_node['soutenance_observation'] = str(soutenance_observation)
|
||
new_node['soutenance_adresse'] = str(soutenance_adresse)
|
||
new_node['soutenance_code_postal'] = str(soutenance_code_postal)
|
||
new_node['soutenance_ville'] = str(soutenance_ville)
|
||
new_node['soutenance_pays'] = str(soutenance_pays)
|
||
new_node['soutenance_convocation_apprenant_date_sending'] = str(soutenance_convocation_apprenant_date_sending)
|
||
new_node['soutenance_convocation_apprenant_send'] = str(soutenance_convocation_apprenant_send)
|
||
|
||
|
||
inscrit_nom = ""
|
||
inscrit_prenom = ""
|
||
inscrit_email = ""
|
||
|
||
if ("inscription_collection" in New_retVal.keys() and len( New_retVal["inscription_collection"]) > 0):
|
||
if ("nom" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
inscrit_nom = New_retVal["jury_soutenance_collection"][0]['nom']
|
||
|
||
if ("prenom" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
inscrit_prenom = New_retVal["jury_soutenance_collection"][0]['prenom']
|
||
|
||
if ("email" in New_retVal["jury_soutenance_collection"][0].keys()):
|
||
inscrit_email = New_retVal["jury_soutenance_collection"][0]['email']
|
||
|
||
new_node['inscrit_nom'] = str(inscrit_nom)
|
||
new_node['inscrit_prenom'] = str(inscrit_prenom)
|
||
new_node['inscrit_email'] = str(inscrit_email)
|
||
|
||
soutenance_agenda_event_start = ""
|
||
soutenance_agenda_event_end = ""
|
||
if ("agenda_id" in New_retVal.keys() and New_retVal['agenda_id']):
|
||
agenda_data = MYSY_GV.dbname['agenda'].find_one({'_id': ObjectId(str(New_retVal['agenda_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
{'_id': 1, 'event_start': 1, 'event_end': 1,
|
||
'event_title': 1})
|
||
|
||
local_date = str(agenda_data['event_start'])[0:16]
|
||
new_date = datetime.strptime(str(local_date), '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M")
|
||
soutenance_agenda_event_start = str(new_date)
|
||
|
||
local_date = str(agenda_data['event_end'])[0:16]
|
||
new_date = datetime.strptime(str(local_date), '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M")
|
||
soutenance_agenda_event_end = str(new_date)
|
||
|
||
new_node['soutenance_agenda_event_start'] = str(soutenance_agenda_event_start)
|
||
new_node['soutenance_agenda_event_end'] = str(soutenance_agenda_event_end)
|
||
|
||
soutenance_agenda_ue_code = ""
|
||
|
||
if ("jury_id" in New_retVal.keys() and New_retVal['jury_id']):
|
||
jury_data = MYSY_GV.dbname['jury'].find_one({'_id': ObjectId(str(New_retVal['jury_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
{'_id': 1, 'ue_id': 1,})
|
||
|
||
if( jury_data and 'ue_id' in jury_data.keys() and jury_data['ue_id']):
|
||
ue_id_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id': ObjectId(str(jury_data['ue_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
{'_id': 1, 'code': 1, }
|
||
)
|
||
|
||
if( ue_id_data and "code" in ue_id_data.keys() ):
|
||
soutenance_agenda_ue_code = ue_id_data['code']
|
||
|
||
new_node['soutenance_code'] = str(soutenance_agenda_ue_code)
|
||
|
||
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(new_node))
|
||
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste des soutenances "
|
||
|
||
|
||
|
||
|
||
|
||
"""
|
||
Recuperer les information d'une soutenance donnée
|
||
"""
|
||
def Get_Given_Jury_Soutenenace(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'agenda_id', 'jury_soutenance_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'agenda_id', 'jury_soutenance_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['_id'] = ObjectId(str(diction['jury_soutenance_id']))
|
||
data_cle['locked'] = "0"
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['jury_soutenance'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
|
||
if ("jury_soutenance_salle" not in retval.keys()):
|
||
user['jury_soutenance_salle'] = ""
|
||
|
||
if ("jury_soutenance_adresse" not in retval.keys()):
|
||
user['jury_soutenance_adresse'] = ""
|
||
|
||
if ("jury_soutenance_code_postal" not in retval.keys()):
|
||
user['jury_soutenance_code_postal'] = ""
|
||
|
||
if ("jury_soutenance_ville" not in retval.keys()):
|
||
user['jury_soutenance_ville'] = ""
|
||
|
||
if ("jury_soutenance_pays" not in retval.keys()):
|
||
user['jury_soutenance_pays'] = ""
|
||
|
||
|
||
if ("convocation_apprenant_send" not in retval.keys()):
|
||
user["convocation_apprenant_send"] = ""
|
||
|
||
if ("convocation_apprenant_date_sending" not in retval.keys()):
|
||
user["convocation_apprenant_date_sending"] = ""
|
||
|
||
|
||
val_tmp = val_tmp + 1
|
||
|
||
jury_apprenant = []
|
||
|
||
# Recuperer le nombre de membre
|
||
nb_jury_apprenant = MYSY_GV.dbname['jury_apprenant'].count_documents(
|
||
{'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'jury_id': str(retval['jury_id'])})
|
||
user['nb_apprenant'] = str(nb_jury_apprenant)
|
||
|
||
for inscrit in MYSY_GV.dbname['jury_apprenant'].find({'partner_owner_recid': str(my_partner['recid']),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'jury_id': str(retval['jury_id'])}):
|
||
|
||
if (inscrit and "inscription_id" in inscrit.keys() and inscrit['inscription_id']):
|
||
jury_inscri_data = MYSY_GV.dbname['inscription'].find_one(
|
||
{'_id': ObjectId(str(inscrit['inscription_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])},
|
||
{'email': 1,
|
||
'nom': 1,
|
||
'prenom': 1})
|
||
|
||
jury_apprenant.append(jury_inscri_data)
|
||
|
||
user['list_inscrit'] = jury_apprenant
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de récupérer la liste des soutenances "
|
||
|
||
|
||
"""
|
||
Supprimer une soutenance donnée
|
||
"""
|
||
def Delete_Given_Jury_Soutenenace(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'agenda_id']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', ' agenda_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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['agenda_id'] = str(diction['agenda_id'])
|
||
data_cle['locked'] = "0"
|
||
|
||
soutenance_agenda_data = MYSY_GV.dbname['agenda'].find_one(
|
||
{'_id': ObjectId(str(diction['agenda_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
delete = MYSY_GV.dbname['jury_soutenance'].delete_many(data_cle)
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Suppression de la soutenance du "+str(soutenance_agenda_data['event_start'])+" au "+str(soutenance_agenda_data['event_end'])
|
||
|
||
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, "La soutenance a été correctement supprimée"
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de supprimer la soutenance"
|
||
|
||
|
||
"""
|
||
Cette fonction permet de telecharger (PDF) la convocation des apprenants concernés
|
||
par une soutenance du jury
|
||
"""
|
||
def Send_Jury_Apprenant_Soutenance_Convocation_By_PDF(diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_id', 'tab_jury_soutenance_ids', 'courrier_template_id']
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
my_token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
my_token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
my_jury_soutenance_ids = ""
|
||
if ("tab_jury_soutenance_ids" in diction.keys()):
|
||
if diction['tab_jury_soutenance_ids']:
|
||
my_jury_soutenance_ids = diction['tab_jury_soutenance_ids']
|
||
|
||
tab_jury_soutenance_ids_work = str(my_jury_soutenance_ids).split(",")
|
||
tab_jury_soutenance_ids = []
|
||
tab_jury_soutenance_ids_ObjectId = []
|
||
|
||
for_log_history_description = []
|
||
|
||
for tmp in tab_jury_soutenance_ids_work:
|
||
if( tmp ):
|
||
is_jury_soutenance_valide = MYSY_GV.dbname['jury_soutenance'].count_documents(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked':'0',
|
||
'jury_id':str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_jury_soutenance_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide "
|
||
|
||
is_jury_soutenance_data = MYSY_GV.dbname['jury_soutenance'].find_one(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'jury_id': str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
if( is_jury_soutenance_data and "agenda_id" in is_jury_soutenance_data.keys() and is_jury_soutenance_data['agenda_id']):
|
||
soutenance_agenda_data = MYSY_GV.dbname['agenda'].find_one({'_id':ObjectId(str(is_jury_soutenance_data['agenda_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
if(soutenance_agenda_data ):
|
||
for_log_history_description.append(soutenance_agenda_data)
|
||
|
||
tab_jury_soutenance_ids.append(tmp)
|
||
tab_jury_soutenance_ids_ObjectId.append(ObjectId(tmp))
|
||
|
||
|
||
|
||
# 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'])}
|
||
)
|
||
|
||
if(courrier_template_data is None ):
|
||
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 "
|
||
|
||
|
||
if("contenu_doc" not in courrier_template_data.keys() or len(str(courrier_template_data['contenu_doc'])) <= 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " contenu_doc : La configuration du modèle de courrier est invalide ")
|
||
return False, " contenu_doc : La configuration du modèle de courrier est invalide "
|
||
|
||
|
||
"""
|
||
Recuperer la liste des inscrits concernés par la soutenance
|
||
"""
|
||
# Stokage des nom de fichier à zipper
|
||
list_file_name_to_zip = []
|
||
|
||
for local_soutenance in tab_jury_soutenance_ids:
|
||
tab_soutenance_inscrit = []
|
||
for tmp in MYSY_GV.dbname['jury_apprenant'].find({'jury_id':str(diction['jury_id']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'jury_soutenance_id':str(local_soutenance),
|
||
'partner_owner_recid':str(my_partner['recid'])}):
|
||
if( tmp['inscription_id'] ):
|
||
tab_soutenance_inscrit.append(str(tmp['inscription_id']))
|
||
|
||
print(" ### tab_soutenance_inscrit = ", tab_soutenance_inscrit)
|
||
|
||
for val in tab_soutenance_inscrit:
|
||
local_diction = {}
|
||
# field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_id']
|
||
local_diction['token'] = diction['token']
|
||
local_diction['jury_soutenance_id'] = str(local_soutenance)
|
||
local_diction['courrier_template_id'] = diction['courrier_template_id']
|
||
local_diction['inscription_id'] = str(val)
|
||
|
||
print(" ### local_diction === ", local_diction)
|
||
local_status, local_full_file_name = Create_Jury_Soutenance_Convocation_By_Inscrit_PDF(local_diction)
|
||
if( local_status is False):
|
||
return local_status, local_full_file_name
|
||
else:
|
||
list_file_name_to_zip.append(str(local_full_file_name))
|
||
|
||
|
||
# Create a ZipFile Object
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
||
zip_file_name = str(MYSY_GV.TEMPORARY_DIRECTORY_V2) + "List_Convocation_Jury_" + str(ts) + "_.zip"
|
||
|
||
with ZipFile(zip_file_name, 'w') as zip_object:
|
||
for pdf_files in list_file_name_to_zip :
|
||
#print(" ### fichier a zipper = ", pdf_files)
|
||
zip_object.write(str(pdf_files))
|
||
|
||
|
||
if os.path.exists(zip_file_name):
|
||
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||
"""
|
||
Mettre à jour l'historique pour que les convocation ont été imprimées
|
||
"""
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Impression convocation soutenance pour les apprenants "
|
||
for tmp in for_log_history_description :
|
||
history_event_dict['action_description'] = history_event_dict['action_description']+" - Soutenance du "+str(tmp['event_start'])+" au "+str(tmp['event_end'])
|
||
|
||
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, send_file(zip_file_name, as_attachment=True)
|
||
|
||
|
||
return False, " Impossible de générer les convocations jury par PDF (1) "
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de générer les convocations jury par PDF"
|
||
|
||
|
||
"""
|
||
Cette fonction créer une convocation à une soutenance de Jury PDF pour un inscrit et retourne le document
|
||
"""
|
||
def Create_Jury_Soutenance_Convocation_By_Inscrit_PDF(diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_soutenance_id', 'courrier_template_id', 'inscription_id']
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
qry = {'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_APPRENANT',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
#print(" ##### qry = ", qry)
|
||
|
||
# 1 - Verifier que le modele de courrier est bien editable par individu
|
||
template_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_APPRENANT',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( template_courrier_data is None ):
|
||
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 "
|
||
|
||
|
||
|
||
|
||
# Verifier que l'inscrit est valide
|
||
local_qry = {'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
statgiaire_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (statgiaire_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du stagiaire est invalide ")
|
||
return False, " L'identifiant du stagiaire est invalide "
|
||
|
||
tab_stagiaire = []
|
||
tab_stagiaire.append(statgiaire_data['_id'])
|
||
|
||
|
||
# Verifier que la soutenance est valide
|
||
jury_soutenance_data = MYSY_GV.dbname['jury_soutenance'].find_one(
|
||
{'_id': ObjectId(str(diction['jury_soutenance_id'])), 'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (jury_soutenance_data is None):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide "
|
||
|
||
tab_soutenance = []
|
||
tab_soutenance.append(jury_soutenance_data['_id'])
|
||
|
||
|
||
|
||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||
convention_dictionnary_data = {}
|
||
new_diction = {}
|
||
new_diction['token'] = diction['token']
|
||
new_diction['list_stagiaire_id'] = tab_stagiaire
|
||
new_diction['list_session_id'] = []
|
||
new_diction['list_class_id'] = []
|
||
new_diction['list_client_id'] = []
|
||
new_diction['list_apprenant_id'] = []
|
||
new_diction['list_jury_soutenance_id'] = tab_soutenance
|
||
|
||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||
|
||
if (local_status is False):
|
||
return local_status, local_retval
|
||
|
||
convention_dictionnary_data = local_retval
|
||
|
||
body = {
|
||
"params": convention_dictionnary_data,
|
||
}
|
||
|
||
"""
|
||
Creation du ficier PDF
|
||
"""
|
||
|
||
contenu_doc_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
|
||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||
|
||
orig_file_name = "Convocation_Soutenance_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||
|
||
# open output file for writing (truncated binary)
|
||
resultFile = open(outputFilename, "w+b")
|
||
|
||
# convert HTML to PDF
|
||
pisaStatus = pisa.CreatePDF(
|
||
src=sourceHtml, # the HTML to convert
|
||
dest=resultFile) # file handle to receive result
|
||
|
||
# close output file
|
||
resultFile.close()
|
||
|
||
return True, outputFilename
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de créer le fichier pdf de convocation du jury "
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction permet d'envoyer par e-mail la convocation des apprenants concernés
|
||
par une soutenance du jury
|
||
"""
|
||
def Send_Jury_Apprenant_Soutenance_Convocation_By_Email(tab_files, Folder, diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_id', 'tab_jury_soutenance_ids',
|
||
'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 la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
# Sauvegarde des fichiers joints depuis le front
|
||
tab_saved_file_full_path = []
|
||
for file in tab_files:
|
||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||
if (status is False):
|
||
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
||
return False, "Impossible de récupérer correctement le fichier à importer"
|
||
|
||
tab_saved_file_full_path.append(saved_file_full_path)
|
||
|
||
|
||
my_jury_soutenance_ids = ""
|
||
if ("tab_jury_soutenance_ids" in diction.keys()):
|
||
if diction['tab_jury_soutenance_ids']:
|
||
my_jury_soutenance_ids = diction['tab_jury_soutenance_ids']
|
||
|
||
tab_jury_soutenance_ids_work = str(my_jury_soutenance_ids).split(",")
|
||
tab_jury_soutenance_ids = []
|
||
tab_jury_soutenance_ids_ObjectId = []
|
||
|
||
for_log_history_description = []
|
||
|
||
for tmp in tab_jury_soutenance_ids_work:
|
||
if( tmp ):
|
||
is_jury_soutenance_valide = MYSY_GV.dbname['jury_soutenance'].count_documents(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked':'0',
|
||
'jury_id':str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_jury_soutenance_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide "
|
||
|
||
is_jury_soutenance_data = MYSY_GV.dbname['jury_soutenance'].find_one(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'jury_id': str(diction['jury_id']),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
if( is_jury_soutenance_data and "agenda_id" in is_jury_soutenance_data.keys() and is_jury_soutenance_data['agenda_id']):
|
||
soutenance_agenda_data = MYSY_GV.dbname['agenda'].find_one({'_id':ObjectId(str(is_jury_soutenance_data['agenda_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
if(soutenance_agenda_data ):
|
||
for_log_history_description.append(soutenance_agenda_data)
|
||
|
||
tab_jury_soutenance_ids.append(tmp)
|
||
tab_jury_soutenance_ids_ObjectId.append(ObjectId(tmp))
|
||
|
||
|
||
|
||
# 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'])}
|
||
)
|
||
|
||
if(courrier_template_data is None ):
|
||
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 "
|
||
|
||
|
||
if("contenu_doc" not in courrier_template_data.keys() or len(str(courrier_template_data['contenu_doc'])) <= 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " contenu_doc : La configuration du modèle de courrier est invalide ")
|
||
return False, " contenu_doc : La configuration du modèle de courrier est invalide "
|
||
|
||
|
||
"""
|
||
Recuperer la liste des inscrits concernés par la soutenance
|
||
"""
|
||
# Stokage des nom de fichier à zipper
|
||
list_file_name_to_zip = []
|
||
|
||
for local_soutenance in tab_jury_soutenance_ids:
|
||
tab_soutenance_inscrit = []
|
||
for tmp in MYSY_GV.dbname['jury_apprenant'].find({'jury_id':str(diction['jury_id']),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'jury_soutenance_id':str(local_soutenance),
|
||
'partner_owner_recid':str(my_partner['recid'])}):
|
||
|
||
if( tmp['inscription_id'] ):
|
||
tab_soutenance_inscrit.append(str(tmp['inscription_id']))
|
||
|
||
|
||
for val in tab_soutenance_inscrit:
|
||
local_diction = {}
|
||
# field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_id']
|
||
local_diction['token'] = diction['token']
|
||
local_diction['jury_soutenance_id'] = str(local_soutenance)
|
||
local_diction['courrier_template_id'] = diction['courrier_template_id']
|
||
local_diction['inscription_id'] = str(val)
|
||
local_diction['email_test'] = diction['email_test']
|
||
local_diction['email_production'] = diction['email_production']
|
||
|
||
local_status, local_full_file_name = Create_Jury_Soutenance_Convocation_By_Inscrit_Email(tab_saved_file_full_path, Folder, local_diction)
|
||
if (local_status is False):
|
||
mycommon.myprint(" WARNING impossible d'envoyer la convocation a l'apprenant : " + str(val) )
|
||
|
||
"""
|
||
Mise à jour des date d'envoie
|
||
"""
|
||
|
||
update_data = {}
|
||
update_data['date_update'] = str(datetime.now())
|
||
update_data['update_by'] = str(my_partner['_id'])
|
||
update_data['convocation_apprenant_send'] = "1"
|
||
update_data['convocation_apprenant_date_sending'] = str(datetime.now())
|
||
|
||
MYSY_GV.dbname['jury_soutenance'].find_one_and_update({'_id':{'$in':tab_jury_soutenance_ids_ObjectId},
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])},
|
||
{"$set": update_data},
|
||
return_document=ReturnDocument.AFTER,
|
||
upsert=True,
|
||
)
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(diction['jury_id'])
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Envoi par email des convocations de soutenance pour les apprenants "
|
||
for tmp in for_log_history_description :
|
||
history_event_dict['action_description'] = history_event_dict['action_description']+" - Soutenance du "+str(tmp['event_start'])+" au "+str(tmp['event_end'])
|
||
|
||
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, " Les convocations au jury 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 convocations au jury par emails"
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction créer une convocation à une soutenance de Jury Email pour un inscrit
|
||
"""
|
||
def Create_Jury_Soutenance_Convocation_By_Inscrit_Email(tab_files, Folder, diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_soutenance_id', 'courrier_template_id', 'inscription_id']
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
qry = {'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_APPRENANT',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
#print(" ##### qry = ", qry)
|
||
|
||
# 1 - Verifier que le modele de courrier est bien editable par individu
|
||
template_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_APPRENANT',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( template_courrier_data is None ):
|
||
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 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(template_courrier_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
|
||
|
||
# Traitement de l'eventuel fichier joint
|
||
tab_files_to_attache_to_mail = []
|
||
|
||
# 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)
|
||
|
||
|
||
|
||
# Verifier que l'inscrit est valide
|
||
local_qry = {'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
statgiaire_data = MYSY_GV.dbname['inscription'].find_one({'_id':ObjectId(str(diction['inscription_id'])), 'status':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (statgiaire_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du stagiaire est invalide ")
|
||
return False, " L'identifiant du stagiaire est invalide "
|
||
|
||
|
||
|
||
|
||
tab_stagiaire = []
|
||
tab_stagiaire.append(statgiaire_data['_id'])
|
||
|
||
|
||
# Verifier que la soutenance est valide
|
||
jury_soutenance_data = MYSY_GV.dbname['jury_soutenance'].find_one(
|
||
{'_id': ObjectId(str(diction['jury_soutenance_id'])), 'valide': '1', 'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (jury_soutenance_data is None):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de la soutenance est invalide ")
|
||
return False, " L'identifiant de la soutenance est invalide "
|
||
|
||
|
||
|
||
for saved_file in tab_files:
|
||
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)
|
||
|
||
send_in_production = 0
|
||
|
||
tab_emails_destinataire = []
|
||
|
||
if ("email_test" in diction.keys() and diction['email_test']):
|
||
send_in_production = 0
|
||
tab_email_test = str(diction['email_test']).replace(";", ",").split(",")
|
||
for email in tab_email_test:
|
||
email = email.strip()
|
||
if (mycommon.isEmailValide(email) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'adresse email " + str(email) + " est invalide ")
|
||
return False, " L'adresse email " + str(email) + " est invalide "
|
||
tab_emails_destinataire = tab_email_test
|
||
|
||
elif ("email_production" in diction.keys() and diction['email_production']):
|
||
send_in_production = 1
|
||
if (str(diction['email_production']) != "default"):
|
||
tab_email_prod = str(diction['email_production']).replace(";", ",").split(",")
|
||
for email in tab_email_prod:
|
||
email = email.strip()
|
||
if (mycommon.isEmailValide(str(email)) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'adresse email '" + str(email) + "' est invalide ")
|
||
return False, " L'adresse email " + str(email) + " est invalide "
|
||
tab_emails_destinataire = tab_email_prod
|
||
else:
|
||
send_in_production = 1
|
||
# On va chercher les adresse email de communication du
|
||
local_dict = {'token': str(diction['token']), '_id': str(diction['inscription_id'])}
|
||
|
||
local_status, tab_apprenant_contact = Inscription_mgt.Get_Statgiaire_Communication_Contact(local_dict)
|
||
if (local_status is False):
|
||
return local_status, tab_apprenant_contact
|
||
|
||
tmp_tab = []
|
||
# print(" ### tab_apprenant_contact = ", tab_apprenant_contact)
|
||
|
||
for tmp in tab_apprenant_contact:
|
||
if ("email" in tmp.keys()):
|
||
tab_emails_destinataire.append((tmp['email']))
|
||
|
||
if (len(tab_emails_destinataire) <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Aucune adresse email n'a été fourni. ")
|
||
return False, " Aucune adresse email n'a été fourni. "
|
||
|
||
tab_soutenance = []
|
||
tab_soutenance.append(jury_soutenance_data['_id'])
|
||
|
||
|
||
|
||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||
convention_dictionnary_data = {}
|
||
new_diction = {}
|
||
new_diction['token'] = diction['token']
|
||
new_diction['list_stagiaire_id'] = tab_stagiaire
|
||
new_diction['list_session_id'] = []
|
||
new_diction['list_class_id'] = []
|
||
new_diction['list_client_id'] = []
|
||
new_diction['list_apprenant_id'] = []
|
||
new_diction['list_jury_soutenance_id'] = tab_soutenance
|
||
|
||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||
|
||
if (local_status is False):
|
||
return local_status, local_retval
|
||
|
||
convention_dictionnary_data = local_retval
|
||
|
||
body = {
|
||
"params": convention_dictionnary_data,
|
||
}
|
||
orig_file_name = None
|
||
outputFilename = None
|
||
|
||
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
|
||
if ("joint_pdf" in template_courrier_data.keys() and str(template_courrier_data['joint_pdf']) == "1"):
|
||
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
|
||
"""
|
||
1 - Creation du PDF
|
||
"""
|
||
|
||
contenu_doc_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
|
||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||
|
||
orig_file_name = "Convocation_Soutenance_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||
|
||
|
||
# open output file for writing (truncated binary)
|
||
resultFile = open(outputFilename, "w+b")
|
||
|
||
# convert HTML to PDF
|
||
pisaStatus = pisa.CreatePDF(
|
||
src=sourceHtml, # the HTML to convert
|
||
dest=resultFile) # file handle to receive result
|
||
|
||
# close output file
|
||
resultFile.close()
|
||
|
||
# Attachement du fichier joint
|
||
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
||
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
||
|
||
encoders.encode_base64(file_to_attache_to_mail)
|
||
file_to_attache_to_mail.add_header('Content-Disposition',
|
||
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
||
|
||
new_node = {"attached_file": file_to_attache_to_mail}
|
||
tab_files_to_attache_to_mail.append(new_node)
|
||
|
||
## Creation du mail au format email
|
||
corps_mail_Template = jinja2.Template(str(template_courrier_data['corps_mail']))
|
||
sourceHtml = corps_mail_Template.render(params=body["params"])
|
||
html_mime = MIMEText(sourceHtml, 'html')
|
||
|
||
# Traitement du sujet du mail
|
||
sujet_mail_Template = jinja2.Template(str(template_courrier_data['sujet']))
|
||
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
||
|
||
# Creation de l'email à enoyer
|
||
msg = MIMEMultipart("alternative")
|
||
|
||
else:
|
||
## Creation du mail au format email
|
||
corps_mail_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
sourceHtml = corps_mail_Template.render(params=body["params"])
|
||
html_mime = MIMEText(sourceHtml, 'html')
|
||
|
||
# Traitement du sujet du mail
|
||
sujet_mail_Template = jinja2.Template(str(template_courrier_data['sujet']))
|
||
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
||
|
||
# Creation de l'email à enoyer
|
||
msg = MIMEMultipart("alternative")
|
||
|
||
|
||
# Recuperation des donnes smpt
|
||
local_stpm_status, partner_SMTP_COUNT_smtpsrv, partner_own_smtp_value, partner_SMTP_COUNT_password, partner_SMTP_COUNT_user, partner_SMTP_COUNT_From_User,\
|
||
partner_SMTP_COUNT_port = mycommon.Get_Partner_SMTP_Param(
|
||
str(my_partner['recid']))
|
||
|
||
if (local_stpm_status is False):
|
||
return local_stpm_status, partner_own_smtp_value
|
||
msg.attach(html_mime)
|
||
msg['From'] = partner_SMTP_COUNT_From_User
|
||
msg['Bcc'] = 'contact@mysy-training.com'
|
||
msg['Subject'] = sujetHtml
|
||
# Attacher l'eventuelle pièces jointes
|
||
for myfile in tab_files_to_attache_to_mail:
|
||
msg.attach(myfile['attached_file'])
|
||
|
||
# msg['to'] = "billardman01@hotmail.com"
|
||
toaddrs = ",".join(tab_emails_destinataire)
|
||
msg['to'] = str(toaddrs)
|
||
|
||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||
|
||
smtpserver.ehlo()
|
||
smtpserver.starttls()
|
||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||
|
||
val = smtpserver.send_message(msg)
|
||
smtpserver.close()
|
||
|
||
|
||
print(" Email envoyé " + str(val))
|
||
|
||
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 par email convocation du jury "
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction permet de telecharger (PDF) la convocation des membres du jury concernés
|
||
par une soutenance du jury
|
||
"""
|
||
def Send_Jury_Membre_Convocation_By_PDF(diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'tab_jury_ids', 'courrier_template_id']
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
"""
|
||
Pour chaque membre du jury
|
||
"""
|
||
my_jury_ids = ""
|
||
if ("tab_jury_ids" in diction.keys()):
|
||
if diction['tab_jury_ids']:
|
||
my_jury_ids = diction['tab_jury_ids']
|
||
|
||
tab_tab_jury_ids_work = str(my_jury_ids).split(",")
|
||
tab_jury_ids = []
|
||
tab_jury_ids_ObjectId = []
|
||
|
||
for tmp in tab_tab_jury_ids_work:
|
||
if (tmp):
|
||
is_jury_id_valide = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_jury_id_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du jury est invalide : "+str(tmp))
|
||
return False, " L'identifiant du jury est invalide : "+str(tmp)
|
||
|
||
tab_jury_ids.append(tmp)
|
||
tab_jury_ids_ObjectId.append(ObjectId(tmp))
|
||
|
||
|
||
|
||
for_log_history_description = []
|
||
|
||
# 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'])}
|
||
)
|
||
|
||
if(courrier_template_data is None ):
|
||
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 "
|
||
|
||
|
||
if("contenu_doc" not in courrier_template_data.keys() or len(str(courrier_template_data['contenu_doc'])) <= 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " contenu_doc : La configuration du modèle de courrier est invalide ")
|
||
return False, " contenu_doc : La configuration du modèle de courrier est invalide "
|
||
|
||
|
||
"""
|
||
Recuperer la liste des inscrits concernés par la soutenance
|
||
"""
|
||
# Stokage des nom de fichier à zipper
|
||
list_file_name_to_zip = []
|
||
|
||
for jury in tab_jury_ids :
|
||
for jury_membre in MYSY_GV.dbname['jury_membre'].find({'jury_id':str(jury),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])}):
|
||
|
||
|
||
local_diction = {}
|
||
# field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_id']
|
||
local_diction['token'] = diction['token']
|
||
local_diction['jury_membre_id'] = str(jury_membre['_id'])
|
||
local_diction['courrier_template_id'] = diction['courrier_template_id']
|
||
local_diction['jury_id'] = str(jury)
|
||
|
||
|
||
local_status, local_full_file_name = Create_Jury_Convocation_By_Membre_PDF(local_diction)
|
||
if( local_status is False):
|
||
return local_status, local_full_file_name
|
||
else:
|
||
list_file_name_to_zip.append(str(local_full_file_name))
|
||
|
||
|
||
# Create a ZipFile Object
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-3:]
|
||
zip_file_name = str(MYSY_GV.TEMPORARY_DIRECTORY_V2) + "List_Convocation_Jury_" + str(ts) + "_.zip"
|
||
|
||
with ZipFile(zip_file_name, 'w') as zip_object:
|
||
for pdf_files in list_file_name_to_zip :
|
||
#print(" ### fichier a zipper = ", pdf_files)
|
||
zip_object.write(str(pdf_files))
|
||
|
||
|
||
if os.path.exists(zip_file_name):
|
||
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||
"""
|
||
Mettre à jour l'historique pour que les convocation ont été imprimées
|
||
"""
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
|
||
for jury in tab_jury_ids:
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(jury)
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Impression convocation pour les membres du jury "
|
||
|
||
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, send_file(zip_file_name, as_attachment=True)
|
||
|
||
|
||
return False, " Impossible de générer les convocations jury par PDF (1) "
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de générer les convocations jury par PDF"
|
||
|
||
|
||
"""
|
||
Cette fonction créer une convocation pour les membre de Jury PDF pour un inscrit et retourne le document
|
||
"""
|
||
def Create_Jury_Convocation_By_Membre_PDF(diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_membre_id', 'courrier_template_id', 'jury_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 la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
qry = {'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_MEMBRE',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
#print(" ##### qry = ", qry)
|
||
|
||
# 1 - Verifier que le modele de courrier est bien editable par individu
|
||
template_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_MEMBRE',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( template_courrier_data is None ):
|
||
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 "
|
||
|
||
|
||
|
||
|
||
|
||
jury_membre_data = MYSY_GV.dbname['jury_membre'].find_one({'_id':ObjectId(str(diction['jury_membre_id'])), 'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (jury_membre_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du membre du jury est invalide ")
|
||
return False, " L'identifiant du membre du jury est invalide "
|
||
|
||
hr_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||
{'_id': ObjectId(str(jury_membre_data['rh_id'])), 'partner_recid': str(my_partner['recid'])})
|
||
|
||
if (hr_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de l'emloyé est invalide ")
|
||
return False, " L'identifiant de l'emloyé est invalide "
|
||
|
||
|
||
|
||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||
convention_dictionnary_data = {}
|
||
new_diction = {}
|
||
new_diction['token'] = diction['token']
|
||
new_diction['list_stagiaire_id'] = []
|
||
new_diction['list_session_id'] = []
|
||
new_diction['list_class_id'] = []
|
||
new_diction['list_client_id'] = []
|
||
new_diction['list_apprenant_id'] = []
|
||
|
||
|
||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||
|
||
if (local_status is False):
|
||
return local_status, local_retval
|
||
|
||
convention_dictionnary_data = local_retval
|
||
convention_dictionnary_data['hr_data'] = hr_data
|
||
|
||
"""
|
||
Recuperer les données du jury
|
||
"""
|
||
jury_data_node = {}
|
||
jury_data = MYSY_GV.dbname['jury'].find_one({'_id':ObjectId(str(diction['jury_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (jury_data and "code" in jury_data.keys()):
|
||
jury_data_node['code'] = jury_data['code']
|
||
else:
|
||
jury_data_node['code'] = ""
|
||
|
||
|
||
if (jury_data and "jury_salle" in jury_data.keys()):
|
||
jury_data_node['jury_salle'] = jury_data['jury_salle']
|
||
else:
|
||
jury_data_node['jury_salle'] = ""
|
||
|
||
if (jury_data and "adresse" in jury_data.keys()):
|
||
jury_data_node['adresse'] = jury_data['adresse']
|
||
else:
|
||
jury_data_node['adresse'] = ""
|
||
|
||
if (jury_data and "code_postal" in jury_data.keys()):
|
||
jury_data_node['code_postal'] = jury_data['code_postal']
|
||
else:
|
||
jury_data_node['code_postal'] = ""
|
||
|
||
if (jury_data and "ville" in jury_data.keys()):
|
||
jury_data_node['ville'] = jury_data['ville']
|
||
else:
|
||
jury_data_node['ville'] = ""
|
||
|
||
if (jury_data and "pays" in jury_data.keys()):
|
||
jury_data_node['pays'] = jury_data['pays']
|
||
else:
|
||
jury_data_node['pays'] = ""
|
||
|
||
convention_dictionnary_data['jury_data'] = jury_data_node
|
||
|
||
"""
|
||
Recuperer la liste des soutenances concernée par ce jury
|
||
"""
|
||
list_soutenance = []
|
||
for jury_apprenant_data in MYSY_GV.dbname['jury_apprenant'].find({'jury_id':diction['jury_id'],
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])}):
|
||
|
||
local_node = {}
|
||
if( "agenda_id" in jury_apprenant_data and jury_apprenant_data['agenda_id']):
|
||
local_agenda_data = MYSY_GV.dbname['agenda'].find_one({ 'partner_owner_recid':str(my_partner['recid']),
|
||
'_id':ObjectId(str(jury_apprenant_data['agenda_id']))})
|
||
|
||
local_date = str(local_agenda_data['event_start'])[0:16]
|
||
new_date = datetime.strptime(str(local_date), '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M")
|
||
local_node['event_start'] = str(new_date)
|
||
|
||
local_date = str(local_agenda_data['event_end'])[0:16]
|
||
new_date = datetime.strptime(str(local_date), '%Y-%m-%dT%H:%M').strftime("%d/%m/%Y %H:%M")
|
||
local_node['event_end'] = str(new_date)
|
||
|
||
|
||
|
||
|
||
if ("inscription_id" in jury_apprenant_data and jury_apprenant_data['inscription_id']):
|
||
local_inscription_data = MYSY_GV.dbname['inscription'].find_one({'partner_owner_recid': str(my_partner['recid']),
|
||
'_id': ObjectId(str(jury_apprenant_data['inscription_id']))})
|
||
|
||
|
||
if( local_inscription_data and "nom" in local_inscription_data.keys() ):
|
||
local_node['nom'] = local_inscription_data['nom']
|
||
else:
|
||
local_node['nom'] = ""
|
||
|
||
if (local_inscription_data and "nom" in local_inscription_data.keys()):
|
||
local_node['prenom'] = local_inscription_data['prenom']
|
||
else:
|
||
local_node['prenom'] = ""
|
||
|
||
if (local_inscription_data and "nom" in local_inscription_data.keys()):
|
||
local_node['email'] = local_inscription_data['email']
|
||
else:
|
||
local_node['email'] = ""
|
||
|
||
if (local_inscription_data and "civilite" in local_inscription_data.keys()):
|
||
local_node['civilite'] = local_inscription_data['civilite']
|
||
else:
|
||
local_node['civilite'] = ""
|
||
|
||
list_soutenance.append(local_node)
|
||
|
||
|
||
#print(" #### list_soutenance = ", list_soutenance)
|
||
convention_dictionnary_data['list_soutenance'] = list_soutenance
|
||
|
||
body = {
|
||
"params": convention_dictionnary_data,
|
||
}
|
||
|
||
"""
|
||
Creation du ficier PDF
|
||
"""
|
||
|
||
contenu_doc_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
|
||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||
|
||
orig_file_name = "Convocation_Jury_Membre_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||
|
||
# open output file for writing (truncated binary)
|
||
resultFile = open(outputFilename, "w+b")
|
||
|
||
# convert HTML to PDF
|
||
pisaStatus = pisa.CreatePDF(
|
||
src=sourceHtml, # the HTML to convert
|
||
dest=resultFile) # file handle to receive result
|
||
|
||
# close output file
|
||
resultFile.close()
|
||
|
||
return True, outputFilename
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de créer le fichier pdf de convocation du jury "
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction permet d'envoyer par email la convocation des membres du jury concernés
|
||
par une soutenance du jury
|
||
"""
|
||
def Send_Jury_Membre_Convocation_By_Email(tab_files, Folder, diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'tab_jury_ids', 'courrier_template_id']
|
||
|
||
for val in field_list_obligatoire:
|
||
if val not in diction:
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
# Sauvegarde des fichiers joints depuis le front
|
||
tab_saved_file_full_path = []
|
||
for file in tab_files:
|
||
status, saved_file_full_path = mycommon.Upload_Save_PDF_IMG_File(file, Folder)
|
||
if (status is False):
|
||
mycommon.myprint("Impossible de récupérer correctement le fichier à importer")
|
||
return False, "Impossible de récupérer correctement le fichier à importer"
|
||
|
||
tab_saved_file_full_path.append(saved_file_full_path)
|
||
|
||
"""
|
||
Pour chaque membre du jury
|
||
"""
|
||
my_jury_ids = ""
|
||
if ("tab_jury_ids" in diction.keys()):
|
||
if diction['tab_jury_ids']:
|
||
my_jury_ids = diction['tab_jury_ids']
|
||
|
||
tab_tab_jury_ids_work = str(my_jury_ids).split(",")
|
||
tab_jury_ids = []
|
||
tab_jury_ids_ObjectId = []
|
||
|
||
for tmp in tab_tab_jury_ids_work:
|
||
if (tmp):
|
||
is_jury_id_valide = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(tmp)),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_jury_id_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du jury est invalide : "+str(tmp))
|
||
return False, " L'identifiant du jury est invalide : "+str(tmp)
|
||
|
||
tab_jury_ids.append(tmp)
|
||
tab_jury_ids_ObjectId.append(ObjectId(tmp))
|
||
|
||
|
||
|
||
for_log_history_description = []
|
||
|
||
# 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'])}
|
||
)
|
||
|
||
if(courrier_template_data is None ):
|
||
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 "
|
||
|
||
|
||
if("contenu_doc" not in courrier_template_data.keys() or len(str(courrier_template_data['contenu_doc'])) <= 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " contenu_doc : La configuration du modèle de courrier est invalide ")
|
||
return False, " contenu_doc : La configuration du modèle de courrier est invalide "
|
||
|
||
|
||
"""
|
||
Recuperer la liste des inscrits concernés par la soutenance
|
||
"""
|
||
# Stokage des nom de fichier à zipper
|
||
list_file_name_to_zip = []
|
||
|
||
for jury in tab_jury_ids :
|
||
for jury_membre in MYSY_GV.dbname['jury_membre'].find({'jury_id':str(jury),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])}):
|
||
|
||
|
||
local_diction = {}
|
||
# field_list_obligatoire = ['token', 'session_id', 'courrier_template_id', 'client_id']
|
||
local_diction['token'] = diction['token']
|
||
local_diction['jury_membre_id'] = str(jury_membre['_id'])
|
||
local_diction['courrier_template_id'] = diction['courrier_template_id']
|
||
local_diction['jury_id'] = str(jury)
|
||
local_diction['email_test'] = diction['email_test']
|
||
local_diction['email_production'] = diction['email_production']
|
||
|
||
local_status, local_full_file_name = Create_Jury_Convocation_By_Membre_Email(tab_saved_file_full_path, Folder, local_diction)
|
||
if( local_status is False):
|
||
return local_status, local_full_file_name
|
||
else:
|
||
list_file_name_to_zip.append(str(local_full_file_name))
|
||
|
||
|
||
|
||
"""
|
||
## Add to log history
|
||
"""
|
||
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
|
||
for jury in tab_jury_ids:
|
||
# Pour la collection inscription
|
||
history_event_dict = {}
|
||
history_event_dict['token'] = str(diction['token'])
|
||
history_event_dict['related_collection'] = "jury"
|
||
history_event_dict['related_collection_recid'] = str(jury)
|
||
history_event_dict['action_date'] = str(now)
|
||
|
||
history_event_dict['action_description'] = "Envoi de l'email de convocation des membres du jury "
|
||
|
||
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, " Les emails de convocation du jury ont été correctement envoyés "
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible d'envoyer l'email de convocation du jury "
|
||
|
||
|
||
"""
|
||
Cette fonction créer une convocation pour les membre de Jury Email pour un inscrit et retourne le document
|
||
"""
|
||
def Create_Jury_Convocation_By_Membre_Email(tab_files, Folder, diction):
|
||
try:
|
||
field_list_obligatoire = ['token', 'jury_membre_id', 'courrier_template_id', 'jury_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 la liste des arguments ")
|
||
return False, " La valeur '" + val + "' n'est pas presente dans la liste des arguments"
|
||
|
||
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
|
||
|
||
qry = {'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_MEMBRE',
|
||
'partner_owner_recid':str(my_partner['recid'])}
|
||
|
||
#print(" ##### qry = ", qry)
|
||
|
||
# 1 - Verifier que le modele de courrier est bien editable par individu
|
||
template_courrier_data = MYSY_GV.dbname['courrier_template'].find_one({'_id':ObjectId(str(diction['courrier_template_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'ref_interne': 'JURY_CONVOCATION_MEMBRE',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( template_courrier_data is None ):
|
||
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 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(template_courrier_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
|
||
|
||
|
||
# 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(template_courrier_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
|
||
|
||
# Traitement de l'eventuel fichier joint
|
||
tab_files_to_attache_to_mail = []
|
||
|
||
|
||
# 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)
|
||
|
||
|
||
jury_membre_data = MYSY_GV.dbname['jury_membre'].find_one({'_id':ObjectId(str(diction['jury_membre_id'])), 'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if (jury_membre_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant du membre du jury est invalide ")
|
||
return False, " L'identifiant du membre du jury est invalide "
|
||
|
||
hr_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
||
{'_id': ObjectId(str(jury_membre_data['rh_id'])), 'partner_recid': str(my_partner['recid'])})
|
||
|
||
if (hr_data is None ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'identifiant de l'emloyé est invalide ")
|
||
return False, " L'identifiant de l'emloyé est invalide "
|
||
|
||
for saved_file in tab_files:
|
||
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)
|
||
|
||
send_in_production = 0
|
||
|
||
tab_emails_destinataire = []
|
||
|
||
if ("email_test" in diction.keys() and diction['email_test']):
|
||
send_in_production = 0
|
||
tab_email_test = str(diction['email_test']).replace(";", ",").split(",")
|
||
for email in tab_email_test:
|
||
email = email.strip()
|
||
if (mycommon.isEmailValide(email) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'adresse email " + str(email) + " est invalide ")
|
||
return False, " L'adresse email " + str(email) + " est invalide "
|
||
tab_emails_destinataire = tab_email_test
|
||
|
||
elif ("email_production" in diction.keys() and diction['email_production']):
|
||
send_in_production = 1
|
||
if (str(diction['email_production']) != "default"):
|
||
tab_email_prod = str(diction['email_production']).replace(";", ",").split(",")
|
||
for email in tab_email_prod:
|
||
email = email.strip()
|
||
if (mycommon.isEmailValide(str(email)) is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " L'adresse email '" + str(email) + "' est invalide ")
|
||
return False, " L'adresse email " + str(email) + " est invalide "
|
||
tab_emails_destinataire = tab_email_prod
|
||
else:
|
||
send_in_production = 1
|
||
|
||
if ("email" in hr_data.keys()):
|
||
tab_emails_destinataire.append((hr_data['email']))
|
||
|
||
if (len(tab_emails_destinataire) <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][
|
||
3]) + " Aucune adresse email n'a été fourni. ")
|
||
return False, " Aucune adresse email n'a été fourni. "
|
||
|
||
|
||
# Creation du dictionnaire d'information à utiliser pour la creation du doc
|
||
convention_dictionnary_data = {}
|
||
new_diction = {}
|
||
new_diction['token'] = diction['token']
|
||
new_diction['list_stagiaire_id'] = []
|
||
new_diction['list_session_id'] = []
|
||
new_diction['list_class_id'] = []
|
||
new_diction['list_client_id'] = []
|
||
new_diction['list_apprenant_id'] = []
|
||
|
||
|
||
local_status, local_retval = mycommon.Get_Dictionnary_data_For_Template(new_diction)
|
||
|
||
if (local_status is False):
|
||
return local_status, local_retval
|
||
|
||
convention_dictionnary_data = local_retval
|
||
convention_dictionnary_data['hr_data'] = hr_data
|
||
|
||
body = {
|
||
"params": convention_dictionnary_data,
|
||
}
|
||
|
||
|
||
# Verifier s'il s'agit d'un document à envoyer avec une version de pièce jointe.
|
||
if ("joint_pdf" in template_courrier_data.keys() and str(template_courrier_data['joint_pdf']) == "1"):
|
||
# Il s'agit bien d'un envoie avec 'contenu_doc' en pièce jointe PDF
|
||
"""
|
||
1 - Creation du PDF
|
||
"""
|
||
|
||
contenu_doc_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
|
||
sourceHtml = contenu_doc_Template.render(params=body["params"])
|
||
|
||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||
ts = datetime.now().timestamp()
|
||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||
|
||
orig_file_name = "Convocation_Jury_Membre_" + str(my_partner['recid'])[0:5] + "_" + str(ts) + ".pdf"
|
||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||
|
||
# open output file for writing (truncated binary)
|
||
resultFile = open(outputFilename, "w+b")
|
||
|
||
# convert HTML to PDF
|
||
pisaStatus = pisa.CreatePDF(
|
||
src=sourceHtml, # the HTML to convert
|
||
dest=resultFile) # file handle to receive result
|
||
|
||
# close output file
|
||
resultFile.close()
|
||
|
||
# Attachement du fichier joint
|
||
file_to_attache_to_mail = MIMEBase('application', "octet-stream")
|
||
file_to_attache_to_mail.set_payload(open(outputFilename, "rb").read())
|
||
|
||
encoders.encode_base64(file_to_attache_to_mail)
|
||
file_to_attache_to_mail.add_header('Content-Disposition',
|
||
'attachment; filename="{0}"'.format(os.path.basename(outputFilename)))
|
||
|
||
new_node = {"attached_file": file_to_attache_to_mail}
|
||
tab_files_to_attache_to_mail.append(new_node)
|
||
|
||
## Creation du mail au format email
|
||
corps_mail_Template = jinja2.Template(str(template_courrier_data['corps_mail']))
|
||
sourceHtml = corps_mail_Template.render(params=body["params"])
|
||
html_mime = MIMEText(sourceHtml, 'html')
|
||
|
||
# Traitement du sujet du mail
|
||
sujet_mail_Template = jinja2.Template(str(template_courrier_data['sujet']))
|
||
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
||
|
||
# Creation de l'email à enoyer
|
||
msg = MIMEMultipart("alternative")
|
||
|
||
else:
|
||
## Creation du mail au format email
|
||
corps_mail_Template = jinja2.Template(str(template_courrier_data['contenu_doc']))
|
||
sourceHtml = corps_mail_Template.render(params=body["params"])
|
||
html_mime = MIMEText(sourceHtml, 'html')
|
||
|
||
# Traitement du sujet du mail
|
||
sujet_mail_Template = jinja2.Template(str(template_courrier_data['sujet']))
|
||
sujetHtml = sujet_mail_Template.render(params=body["params"])
|
||
|
||
# Creation de l'email à enoyer
|
||
msg = MIMEMultipart("alternative")
|
||
|
||
# Recuperation des donnes smpt
|
||
local_stpm_status, partner_SMTP_COUNT_smtpsrv, partner_own_smtp_value, partner_SMTP_COUNT_password, partner_SMTP_COUNT_user, partner_SMTP_COUNT_From_User, \
|
||
partner_SMTP_COUNT_port = mycommon.Get_Partner_SMTP_Param(
|
||
str(my_partner['recid']))
|
||
|
||
if (local_stpm_status is False):
|
||
return local_stpm_status, partner_own_smtp_value
|
||
msg.attach(html_mime)
|
||
msg['From'] = partner_SMTP_COUNT_From_User
|
||
msg['Bcc'] = 'contact@mysy-training.com'
|
||
msg['Subject'] = sujetHtml
|
||
# Attacher l'eventuelle pièces jointes
|
||
for myfile in tab_files_to_attache_to_mail:
|
||
msg.attach(myfile['attached_file'])
|
||
|
||
# msg['to'] = "billardman01@hotmail.com"
|
||
toaddrs = ",".join(tab_emails_destinataire)
|
||
msg['to'] = str(toaddrs)
|
||
|
||
smtpserver = smtplib.SMTP(partner_SMTP_COUNT_smtpsrv, partner_SMTP_COUNT_port)
|
||
|
||
smtpserver.ehlo()
|
||
smtpserver.starttls()
|
||
smtpserver.login(partner_SMTP_COUNT_user, partner_SMTP_COUNT_password)
|
||
|
||
val = smtpserver.send_message(msg)
|
||
smtpserver.close()
|
||
|
||
print(" Email envoyé " + str(val))
|
||
|
||
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 les email de convocation du jury "
|
||
|
||
|
||
|
||
"""
|
||
Cette fonction met à jour la decision du jury pour
|
||
un inscrit (jury_cac)
|
||
"""
|
||
|
||
def Add_Update_Inscrit_Juy_Promo_Decision(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'jury_id', 'tab_inscriptions_ids', 'jury_observation', 'jury_note', 'jury_validation']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'jury_id', 'tab_inscriptions_ids', 'jury_observation', 'jury_note', 'jury_validation']
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
is_existe_jury = MYSY_GV.dbname['jury'].count_documents(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_jury != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du jury est invalide ")
|
||
return False, " L'identifiant du jury est invalide "
|
||
|
||
jury_data = MYSY_GV.dbname['jury'].find_one(
|
||
{'_id': ObjectId(str(diction['jury_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
tab_inscriptions_ids = ""
|
||
tab_inscriptions_ids_ObjectId = []
|
||
|
||
if ("tab_inscriptions_ids" in diction.keys()):
|
||
if diction['tab_inscriptions_ids']:
|
||
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
||
|
||
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
||
|
||
# Controle de validité des inscriptions
|
||
for my_inscription in tab_inscriptions_ids_splited:
|
||
# Verifier que l'inscription est valide
|
||
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents(
|
||
{'_id': ObjectId(str(my_inscription)),
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (my_inscription_is_valide != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' est invalide ")
|
||
return False, " L'inscription_id '" + my_inscription + "' est invalide "
|
||
|
||
tab_inscriptions_ids_ObjectId.append(ObjectId(str(my_inscription)))
|
||
|
||
update_data = {}
|
||
update_data['date_update'] = str(datetime.now())
|
||
update_data['update_by'] = str(my_partner['_id'])
|
||
update_data['jury_observation'] = str(diction['jury_observation'])
|
||
update_data['jury_note'] = str(diction['jury_note'])
|
||
update_data['jury_validation'] = str(diction['jury_validation'])
|
||
|
||
MYSY_GV.dbname['inscription'].update_many({'_id': {'$in' : tab_inscriptions_ids_ObjectId},
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
|
||
},
|
||
{'$set': update_data}
|
||
)
|
||
|
||
return True, " La décision du jury été correctement mise à jour"
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de mettre à jour la décision du jury "
|
||
|
||
|
||
"""
|
||
Cette fonction met à jour les observation du jury sur les notes UE
|
||
|
||
collection : session_formation_final_note_classement
|
||
"""
|
||
def Add_Update_UE_Jury_Observation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'tab_ids', 'jury_observation', 'jury_note', 'jury_validation']
|
||
|
||
incom_keys = diction.keys()
|
||
for val in incom_keys:
|
||
if val not in field_list and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'tab_ids', 'jury_observation', 'jury_note', 'jury_validation']
|
||
|
||
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 la liste des arguments ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
tab_ids = ""
|
||
tab_ids = []
|
||
tab_ids_ObjectId = []
|
||
|
||
if ("tab_ids" in diction.keys()):
|
||
if diction['tab_ids']:
|
||
tab_ids = diction['tab_ids']
|
||
|
||
|
||
tab_ids_splited = str(tab_ids).split(",")
|
||
|
||
|
||
# Controle de validité des inscriptions
|
||
for my_session_formation_final_note_classement in tab_ids_splited:
|
||
if( my_session_formation_final_note_classement):
|
||
tab_ids_ObjectId.append(ObjectId(str(my_session_formation_final_note_classement)))
|
||
|
||
|
||
|
||
update_data = {}
|
||
update_data['date_update'] = str(datetime.now())
|
||
update_data['update_by'] = str(my_partner['_id'])
|
||
update_data['jury_observation'] = str(diction['jury_observation'])
|
||
update_data['jury_note'] = str(diction['jury_note'])
|
||
update_data['jury_validation'] = str(diction['jury_validation'])
|
||
|
||
MYSY_GV.dbname['session_formation_final_note_classement'].update_many({'_id': {'$in' : tab_ids_ObjectId},
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
},
|
||
{'$set': update_data}
|
||
)
|
||
|
||
return True, " La décision du jury été correctement mise à jour"
|
||
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible de mettre à jour la décision du jury "
|