185 lines
5.7 KiB
Python
185 lines
5.7 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)
|
||
|
||
|
||
return True, " Le champ 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 "
|
||
|
||
|
||
"""
|
||
Modification d'un champ spécifique
|
||
"""
|
||
def update_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
|
||
return True, " Le champ a été correctement modifié "
|
||
|
||
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 modifier le champ "
|
||
|
||
|
||
"""
|
||
Recuperation d'un champ spécifique donné en partant de l'_id
|
||
"""
|
||
def get_given_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
|
||
return True, " Le champ a été correctement modifié "
|
||
|
||
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 modifier le champ "
|
||
|
||
"""
|
||
Suppression d'un champ spécifique
|
||
"""
|
||
def delete_given_specific_field(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
|
||
return True, " Le champ a été correctement modifié "
|
||
|
||
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 "
|
||
|
||
|
||
|
||
|
||
"""
|
||
Recuperation de liste des champs spécifiques d'un partenaire
|
||
"""
|
||
def get_list_specific_field_partner(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
return True, " Le champ a été correctement modifié "
|
||
|
||
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 modifier le champ "
|
||
|
||
|
||
"""
|
||
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 " |