1847 lines
72 KiB
Python
1847 lines
72 KiB
Python
"""
|
|
Ce fichier permet de gerer de tout ce qui a atrait aux ressources humaines.
|
|
c'est dire :
|
|
- enseignent
|
|
- cadre administratif
|
|
- employés,
|
|
etc
|
|
|
|
Une ressource humaine a toujours un profil (enseignant, cadre admin) et une fonction.
|
|
"""
|
|
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
import GlobalVariable as MYSY_GV
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
|
|
|
|
|
|
def Add_Ressource_Humaine(diction):
|
|
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "nom", "email", "telephone", "website", "comment",'adr_adresse', 'adr_code_postal',
|
|
'adr_ville', 'adr_pays', 'profil', 'telephone_mobile', 'linkedin',
|
|
'facebook', 'twitter', 'prenom', 'fonction', 'civilite', 'superieur_hierarchie_id', 'ismanager']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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', "email", ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
|
|
"""
|
|
Verification s'il n'existe pas un cient du partenaire qui porte la meme adresse email
|
|
"""
|
|
|
|
tmp_count = MYSY_GV.dbname['ressource_humaine'].count_documents({'email': str(diction['email']),
|
|
'valide': '1', 'partner_recid': my_partner['recid']})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Il existe déjà une personne qui porte le même email principal = " +str(diction['email']))
|
|
|
|
return False, " - Vous avez déjà une personne qui a le même email principal " +str(diction['email'])+" "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = my_partner['recid']
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
if diction['nom']:
|
|
nom = diction['nom']
|
|
data['nom'] = diction['nom']
|
|
|
|
|
|
prenom = ""
|
|
if ("prenom" in diction.keys()):
|
|
if diction['prenom']:
|
|
prenom = diction['prenom']
|
|
data['prenom'] = diction['prenom']
|
|
|
|
ismanager = "0"
|
|
if ("ismanager" in diction.keys()):
|
|
if diction['ismanager']:
|
|
ismanager = diction['ismanager']
|
|
if( str(ismanager).lower() not in ['1', '0', 'oui', 'non']):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Valeur du champ 'manager' invalide : "+str(ismanager)+". Les valeurs acceptée : '1', '0', 'oui', 'non'")
|
|
return False, str(inspect.stack()[0][3]) + " - Valeur du champ 'manager' invalide : "+str(ismanager)+". Les valeurs acceptée : '1', '0', 'oui', 'non'"
|
|
|
|
if( str(ismanager).lower() == "oui"):
|
|
ismanager = "1"
|
|
elif (str(ismanager).lower() == "non"):
|
|
ismanager = "0"
|
|
|
|
ismanager = diction['ismanager']
|
|
|
|
data['ismanager'] = ismanager
|
|
|
|
fonction = ""
|
|
if ("fonction" in diction.keys()):
|
|
if diction['fonction']:
|
|
fonction = diction['fonction']
|
|
data['fonction'] = diction['fonction']
|
|
|
|
superieur_hierarchie_id = ""
|
|
if ("superieur_hierarchie_id" in diction.keys()):
|
|
if diction['superieur_hierarchie_id']:
|
|
superieur_hierarchie_id = diction['superieur_hierarchie_id']
|
|
data['superieur_hierarchie_id'] = diction['superieur_hierarchie_id']
|
|
|
|
civilite = ""
|
|
if ("civilite" in diction.keys()):
|
|
if diction['civilite']:
|
|
civilite = diction['civilite']
|
|
data['civilite'] = diction['civilite']
|
|
|
|
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
if diction['adr_adresse']:
|
|
adr_adresse = diction['adr_adresse']
|
|
data['adr_adresse'] = diction['adr_adresse']
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
if diction['adr_code_postal']:
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data['adr_code_postal'] = diction['adr_code_postal']
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
if diction['adr_ville']:
|
|
adr_ville = diction['adr_ville']
|
|
data['adr_ville'] = diction['adr_ville']
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
if diction['adr_pays']:
|
|
adr_pays = diction['adr_pays']
|
|
data['adr_pays'] = diction['adr_pays']
|
|
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
if diction['email']:
|
|
email = diction['email']
|
|
data['email'] = diction['email']
|
|
if( mycommon.isEmailValide(email) is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - L'adresse email "+str(email)+" n'est pas valide")
|
|
|
|
return False, " - - L'adresse email "+str(email)+" n'est pas valide "
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
if diction['telephone']:
|
|
telephone = diction['telephone']
|
|
data['telephone'] = diction['telephone']
|
|
|
|
telephone_mobile = ""
|
|
if ("telephone_mobile" in diction.keys()):
|
|
if diction['telephone_mobile']:
|
|
telephone_mobile = diction['telephone_mobile']
|
|
data['telephone_mobile'] = diction['telephone_mobile']
|
|
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
if diction['website']:
|
|
website = diction['website']
|
|
data['website'] = diction['website']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = diction['comment']
|
|
|
|
linkedin = ""
|
|
if ("linkedin" in diction.keys()):
|
|
if diction['linkedin']:
|
|
linkedin = diction['linkedin']
|
|
data['linkedin'] = diction['linkedin']
|
|
|
|
facebook = ""
|
|
if ("facebook" in diction.keys()):
|
|
if diction['facebook']:
|
|
facebook = diction['facebook']
|
|
data['facebook'] = diction['facebook']
|
|
|
|
twitter = ""
|
|
if ("twitter" in diction.keys()):
|
|
if diction['twitter']:
|
|
twitter = diction['twitter']
|
|
data['twitter'] = diction['twitter']
|
|
|
|
|
|
profil = ""
|
|
if ("profil" in diction.keys()):
|
|
if diction['profil']:
|
|
profil = diction['profil']
|
|
data['profil'] = diction['profil']
|
|
Rh_profil_count = MYSY_GV.dbname['ressource_humaine_profil'].count_documents({'profil_nom':str(profil), 'valide':'1', 'locked':'0'})
|
|
if( Rh_profil_count != 1):
|
|
mycommon.myprint(
|
|
"- Le type de profil "+str(profil)+" n'est pas autorisé")
|
|
return False, "- Le type de profil "+str(profil)+" n'est pas autorisé"
|
|
|
|
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
data['date_update'] = str(datetime.now())
|
|
|
|
# Creation du RecId
|
|
data['recid'] = mycommon.create_user_recid()
|
|
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['ressource_humaine'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le contact ")
|
|
return False, " Impossible de créer la ressource "
|
|
|
|
|
|
return True, " Le contact a été correctement créé"
|
|
|
|
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'ajouter la ressource "
|
|
|
|
|
|
"""
|
|
Mise à jour d'une personne en se basant sur sont _id
|
|
"""
|
|
def Update_Ressource_Humaine(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "nom", "prenom", "email",
|
|
"telephone", "website", "comment",'adr_adresse', 'adr_code_postal',
|
|
'adr_ville', 'adr_pays', 'profil', 'telephone_mobile', 'linkedin',
|
|
'facebook', 'twitter', '_id', 'prenom', 'fonction', 'civilite',
|
|
'superieur_hierarchie_id', 'ismanager']
|
|
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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', 'email']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
"""
|
|
Verification si cette adresse email n'existe pas deja pour ce partner
|
|
"""
|
|
|
|
qry_update = {'_id': ObjectId(str(diction['_id'])), 'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid']),}
|
|
|
|
|
|
|
|
print(" ### qry_update aa = ", qry_update)
|
|
|
|
tmp_count = MYSY_GV.dbname['ressource_humaine'].count_documents(qry_update)
|
|
if (tmp_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Cette personne n'existe pas: nom = "+str(diction['nom']))
|
|
|
|
return False, " - Cette personne n'est pas reconnue dans le système "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data_update = {}
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
data_update['nom'] = diction['nom']
|
|
|
|
fonction = ""
|
|
if ("fonction" in diction.keys()):
|
|
data_update['fonction'] = diction['fonction']
|
|
|
|
civilite = ""
|
|
if ("civilite" in diction.keys()):
|
|
data_update['civilite'] = diction['civilite']
|
|
|
|
ismanager = "0"
|
|
if ("ismanager" in diction.keys()):
|
|
ismanager = diction['ismanager']
|
|
if (ismanager != "0" and ismanager != "1"):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Valeur du champ 'manager' invalide : " + str(
|
|
ismanager) + ". Les valeurs acceptée : 1 ou 0")
|
|
return False, str(inspect.stack()[0][3]) + " - Valeur du champ 'manager' invalide : " + str(
|
|
ismanager) + ". Les valeurs acceptée : 1 ou 0"
|
|
|
|
ismanager = diction['ismanager']
|
|
|
|
data_update['ismanager'] = ismanager
|
|
|
|
|
|
|
|
prenom = ""
|
|
if ("prenom" in diction.keys()):
|
|
data_update['prenom'] = diction['prenom']
|
|
|
|
superieur_hierarchie_id = ""
|
|
if ("superieur_hierarchie_id" in diction.keys()):
|
|
data_update['superieur_hierarchie_id'] = diction['superieur_hierarchie_id']
|
|
|
|
profil = ""
|
|
if ("profil" in diction.keys()):
|
|
profil = diction['profil']
|
|
data_update['profil'] = diction['profil']
|
|
if (profil not in MYSY_GV.RESSOURCE_PROFIL):
|
|
mycommon.myprint( "- Le type de profil " + str(profil) + " n'est pas autorisé")
|
|
return False, "- Le type de profil " + str(profil) + " n'est pas autorisé"
|
|
|
|
fonction = ""
|
|
if ("fonction" in diction.keys()):
|
|
fonction = diction['fonction']
|
|
data_update['fonction'] = diction['fonction']
|
|
|
|
civilite = ""
|
|
if ("civilite" in diction.keys()):
|
|
civilite = diction['civilite']
|
|
data_update['civilite'] = diction['civilite']
|
|
|
|
adr_adresse = ""
|
|
if ("adr_adresse" in diction.keys()):
|
|
adr_adresse = diction['adr_adresse']
|
|
data_update['adr_adresse'] = diction['adr_adresse']
|
|
|
|
adr_code_postal = ""
|
|
if ("adr_code_postal" in diction.keys()):
|
|
adr_code_postal = diction['adr_code_postal']
|
|
data_update['adr_code_postal'] = diction['adr_code_postal']
|
|
|
|
adr_ville = ""
|
|
if ("adr_ville" in diction.keys()):
|
|
adr_ville = diction['adr_ville']
|
|
data_update['adr_ville'] = diction['adr_ville']
|
|
|
|
adr_pays = ""
|
|
if ("adr_pays" in diction.keys()):
|
|
adr_pays = diction['adr_pays']
|
|
data_update['adr_pays'] = diction['adr_pays']
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in diction.keys()):
|
|
telephone = diction['telephone']
|
|
data_update['telephone'] = diction['telephone']
|
|
|
|
email = ""
|
|
if ("email" in diction.keys()):
|
|
email = diction['email']
|
|
# data_update['email'] = diction['email'] - on ne modifie pas le mail
|
|
|
|
|
|
telephone_mobile = ""
|
|
if ("telephone_mobile" in diction.keys()):
|
|
telephone_mobile = diction['telephone_mobile']
|
|
data_update['telephone_mobile'] = diction['telephone_mobile']
|
|
|
|
website = ""
|
|
if ("website" in diction.keys()):
|
|
website = diction['website']
|
|
data_update['website'] = diction['website']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
comment = diction['comment']
|
|
data_update['comment'] = diction['comment']
|
|
|
|
linkedin = ""
|
|
if ("linkedin" in diction.keys()):
|
|
linkedin = diction['linkedin']
|
|
data_update['linkedin'] = diction['linkedin']
|
|
|
|
facebook = ""
|
|
if ("facebook" in diction.keys()):
|
|
facebook = diction['facebook']
|
|
data_update['facebook'] = diction['facebook']
|
|
|
|
twitter = ""
|
|
if ("twitter" in diction.keys()):
|
|
twitter = diction['twitter']
|
|
data_update['twitter'] = diction['twitter']
|
|
|
|
|
|
|
|
data_update['valide'] = '1'
|
|
data_update['locked'] = '0'
|
|
data_update['date_update'] = str(datetime.now())
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {'_id': ObjectId(str(diction['_id'])), 'valide': '1', 'locked': '0', 'partner_recid': str(my_partner['recid']),}
|
|
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['ressource_humaine'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour les information : email = " + str(diction['email']))
|
|
return False, " Impossible de mettre à jour les informations "
|
|
|
|
return True, " Les données a été correctement mises à 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 les données "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des ressources humaines d'une entité en se basant sur
|
|
- token (partner_recid)
|
|
|
|
"""
|
|
def Get_List_Ressource_Humaine(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:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
"""
|
|
Si l'employé a un superieur_hierarchie_id, alors on va aller recuperer son nom et prenom.
|
|
ce superieur est une ressource humaime
|
|
"""
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
if( "superieur_hierarchie_id" in retval.keys() and retval['superieur_hierarchie_id']):
|
|
hierarchi_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(retval['superieur_hierarchie_id'])),
|
|
'valide':'1', 'locked':'0'}, {'nom':1, 'prenom':1})
|
|
if( hierarchi_data is None):
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
|
|
else:
|
|
if ("superieur_hierarchie_nom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_nom = hierarchi_data['superieur_hierarchie_nom']
|
|
|
|
if ("superieur_hierarchie_prenom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_prenom = hierarchi_data['superieur_hierarchie_prenom']
|
|
|
|
user['superieur_hierarchie_nom'] = superieur_hierarchie_nom
|
|
user['superieur_hierarchie_prenom'] = superieur_hierarchie_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 recuperer la liste des contact "
|
|
|
|
"""
|
|
Recuperation de la liste des profils de ressources humaines
|
|
"""
|
|
def Get_List_Profil_Ressource_Humaine(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:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_humaine_profil'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la liste des contact "
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des ressources humaines avec des filtre sur
|
|
- nom
|
|
- email
|
|
"""
|
|
def Get_List_Ressource_Humaine_with_filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'nom', 'email']
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
filt_email = {}
|
|
if ("email" in diction.keys()):
|
|
filt_email = {
|
|
'email': {'$regex': str(diction['email']), "$options": "i"}}
|
|
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
find_qry = {'$and':[{'partner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }, filt_nom, filt_email] }
|
|
|
|
print(" ##### find_qry aa = ", find_qry)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find(find_qry):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la liste des contact "
|
|
|
|
|
|
"""
|
|
Recherche sans filter - no_filter
|
|
"""
|
|
def Get_List_Ressource_Humaine_no_filter(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:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
find_qry = {'partner_recid': str(my_partner['recid']), 'valide':'1', 'locked':'0' }
|
|
|
|
print(" ##### find_qry bbb = ", find_qry)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find(find_qry):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recuperer la liste des contact "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation d'une ressourcesdonnée en se basant sur on token, _id,
|
|
"""
|
|
def Get_Given_Ressource_Humaine(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:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(str(diction['_id']))
|
|
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
#print(" ### data_cle = ", data_cle)
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
"""
|
|
Si l'employé a un superieur_hierarchie_id, alors on va aller recuperer son nom et prenom.
|
|
ce superieur est une ressource humaime
|
|
"""
|
|
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
if ("superieur_hierarchie_id" in retval.keys() and retval['superieur_hierarchie_id']):
|
|
hierarchi_data_qry = {'_id': ObjectId(str(retval['superieur_hierarchie_id'])), 'valide': '1', 'locked': '0'}
|
|
|
|
hierarchi_data = MYSY_GV.dbname['ressource_humaine'].find_one( hierarchi_data_qry)
|
|
|
|
if (hierarchi_data is None):
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
|
|
else:
|
|
if ("nom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_nom = hierarchi_data['nom']
|
|
|
|
if ("prenom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_prenom = hierarchi_data['prenom']
|
|
|
|
user['superieur_hierarchie_nom'] = superieur_hierarchie_nom
|
|
user['superieur_hierarchie_prenom'] = superieur_hierarchie_prenom
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
#print(" ### RetObject = ", RetObject)
|
|
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 recuperer la personne "
|
|
|
|
"""
|
|
Cette fonction ajoute une image de profil d'un stagaire
|
|
"""
|
|
def Update_Ressource_Humaine_Image(file_img=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', 'file_img_recid', 'rh_id' ]
|
|
|
|
|
|
incom_keys = diction.keys()
|
|
|
|
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " : Le champ '"+val + "' n'est pas autorisé ")
|
|
return False, " Le champ '" + val + "' n'est pas accepté "
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['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, " La valeur '" + val + "' n'est pas presente dans liste "
|
|
|
|
# recuperation des paramettre
|
|
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
|
|
|
|
|
|
|
|
rh_id = ""
|
|
if ("rh_id" in diction.keys()):
|
|
if diction['rh_id']:
|
|
rh_id = diction['rh_id']
|
|
|
|
|
|
if( file_img ):
|
|
recordimage_diction = {}
|
|
recordimage_diction['token'] = diction['token']
|
|
recordimage_diction['related_collection'] = "ressource_humaine"
|
|
recordimage_diction['type_img'] = "user"
|
|
recordimage_diction['related_collection_recid'] = str(rh_id)
|
|
recordimage_diction['image_recid'] = diction['file_img_recid']
|
|
|
|
|
|
local_status, local_message = mycommon.recordClassImage_v2(file_img, MYSY_GV.upload_folder, recordimage_diction)
|
|
if( local_status is False):
|
|
return local_status, local_message
|
|
|
|
return True, "L'image a été correctement enregistrée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'enregistrer l'image"
|
|
|
|
"""
|
|
Suppresion d'un image d'une ressource humaine
|
|
"""
|
|
def DeleteImage_Ressource_Humaine(diction=None):
|
|
try:
|
|
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'image_recid', ]
|
|
incom_keys = diction.keys()
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
for val in incom_keys:
|
|
if str(val).lower() not in str(field_list).lower():
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas accepté dans cette API")
|
|
return False, " Impossible de se connecter"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'image_recid']
|
|
for val in field_list_obligatoire:
|
|
if str(val).lower() not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + val + "' n'est pas presente dans liste des champs")
|
|
return False, "Impossible de se connecter"
|
|
|
|
mydata = {}
|
|
mytoken = ""
|
|
|
|
# recuperation des paramettre
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
mytoken = diction['token']
|
|
|
|
image_recid = ""
|
|
if ("image_recid" in diction.keys()):
|
|
if diction['image_recid']:
|
|
image_recid = diction['image_recid']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# " Lecture du fichier "
|
|
# print(" Lecture du fichier : " + saved_file + ". le token est :" + str(mytoken))
|
|
nb_line = 0
|
|
coll_name = MYSY_GV.dbname['mysy_images']
|
|
|
|
query_delete = {"recid": image_recid,}
|
|
|
|
|
|
ret_val = coll_name.delete_one({"recid": image_recid,}, )
|
|
|
|
|
|
|
|
print(" ### recordClassImage_v2 :L'image a été correctement supprimée ")
|
|
return True, "L'image a été correctement supprimée"
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de supprimer l'image "
|
|
|
|
|
|
""" Recuperation de l'image d'un employé
|
|
|
|
/!\ important : on prend le 'related_collection_recid' comme le '_id' de la collection inscription
|
|
"""
|
|
def getRecoded_Employee_Image_from_front(diction=None):
|
|
try:
|
|
# Dictionnaire des champs utilisables
|
|
field_list = ['token', 'rh_id', ]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Le champ '" + val + "' n'existe pas, requete annulée")
|
|
return False, " Impossible de recuperer les informations"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['token', 'rh_id',]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Impossible de recuperer les informations"
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
qery_images = {'locked': '0', 'valide': '1', 'related_collection': 'ressource_humaine',
|
|
'related_collection_recid': str(diction['rh_id'])}
|
|
|
|
print(" ### qery_images = ", qery_images)
|
|
|
|
RetObject = []
|
|
employee_images = {}
|
|
# Recuperation des image 'logo' et 'cachet' si le partenaire en a
|
|
for retVal in MYSY_GV.dbname['mysy_images'].find(qery_images):
|
|
if ('type_img' in retVal.keys()):
|
|
if (retVal['type_img'] == "user"):
|
|
employee_images['logo_img'] = retVal['img'].decode()
|
|
employee_images['logo_img_recid'] = retVal['recid']
|
|
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(employee_images))
|
|
|
|
|
|
return True, RetObject
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de recupérer l'image de l'employé "
|
|
|
|
|
|
"""
|
|
Cette fontion retourne la liste des manager
|
|
les personne qui ont statut manager à 1
|
|
"""
|
|
def Get_List_Manager_Ressource_Humaine(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:
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['ismanager'] = "1"
|
|
data_cle['locked'] = "0"
|
|
data_cle['valide'] = "1"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['ressource_humaine'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
"""
|
|
Si l'employé a un superieur_hierarchie_id, alors on va aller recuperer son nom et prenom.
|
|
ce superieur est une ressource humaime
|
|
"""
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
if( "superieur_hierarchie_id" in retval.keys() and retval['superieur_hierarchie_id']):
|
|
hierarchi_data = MYSY_GV.dbname['ressource_humaine'].find_one({'_id':ObjectId(str(retval['superieur_hierarchie_id'])),
|
|
'valide':'1', 'locked':'0'}, {'nom':1, 'prenom':1})
|
|
if( hierarchi_data is None):
|
|
superieur_hierarchie_nom = ""
|
|
superieur_hierarchie_prenom = ""
|
|
|
|
else:
|
|
if ("superieur_hierarchie_nom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_nom = hierarchi_data['superieur_hierarchie_nom']
|
|
|
|
if ("superieur_hierarchie_prenom" in hierarchi_data.keys()):
|
|
superieur_hierarchie_prenom = hierarchi_data['superieur_hierarchie_prenom']
|
|
|
|
user['superieur_hierarchie_nom'] = superieur_hierarchie_nom
|
|
user['superieur_hierarchie_prenom'] = superieur_hierarchie_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 recuperer la liste des contact "
|
|
|
|
|
|
|
|
""" Import des employés en mass
|
|
Avec l'import d'un fichier csv
|
|
"""
|
|
def Add_Ressource_Humaine_mass(file=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', ]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, Creation participants annulée")
|
|
return False, " Verifier votre API"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['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, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
|
return False, " Les information de connexion sont incorrectes. Impossible d'importer la liste des participants"
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", my_token)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
status, saved_file = mycommon.Upload_Save_CSV_File(file, Folder)
|
|
if (status == False):
|
|
mycommon.myprint("Impossible de recuperer correctement le fichier à importer")
|
|
return False, "Impossible d'importer la liste des participants, le nom du fichier est incorrect "
|
|
|
|
""""
|
|
Controle de l'integrité du fichier
|
|
"""
|
|
local_controle_status, local_controle_message = Controle_Add_Ressource_Humaine_mass(saved_file,
|
|
Folder,
|
|
diction)
|
|
|
|
if (local_controle_status is False):
|
|
return local_controle_status, local_controle_message
|
|
|
|
#print(" #### local_controle_message = ", local_controle_message)
|
|
|
|
nb_line = 0
|
|
|
|
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore')
|
|
df = df.fillna('')
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les noms des colonne sont bien corrects"
|
|
'''
|
|
field_list = ['nom', 'prenom', 'email', 'telephone_mobile', 'telephone', 'profil', 'ismanager', 'superieur_hierarchie_email', 'civilite',
|
|
'adresse', 'code_postal', 'ville', 'pays', 'facebook', 'fonction', 'linkedin', 'twitter']
|
|
|
|
|
|
# Controle du nombre de lignes dans le fichier.
|
|
total_rows = len(df)
|
|
if( total_rows > MYSY_GV.MAX_PARTICIPANT_BY_CSV ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes.")
|
|
return False, " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes."
|
|
|
|
|
|
#print(df.columns)
|
|
for val in df.columns:
|
|
if str(val).lower() not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3])+" : entete du fichier csv. '" + val + "' n'est pas acceptée")
|
|
return False, " Entete du fichier csv. '" + val + "' n'est pas acceptée"
|
|
|
|
# Verification des champs obligatoires dans le fichier
|
|
field_list_obligatoire_file = ['prenom', 'nom', 'email', 'ismanager', 'profil', ]
|
|
|
|
for val in field_list_obligatoire_file:
|
|
if val not in df.columns:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
|
|
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
|
|
|
|
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
mydata['prenom'] = str(df['prenom'].values[n])
|
|
mydata['nom'] = str(df['nom'].values[n])
|
|
mydata['profil'] = str(df['profil'].values[n])
|
|
|
|
rh_profil_count = MYSY_GV.dbname['ressource_humaine_profil'].count_documents({'profil_nom':str(mydata['profil']), 'valide':'1'})
|
|
if( rh_profil_count<= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ profil " + str(
|
|
df['profil'].values[n]) + " est invalide.")
|
|
return False, " Le champ profil -" + str(
|
|
df['profil'].values[n]) + "- est invalide."
|
|
|
|
|
|
mydata['ismanager'] = str(df['ismanager'].values[n])
|
|
|
|
if( str(mydata['ismanager']).lower() not in ['1', '0', 'oui', 'non']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ ismanager " + str(df['ismanager'].values[n]) + " est invalide. Les valeurs autorisées : 1, 0, oui, non")
|
|
return False, " Le champ ismanager -" + str(df['ismanager'].values[n]) + "- est invalide. Les valeurs autorisées : 1, 0, oui, non"
|
|
|
|
|
|
mydata['email'] = str(df['email'].values[n])
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]))):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email " + str(df['email'].values[n]) + " est invalide")
|
|
return False, " L'adresse email -" + str(df['email'].values[n]) + "- est invalide"
|
|
|
|
|
|
superieur_hierarchie_id = ""
|
|
superieur_hierarchie_email = ""
|
|
if ("superieur_hierarchie_email" in df.keys()):
|
|
if (str(df['superieur_hierarchie_email'].values[n])):
|
|
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]))):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'adresse email du manager " + str(
|
|
df['email'].values[n]) + " est invalide")
|
|
return False, " L'adresse email du manager -" + str(df['email'].values[n]) + "- est invalide"
|
|
|
|
superieur_hierarchie_email = str(df['superieur_hierarchie_email'].values[n])
|
|
superieur_hierarchie_data_count = MYSY_GV.dbname['ressource_humaine'].count_documents({'email':str(superieur_hierarchie_email),
|
|
'partner_recid':str(partner_recid), 'valide':'1', 'locked':'0'})
|
|
|
|
if( superieur_hierarchie_data_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Aucun manager avec l'adresse email " + str(
|
|
df['superieur_hierarchie_email'].values[n]) + " ")
|
|
return False, " Aucun manager avec l'adresse email -" + str(df['superieur_hierarchie_email'].values[n]) + ""
|
|
|
|
if (superieur_hierarchie_data_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il a plusieurs managers avec l'adresse email " + str(
|
|
df['superieur_hierarchie_email'].values[n]) + " ")
|
|
return False, " Il a plusieurs managers avec l'adresse email -" + str(
|
|
df['superieur_hierarchie_email'].values[n]) + ""
|
|
|
|
superieur_hierarchie_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'email': str(superieur_hierarchie_email),
|
|
'partner_recid': str(partner_recid), 'valide': '1', 'locked': '0'},{'_id':1})
|
|
|
|
superieur_hierarchie_id = superieur_hierarchie_data['_id']
|
|
|
|
mydata['superieur_hierarchie_id'] = superieur_hierarchie_id
|
|
|
|
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
|
|
telephone_mobile = ""
|
|
if ("telephone_mobile" in df.keys()):
|
|
if (str(df['telephone_mobile'].values[n])):
|
|
telephone_mobile = str(df['telephone_mobile'].values[n])
|
|
mydata['telephone_mobile'] = telephone_mobile
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in df.keys()):
|
|
if (str(df['telephone'].values[n])):
|
|
telephone = str(df['telephone'].values[n])
|
|
mydata['telephone'] = telephone
|
|
|
|
civilite = "-1"
|
|
if ("civilite" in df.keys()):
|
|
if (str(df['civilite'].values[n])):
|
|
civilite = str(df['civilite'].values[n])
|
|
if(str(civilite).lower() not in ['m', 'mme', 'neutre'] ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ civilité " + str(
|
|
df['civilite'].values[n]) + " est invalide. Les valeurs autorisées : 'm', 'mme', 'neutre'")
|
|
return False, " Le champ civilité -" + str(
|
|
df['civilite'].values[n]) + "- est invalide. Les valeurs autorisées : 'm', 'mme', 'neutre' "
|
|
|
|
if( str(civilite).lower() == "m"):
|
|
civilite = "1"
|
|
elif (str(civilite).lower() == "mme"):
|
|
civilite = "0"
|
|
else:
|
|
civilite = "-1"
|
|
|
|
mydata['civilite'] = civilite
|
|
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['adr_ville'] = ville
|
|
|
|
adresse = ""
|
|
if ("adresse" in df.keys()):
|
|
if (str(df['adresse'].values[n])):
|
|
pays = str(df['adresse'].values[n])
|
|
mydata['adr_adresse'] = adresse
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in df.keys()):
|
|
if (str(df['code_postal'].values[n])):
|
|
code_postal = str(df['code_postal'].values[n])
|
|
mydata['adr_code_postal'] = code_postal
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['adr_ville'] = ville
|
|
|
|
pays = ""
|
|
if ("pays" in df.keys()):
|
|
if (str(df['pays'].values[n])):
|
|
pays = str(df['pays'].values[n])
|
|
mydata['adr_pays'] = pays
|
|
|
|
facebook = ""
|
|
if ("facebook" in df.keys()):
|
|
if (str(df['facebook'].values[n])):
|
|
facebook = str(df['facebook'].values[n])
|
|
mydata['facebook'] = facebook
|
|
|
|
fonction = ""
|
|
if ("fonction" in df.keys()):
|
|
if (str(df['fonction'].values[n])):
|
|
fonction = str(df['fonction'].values[n])
|
|
mydata['fonction'] = fonction
|
|
|
|
linkedin = ""
|
|
if ("linkedin" in df.keys()):
|
|
if (str(df['linkedin'].values[n])):
|
|
linkedin = str(df['linkedin'].values[n])
|
|
mydata['linkedin'] = linkedin
|
|
|
|
twitter = ""
|
|
if ("twitter" in df.keys()):
|
|
if (str(df['twitter'].values[n])):
|
|
linkedin = str(df['twitter'].values[n])
|
|
mydata['twitter'] = twitter
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
print( "#### clean_dict ", clean_dict)
|
|
|
|
is_employe_exist_count = MYSY_GV.dbname['ressource_humaine'].count_documents({'email':str(mydata['email']), 'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
if( is_employe_exist_count > 0):
|
|
## Si l'adresse email exist deja en base, alors on fait une mise à jour
|
|
is_employe_exist_data = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'email': str(mydata['email']), 'partner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'}, {'_id'})
|
|
clean_dict['id'] = str(is_employe_exist_data['_id'])
|
|
status, retval = Update_Ressource_Humaine(clean_dict)
|
|
if (status is False):
|
|
return status, retval
|
|
|
|
|
|
if (is_employe_exist_count <= 0):
|
|
## Si l'adress email n'hexiste pas en base, on fait une creation
|
|
status, retval = Add_Ressource_Humaine(clean_dict)
|
|
if( status is False ):
|
|
return status, retval
|
|
|
|
print(str(total_rows)+" employé ont été inserés")
|
|
|
|
return True, str(total_rows)+" employés ont été inserées / Mises à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible d'importer les employés en masse "
|
|
|
|
"""
|
|
Avant de lancer l'import en masse, cette fonction va verifer que le fichier est bon en entier
|
|
Cela evite les imports partielles
|
|
"""
|
|
def Controle_Add_Ressource_Humaine_mass(saved_file=None, Folder=None, diction=None):
|
|
try:
|
|
|
|
'''
|
|
# Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés
|
|
# Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API
|
|
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
|
# field_list.
|
|
'''
|
|
field_list = ['token', ]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Verifier votre API"
|
|
|
|
'''
|
|
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
|
|
On controle que les champs obligatoires sont presents dans la liste
|
|
'''
|
|
field_list_obligatoire = ['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, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
|
return False, " Les information de connexion sont incorrectes. Impossible d'importer la liste des participants"
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", my_token)
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
|
|
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore')
|
|
df = df.fillna('')
|
|
|
|
# Dictionnaire des champs utilisables
|
|
'''
|
|
# Verification que les noms des colonne sont bien corrects"
|
|
'''
|
|
field_list = ['nom', 'prenom', 'email', 'telephone_mobile', 'telephone', 'profil', 'ismanager', 'superieur_hierarchie_email', 'civilite',
|
|
'adresse', 'code_postal', 'ville', 'pays', 'facebook', 'fonction', 'linkedin', 'twitter']
|
|
|
|
|
|
# Controle du nombre de lignes dans le fichier.
|
|
total_rows = len(df)
|
|
if( total_rows > MYSY_GV.MAX_PARTICIPANT_BY_CSV ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes.")
|
|
return False, " Le fichier comporte plus de "+str(MYSY_GV.MAX_PARTICIPANT_BY_CSV)+" lignes."
|
|
|
|
|
|
#print(df.columns)
|
|
for val in df.columns:
|
|
if str(val).lower() not in field_list:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3])+" : entete du fichier csv. '" + val + "' n'est pas acceptée")
|
|
return False, " Entete du fichier csv. '" + val + "' n'est pas acceptée"
|
|
|
|
# Verification des champs obligatoires dans le fichier
|
|
field_list_obligatoire_file = ['prenom', 'nom', 'email', 'ismanager', 'profil', ]
|
|
|
|
for val in field_list_obligatoire_file:
|
|
if val not in df.columns:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
|
|
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
|
|
|
|
|
|
x = range(0, total_rows)
|
|
for n in x:
|
|
mydata = {}
|
|
mydata['prenom'] = str(df['prenom'].values[n])
|
|
mydata['nom'] = str(df['nom'].values[n])
|
|
mydata['profil'] = str(df['profil'].values[n])
|
|
|
|
rh_profil_count = MYSY_GV.dbname['ressource_humaine_profil'].count_documents({'profil_nom':str(mydata['profil']), 'valide':'1', })
|
|
if( rh_profil_count<= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ profil " + str(
|
|
df['profil'].values[n]) + " est invalide.")
|
|
return False, " Le champ profil -" + str(
|
|
df['profil'].values[n]) + "- est invalide."
|
|
|
|
|
|
mydata['ismanager'] = str(df['ismanager'].values[n])
|
|
|
|
if( str(mydata['ismanager']).lower() not in ['1', '0', 'oui', 'non']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ ismanager " + str(df['ismanager'].values[n]) + " est invalide. Les valeurs autorisées : 1, 0, oui, non")
|
|
return False, " Le champ ismanager -" + str(df['ismanager'].values[n]) + "- est invalide. Les valeurs autorisées : 1, 0, oui, non"
|
|
|
|
|
|
mydata['email'] = str(df['email'].values[n])
|
|
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]))):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " l'adresse email " + str(df['email'].values[n]) + " est invalide")
|
|
return False, " L'adresse email -" + str(df['email'].values[n]) + "- est invalide"
|
|
|
|
|
|
superieur_hierarchie_id = ""
|
|
superieur_hierarchie_email = ""
|
|
if ("superieur_hierarchie_email" in df.keys()):
|
|
if (str(df['superieur_hierarchie_email'].values[n])):
|
|
|
|
if (not re.fullmatch(regex, str(df['email'].values[n]))):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'adresse email du manager " + str(
|
|
df['email'].values[n]) + " est invalide")
|
|
return False, " L'adresse email du manager -" + str(df['email'].values[n]) + "- est invalide"
|
|
|
|
superieur_hierarchie_email = str(df['superieur_hierarchie_email'].values[n])
|
|
superieur_hierarchie_data_count = MYSY_GV.dbname['ressource_humaine'].count_documents({'email':str(superieur_hierarchie_email),
|
|
'partner_recid':str(partner_recid), 'valide':'1', 'locked':'0'})
|
|
|
|
if( superieur_hierarchie_data_count <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Aucun manager avec l'adresse email " + str(
|
|
df['superieur_hierarchie_email'].values[n]) + " ")
|
|
return False, " Aucun manager avec l'adresse email -" + str(df['superieur_hierarchie_email'].values[n]) + ""
|
|
|
|
if (superieur_hierarchie_data_count > 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Il a plusieurs managers avec l'adresse email " + str(
|
|
df['superieur_hierarchie_email'].values[n]) + " ")
|
|
return False, " Il a plusieurs managers avec l'adresse email -" + str(
|
|
df['superieur_hierarchie_email'].values[n]) + ""
|
|
|
|
superieur_hierarchie_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'email': str(superieur_hierarchie_email),
|
|
'partner_recid': str(partner_recid), 'valide': '1', 'locked': '0'},{'_id':1})
|
|
|
|
superieur_hierarchie_id = superieur_hierarchie_data['_id']
|
|
|
|
mydata['superieur_hierarchie_id'] = superieur_hierarchie_id
|
|
|
|
|
|
|
|
mydata['token'] = str(my_token)
|
|
|
|
|
|
telephone_mobile = ""
|
|
if ("telephone_mobile" in df.keys()):
|
|
if (str(df['telephone_mobile'].values[n])):
|
|
telephone_mobile = str(df['telephone_mobile'].values[n])
|
|
mydata['telephone_mobile'] = telephone_mobile
|
|
|
|
|
|
telephone = ""
|
|
if ("telephone" in df.keys()):
|
|
if (str(df['telephone'].values[n])):
|
|
telephone = str(df['telephone'].values[n])
|
|
mydata['telephone'] = telephone
|
|
|
|
civilite = "-1"
|
|
if ("civilite" in df.keys()):
|
|
if (str(df['civilite'].values[n])):
|
|
civilite = str(df['civilite'].values[n])
|
|
if(str(civilite).lower() not in ['m', 'mme', 'neutre'] ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le champ civilité " + str(
|
|
df['civilite'].values[n]) + " est invalide. Les valeurs autorisées : 'm', 'mme', 'neutre'")
|
|
return False, " Le champ civilité -" + str(
|
|
df['civilite'].values[n]) + "- est invalide. Les valeurs autorisées : 'm', 'mme', 'neutre' "
|
|
|
|
if( str(civilite).lower() == "m"):
|
|
civilite = "1"
|
|
elif (str(civilite).lower() == "mme"):
|
|
civilite = "0"
|
|
else:
|
|
civilite = "-1"
|
|
|
|
mydata['civilite'] = civilite
|
|
|
|
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['adr_ville'] = ville
|
|
|
|
adresse = ""
|
|
if ("adresse" in df.keys()):
|
|
if (str(df['adresse'].values[n])):
|
|
pays = str(df['adresse'].values[n])
|
|
mydata['adr_adresse'] = adresse
|
|
|
|
code_postal = ""
|
|
if ("code_postal" in df.keys()):
|
|
if (str(df['code_postal'].values[n])):
|
|
code_postal = str(df['code_postal'].values[n])
|
|
mydata['adr_code_postal'] = code_postal
|
|
|
|
ville = ""
|
|
if ("ville" in df.keys()):
|
|
if (str(df['ville'].values[n])):
|
|
ville = str(df['ville'].values[n])
|
|
mydata['adr_ville'] = ville
|
|
|
|
pays = ""
|
|
if ("pays" in df.keys()):
|
|
if (str(df['pays'].values[n])):
|
|
pays = str(df['pays'].values[n])
|
|
mydata['adr_pays'] = pays
|
|
|
|
facebook = ""
|
|
if ("facebook" in df.keys()):
|
|
if (str(df['facebook'].values[n])):
|
|
facebook = str(df['facebook'].values[n])
|
|
mydata['facebook'] = facebook
|
|
|
|
fonction = ""
|
|
if ("fonction" in df.keys()):
|
|
if (str(df['fonction'].values[n])):
|
|
fonction = str(df['fonction'].values[n])
|
|
mydata['fonction'] = fonction
|
|
|
|
linkedin = ""
|
|
if ("linkedin" in df.keys()):
|
|
if (str(df['linkedin'].values[n])):
|
|
linkedin = str(df['linkedin'].values[n])
|
|
mydata['linkedin'] = linkedin
|
|
|
|
twitter = ""
|
|
if ("twitter" in df.keys()):
|
|
if (str(df['twitter'].values[n])):
|
|
linkedin = str(df['twitter'].values[n])
|
|
mydata['twitter'] = twitter
|
|
|
|
|
|
clean_dict = {k: mydata[k] for k in mydata if ( str(mydata[k]) != "nan") }
|
|
|
|
print( "#### clean_dict ", clean_dict)
|
|
|
|
|
|
|
|
return True, str(total_rows)+" employés dans le fichier"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
|
return False, "Impossible de controler le fichier des employes à importer en masse "
|