1332 lines
52 KiB
Python
1332 lines
52 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 bson
|
||
import pymongo
|
||
import xlsxwriter
|
||
from pymongo import MongoClient
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
from datetime import datetime, date
|
||
|
||
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' ]
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
"""
|
||
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 "
|
||
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
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:
|
||
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' ]
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
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 "
|
||
|
||
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 "
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes"
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
|
||
|
||
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 "
|
||
|
||
|
||
|
||
"""
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
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)
|
||
|
||
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 liste ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
"""
|
||
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)
|
||
|
||
# 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 liste ")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification de l'identité et autorisation de l'entité qui
|
||
appelle cette API
|
||
"""
|
||
token = ""
|
||
if ("token" in diction.keys()):
|
||
if diction['token']:
|
||
token = diction['token']
|
||
|
||
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
||
if (local_status is not True):
|
||
return local_status, my_partner
|
||
|
||
filt_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'] = ""
|
||
|
||
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 "
|
||
|
||
|