252 lines
9.1 KiB
Python
252 lines
9.1 KiB
Python
"""
|
|
Fonction commune des tableaux de bord comme :
|
|
- get_list_tbd
|
|
- add to my tbd
|
|
- remove from my tbd,
|
|
- etc
|
|
"""
|
|
|
|
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
|
|
from datetime import timedelta
|
|
from datetime import timedelta
|
|
import ast
|
|
|
|
def Get_List_Partner_Dashbord(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_start_date', 'session_end_date' ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['base_config_dashbord'].find({'$or':[{'valide':"1", 'locked':'0', 'partner_owner_recid':'default'},
|
|
{'valide':"1", 'locked':'0', 'partner_owner_recid':str(my_partner['recid'])} ]} ):
|
|
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
|
|
|
|
|
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 tableaux de bord "
|
|
|
|
|
|
"""
|
|
Fonction ajoute un dashbord au dashbord de l'utilisateur
|
|
"""
|
|
def Add_To_User_Dashbord(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "dashbord_internal_code", "default_filter", "title"]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', "dashbord_internal_code", "default_filter", ]
|
|
|
|
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
|
|
|
|
# Verifier que le dashbord existe
|
|
is_existe_dashbord = MYSY_GV.dbname['base_config_dashbord'].count_documents({"dashbord_internal_code":str(diction['dashbord_internal_code']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])
|
|
})
|
|
|
|
if( is_existe_dashbord <= 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le code du tableau de bord est invalide ")
|
|
return False, " Le code du tableau de bord est invalide "
|
|
|
|
# S'assurer que le 'default_qery' est bien un json
|
|
default_qery_Json = ast.literal_eval(diction['default_filter'])
|
|
|
|
|
|
my_data = {}
|
|
my_data['connected_id'] = str(my_partner['_id'])
|
|
my_data['update_by'] = str(my_partner['_id'])
|
|
my_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
my_data['default_filter'] = str(diction['default_filter'])
|
|
my_data['title'] = str(diction['title'])
|
|
my_data['dashbord_internal_code'] = str(diction['dashbord_internal_code'])
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
|
|
result = MYSY_GV.dbname['user_dashbord'].find_one_and_update(
|
|
{'partner_owner_recid': str(my_partner['recid']), 'connected_id':str(my_partner['_id']),
|
|
'dashbord_internal_code':str(diction['dashbord_internal_code']),
|
|
'title':str(diction['title'])},
|
|
{"$set": my_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
return True, " Le tableau de bord 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 tableau de bord "
|
|
|
|
|
|
"""
|
|
Fonction qui supprime un dashbord de la liste des dashbord de l'utilisateur
|
|
"""
|
|
|
|
|
|
def Delete_To_User_Dashbord(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "dashbord_internal_code", "title"]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', "dashbord_internal_code" ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verifier que le dashbord existe
|
|
is_existe_dashbord = MYSY_GV.dbname['base_config_dashbord'].count_documents(
|
|
{"dashbord_internal_code": str(diction['dashbord_internal_code']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])
|
|
})
|
|
|
|
if (is_existe_dashbord <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le code du tableau de bord est invalide ")
|
|
return False, " Le code du tableau de bord est invalide "
|
|
|
|
# S'assurer que le 'default_qery' est bien un json
|
|
default_qery_Json = json.loads(diction['default_filter'])
|
|
|
|
my_data = {}
|
|
my_data['connected_id'] = str(my_partner['_id'])
|
|
my_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
my_data['dashbord_internal_code'] = str(diction['dashbord_internal_code'])
|
|
|
|
|
|
MYSY_GV.dbname["user_dashbord"].delete_one(my_data)
|
|
|
|
data = {}
|
|
data['partner_owner_recid'] = my_partner['recid']
|
|
|
|
return True, " Le tableau de bord 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 d'ajouter le tableau de bord "
|