291 lines
10 KiB
Python
291 lines
10 KiB
Python
""""
|
|
Ce fichier permet de configurer le catalogue public d'un partenaire
|
|
"""
|
|
from base64 import b64encode
|
|
|
|
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
|
|
|
|
"""
|
|
Fonction permet de récuperer la liste des
|
|
thèmes de catalogue public
|
|
"""
|
|
|
|
def Get_List_Theme_Catalog_Pub(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = "default"
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['config_partner_catalog_theme'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
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écupérer la liste des thèmes "
|
|
|
|
|
|
"""
|
|
Cette fonction enregistrer les données de configuration
|
|
du catalog public d'un partenaire
|
|
"""
|
|
|
|
def Add_Update_Partner_Catalog_Pub_Config(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id','logo', 'message_1_txt', 'theme_id', 'banniere_img', 'message_2_txt',
|
|
'message_3_txt', 'message_1_color', 'message_1_gras', 'message_2_color', 'message_2_gras',
|
|
'message_3_color', 'message_3_gras','message_1_taille', 'message_2_taille', 'message_3_taille',
|
|
'indicateur_1_txt', 'indicateur_1_taille','indicateur_1_color', 'indicateur_1_gras',
|
|
'indicateur_2_txt', 'indicateur_2_taille', 'indicateur_2_color', 'indicateur_2_gras',
|
|
'indicateur_3_txt', 'indicateur_3_taille', 'indicateur_3_color', 'indicateur_3_gras',
|
|
'indicateur_4_txt', 'indicateur_4_taille', 'indicateur_4_color', 'indicateur_4_gras',
|
|
'cgv_pdf', 'cgu_pdf', 'mention_legale_pdf', 'contact_public_email', 'contact_public_telephone'
|
|
]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '_id', ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
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
|
|
|
|
my_id = diction['_id']
|
|
|
|
del diction['_id']
|
|
del diction['token']
|
|
|
|
if( my_id ):
|
|
diction['date_update'] = str(datetime.now())
|
|
diction['update_by'] = str(my_partner['_id'])
|
|
result = MYSY_GV.dbname['config_partner_catalog'].find_one_and_update(
|
|
{'_id': ObjectId(str(my_id)),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{"$set": diction},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible d'ajouter ou mettre à jour la configuration du catalogue public (2) ")
|
|
return False, " Impossible d'ajouter ou mettre à jour la configuration du catalogue public (2) "
|
|
|
|
else:
|
|
|
|
diction['valide'] = "1"
|
|
diction['locked'] = "0"
|
|
diction['partner_owner_recid'] = str(my_partner['recid'])
|
|
diction['date_update'] = str(datetime.now())
|
|
diction['update_by'] = str(my_partner['_id'])
|
|
|
|
result = MYSY_GV.dbname['config_partner_catalog'].insert_one(diction)
|
|
|
|
return True, " La configuration du catalogue a été correctement mise à 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 d'ajouter ou mettre à jour la configuration du catalogue public "
|
|
|
|
|
|
"""
|
|
Recuperation des la configuration du catalogue public
|
|
d'un partenaire
|
|
"""
|
|
def Get_Partner_Catalog_Pub_Config(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans la liste des arguments ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = my_partner['recid']
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
#print(" ### data_cle = ", data_cle)
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['config_partner_catalog'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
if ("contact_public_email" not in retval.keys()):
|
|
user['contact_public_email'] = ""
|
|
|
|
if ("contact_public_telephone" not in retval.keys()):
|
|
user['contact_public_telephone'] = ""
|
|
|
|
if( "logo" not in retval.keys() ):
|
|
user['logo'] = ""
|
|
|
|
|
|
"""
|
|
Recuperer les données (preview) du
|
|
config_partner_catalog_theme
|
|
"""
|
|
user['theme_preview'] = ""
|
|
|
|
if( "theme_id" in retval.keys() and retval['theme_id']):
|
|
config_partner_catalog_theme_data = MYSY_GV.dbname['config_partner_catalog_theme'].find_one({'_id':ObjectId(str(retval['theme_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':"default"})
|
|
|
|
if( config_partner_catalog_theme_data and "theme_preview" in config_partner_catalog_theme_data.keys() ):
|
|
user['theme_preview'] = config_partner_catalog_theme_data['theme_preview']
|
|
|
|
else:
|
|
user['theme_id'] = ""
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
#print(" ### Get_Partner_Catalog_Pub_Config = 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écupérer la configuration du catalogue public "
|
|
|
|
|
|
|