668 lines
26 KiB
Python
668 lines
26 KiB
Python
"""
|
||
Ce document définit comment les utilisateurs avec un profil ‘admin’ pourront ajouter de nouveaux champs spécifiques.
|
||
|
||
Il arrive fréquemment que des clients souhaite ajouter des champs relatifs à leur activité (champs non gérés en standard), ce module est conçu pour répondre à ce besoin.
|
||
|
||
"""
|
||
|
||
import bson
|
||
import pymongo
|
||
from pymongo import MongoClient
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
from datetime import datetime
|
||
import prj_common as mycommon
|
||
import secrets
|
||
import inspect
|
||
import sys, os
|
||
import csv
|
||
import pandas as pd
|
||
from pymongo import ReturnDocument
|
||
import GlobalVariable as MYSY_GV
|
||
from math import isnan
|
||
import GlobalVariable as MYSY_GV
|
||
import ela_index_bdd_classes as eibdd
|
||
import email_mgt as email
|
||
import jinja2
|
||
from flask import send_file
|
||
from xhtml2pdf import pisa
|
||
from email.message import EmailMessage
|
||
from email.mime.text import MIMEText
|
||
from email import encoders
|
||
import smtplib
|
||
from email.mime.multipart import MIMEMultipart
|
||
from email.mime.text import MIMEText
|
||
from email.mime.base import MIMEBase
|
||
from email import encoders
|
||
|
||
"""
|
||
Ajout d'un champs spécifique"""
|
||
|
||
def Add_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
field_list = ['related_collection', 'field_type', 'is_mandatory', 'field_label', 'field_name',
|
||
'is_displayed','field_value', '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'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['related_collection', 'field_type', 'is_mandatory', 'field_label', 'field_name',
|
||
'is_displayed','field_value', '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, False
|
||
|
||
"""
|
||
Recuperation des données fournies en entrée
|
||
"""
|
||
data = {}
|
||
data['partner_owner_recid'] = str(my_partner['recid'])
|
||
data['valide'] = str(my_partner['recid'])
|
||
data['locked'] = str(my_partner['recid'])
|
||
data['date_update'] = str(datetime.now())
|
||
data['field_value'] = ""
|
||
|
||
|
||
related_collection = ""
|
||
if ("related_collection" in diction.keys()):
|
||
if diction['related_collection']:
|
||
related_collection = diction['related_collection']
|
||
if( str(related_collection) not in MYSY_GV.PERSONALISATION_AUTORIZED_COLLECTION ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(related_collection) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(related_collection) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['related_collection'] = related_collection
|
||
|
||
field_type = ""
|
||
if ("field_type" in diction.keys()):
|
||
if diction['field_type']:
|
||
field_type = diction['field_type']
|
||
|
||
if (str(field_type) not in ['float', 'string']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_type) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(field_type) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['field_type'] = field_type
|
||
|
||
is_mandatory = ""
|
||
if ("is_mandatory" in diction.keys()):
|
||
if diction['is_mandatory']:
|
||
is_mandatory = diction['is_mandatory']
|
||
|
||
if (str(is_mandatory) not in ['0', '1']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
is_mandatory) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(is_mandatory) + "' n'est pas autorisée pour la personnalisation",
|
||
data['is_mandatory'] = is_mandatory
|
||
|
||
field_label = ""
|
||
if ("field_label" in diction.keys()):
|
||
if diction['field_label']:
|
||
field_label = diction['field_label']
|
||
|
||
if (len(str(field_label)) > 50 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_label) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères ")
|
||
return False, " La valeur '" + str(field_label) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères",
|
||
|
||
data['field_label'] = field_label
|
||
|
||
field_name = ""
|
||
if ("field_name" in diction.keys()):
|
||
if diction['field_name']:
|
||
field_name = diction['field_name']
|
||
|
||
if (str(field_name).startswith("my_") is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(field_name) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
if (len(str(field_name)) > 50):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères ")
|
||
return False, " La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères",
|
||
|
||
data['field_name'] = field_name
|
||
|
||
|
||
is_displayed = ""
|
||
if ("is_displayed" in diction.keys()):
|
||
if diction['is_displayed']:
|
||
is_displayed = diction['is_displayed']
|
||
|
||
if (str(is_displayed) not in ['0', '1']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
is_displayed) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(is_displayed) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['is_displayed'] = is_displayed
|
||
|
||
|
||
# Verification que le champ n'existe pas
|
||
# la clé est le nom
|
||
is_personalisez_field_count = MYSY_GV.dbname['base_specific_fields'].count_documents({'related_collection':str(diction['related_collection']),
|
||
'partner_owner_recid':str(my_partner['recid']),
|
||
'field_name':str(diction['field_name']),
|
||
'valide':'1',
|
||
})
|
||
|
||
if( is_personalisez_field_count > 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - Cette personnalisation existe déjà ")
|
||
return False, "Cette personnalisation existe déjà ",
|
||
|
||
inserted_id = ""
|
||
inserted_id = MYSY_GV.dbname['base_specific_fields'].insert_one(data).inserted_id
|
||
if (not inserted_id):
|
||
mycommon.myprint(
|
||
" Impossible de créer le champ personnalisé ")
|
||
return False, " Impossible de créer le champ personnalisé "
|
||
|
||
|
||
return True, " Le champ personnalisé a été correctement ajouté "
|
||
|
||
except Exception as e:
|
||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||
return False, " Impossible d'ajouter le nouveau champ personnalisé"
|
||
|
||
|
||
"""
|
||
Modification d'un champ spécifique
|
||
"""
|
||
def Update_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
field_list = ['related_collection', 'field_type', 'is_mandatory', 'field_label', 'field_name',
|
||
'is_displayed', 'field_value', '_id', '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'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['_id', '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, False
|
||
|
||
"""
|
||
Recuperation des données fournies en entrée
|
||
"""
|
||
data = {}
|
||
data['partner_owner_recid'] = str(my_partner['recid'])
|
||
data['valide'] = str(my_partner['recid'])
|
||
data['locked'] = str(my_partner['recid'])
|
||
data['date_update'] = str(datetime.now())
|
||
data['field_value'] = ""
|
||
|
||
related_collection = ""
|
||
if ("related_collection" in diction.keys()):
|
||
related_collection = diction['related_collection']
|
||
if (str(related_collection) not in MYSY_GV.PERSONALISATION_AUTORIZED_COLLECTION):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
related_collection) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(related_collection) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['related_collection'] = related_collection
|
||
|
||
field_type = ""
|
||
if ("field_type" in diction.keys()):
|
||
field_type = diction['field_type']
|
||
|
||
if (str(field_type) not in ['float', 'string']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_type) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(field_type) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['field_type'] = field_type
|
||
|
||
is_mandatory = ""
|
||
if ("is_mandatory" in diction.keys()):
|
||
is_mandatory = diction['is_mandatory']
|
||
|
||
if (str(is_mandatory) not in ['0', '1']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
is_mandatory) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(is_mandatory) + "' n'est pas autorisée pour la personnalisation",
|
||
data['is_mandatory'] = is_mandatory
|
||
|
||
field_label = ""
|
||
if ("field_label" in diction.keys()):
|
||
field_label = diction['field_label']
|
||
|
||
if (len(str(field_label)) > 50):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_label) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères ")
|
||
return False, " La valeur '" + str(
|
||
field_label) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères",
|
||
|
||
data['field_label'] = field_label
|
||
|
||
field_name = ""
|
||
if ("field_name" in diction.keys()):
|
||
field_name = diction['field_name']
|
||
|
||
if (str(field_name).startswith("my_") is False):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(field_name) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
if (len(str(field_name)) > 50):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères ")
|
||
return False, " La valeur '" + str(
|
||
field_name) + "' n'est pas autorisée pour la personnalisation. Il fait plus de 50 caractères",
|
||
|
||
data['field_name'] = field_name
|
||
|
||
is_displayed = ""
|
||
if ("is_displayed" in diction.keys()):
|
||
is_displayed = diction['is_displayed']
|
||
|
||
if (str(is_displayed) not in ['0', '1']):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - La valeur '" + str(
|
||
is_displayed) + "' n'est pas autorisée pour la personnalisation ")
|
||
return False, " La valeur '" + str(is_displayed) + "' n'est pas autorisée pour la personnalisation",
|
||
|
||
data['is_displayed'] = is_displayed
|
||
|
||
# Verification que le champ n'existe pas
|
||
# la clé est le nom
|
||
is_personalisez_field_count = MYSY_GV.dbname['base_specific_fields'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
})
|
||
|
||
if (is_personalisez_field_count <= 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " - Cette personnalisation n'existe pas ")
|
||
return False, "Cette personnalisation n'existe pas ",
|
||
|
||
ret_val2 = MYSY_GV.dbname['base_specific_fields'].find_one_and_update(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',},
|
||
{"$set": data},
|
||
return_document=ReturnDocument.AFTER,
|
||
upsert=False,
|
||
)
|
||
|
||
|
||
inserted_id = ""
|
||
inserted_id = MYSY_GV.dbname['base_specific_fields'].insert_one(data).inserted_id
|
||
if (ret_val2 is None ):
|
||
mycommon.myprint(
|
||
" Impossible de mettre à jour le champ personnalisé ")
|
||
return False, " Impossible de mettre à jour le champ personnalisé "
|
||
|
||
|
||
return True, " Le champ personnalisé 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 champ personnalisé "
|
||
|
||
|
||
"""
|
||
Recuperation d'un champ spécifique donné en partant de l'_id
|
||
"""
|
||
def get_given_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
field_list = ['_id', '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'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['_id', '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, False
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 1
|
||
for retval in MYSY_GV.dbname['base_specific_fields'].find(data_cle):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
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 récuperer le champ personnalisé "
|
||
|
||
"""
|
||
Suppression d'un champ spécifique.
|
||
Pour qu'un champ personnalisé soit supprimable, il faut qu'il existe aucun enregistrement avec une valeur pour ce champs.
|
||
|
||
la requete de controle est : { "mon_champs" : { $exists : true, $ne: "" } }, si existe alors PAS de suppression
|
||
|
||
"""
|
||
def delete_given_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
diction = mycommon.strip_dictionary(diction)
|
||
field_list = ['_id', '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'est pas autorisé")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['_id', '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, False
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
"""
|
||
Recuperation des données du champ à surprimer
|
||
"""
|
||
personnalized_field_data = MYSY_GV.dbname['base_specific_fields'].find_one({'_id':ObjectId(str(diction['_id'])),
|
||
'valide':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( personnalized_field_data is None):
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " L'identification du champ n'est pas valide ")
|
||
return False, "L'identification du champ n'est pas valide ",
|
||
|
||
"""
|
||
Verification qu'il n'existe aucun enregistrement avec une valeur pour ce champ
|
||
"""
|
||
local_qry = { str(personnalized_field_data['field_name']) : { '$exists' : True, '$ne': "" } }
|
||
print(" #### delete_given_specific_field local_qry = ", local_qry)
|
||
is_record_exist_count = MYSY_GV.dbname[str(personnalized_field_data['related_collection'])].count_documents(local_qry)
|
||
|
||
if( is_record_exist_count > 0 ):
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champs est déjà utilisé, impossible de le supprimer ")
|
||
return False, "Le champs est déjà utilisé, impossible de le supprimer ",
|
||
|
||
|
||
MYSY_GV.dbname['base_specific_fields'].delete_one({'_id':ObjectId(str(diction['_id']))})
|
||
|
||
|
||
return True, " Le champ personnalisé a été correctement supprimé "
|
||
|
||
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 champ personnalisé "
|
||
|
||
|
||
|
||
|
||
"""
|
||
Recuperation de liste des champs spécifiques d'un partenaire
|
||
"""
|
||
def get_list_specific_field_partner(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'object_name']
|
||
|
||
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', 'object_name']
|
||
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
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['is_displayed'] = "1"
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
RetObject = []
|
||
val_tmp = 1
|
||
|
||
# print(" ### qtry = ", data_cle)
|
||
|
||
for retval in MYSY_GV.dbname['base_specific_fields'].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 récuperer la liste des champs personnalisés "
|
||
|
||
|
||
"""
|
||
Recuperation de liste des champs spécifiques d'un objet (client, formation, etc) d'un partenaire
|
||
"""
|
||
def get_list_specific_field_partner_by_object(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'object_name']
|
||
|
||
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', 'object_name']
|
||
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
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['related_collection'] = str(diction['object_name']).strip().lower()
|
||
data_cle['is_displayed'] = "1"
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
RetObject = []
|
||
val_tmp = 1
|
||
|
||
#print(" ### qtry = ", data_cle)
|
||
|
||
for retval in MYSY_GV.dbname['base_specific_fields'].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 récupérer la liste des champs spécifiques " |