02/07/22 - 14h30

master
ChérifBALDE 2022-07-02 22:24:58 +02:00 committed by cherif
parent 8836da12a4
commit 55288d6627
6 changed files with 715 additions and 106 deletions

View File

@ -104,4 +104,10 @@ MAINPAGE_QUERY_LIMIT_ROW = 55
Cette variable definit le nombre de mots retourné dans le Cette variable definit le nombre de mots retourné dans le
cas d'une aide à avec une recherche vide cas d'une aide à avec une recherche vide
''' '''
HELP_WORD_QUERY_LIMIT = 3 HELP_WORD_QUERY_LIMIT = 3
'''
Les formats d'image accepté
'''
IMG_FORMAT=['jpg', 'jpeg', 'png', 'jpe']

View File

@ -44,7 +44,7 @@ def add_class(diction):
# field_list. # field_list.
''' '''
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel', field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel',
'price', 'url','duree_formation','token', 'plus_produit', 'mots_cle','domaine'] 'price', 'url','duration','token', 'plus_produit', 'mots_cle','domaine', 'internal_url', 'zone_diffusion']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
if val not in field_list: if val not in field_list:
@ -96,7 +96,18 @@ def add_class(diction):
mydata['partner_owner_recid'] = user_recid mydata['partner_owner_recid'] = user_recid
class_internal_url = ""
if ("internal_url" in diction.keys()):
if diction['internal_url']:
class_internal_url = diction['internal_url']
'''
Si l'internal_url reste à vide, alors le système va créer une internal url de la formation
'''
if( len(class_internal_url) <= 0 ):
status, class_internal_url = mycommon.CreateInternalUrl(diction['title'])
mydata['internal_url'] = class_internal_url
if ("external_code" in diction.keys()): if ("external_code" in diction.keys()):
if diction['external_code']: if diction['external_code']:
@ -122,13 +133,18 @@ def add_class(diction):
if diction['institut_formation']: if diction['institut_formation']:
mydata['institut_formation'] = diction['institut_formation'] mydata['institut_formation'] = diction['institut_formation']
my_presentiel = "0"
my_distantiel = "0"
if ("distantiel" in diction.keys()): if ("distantiel" in diction.keys()):
if diction['distantiel']: if diction['distantiel']:
mydata['distantiel'] = diction['distantiel'] my_distantiel = diction['distantiel']
if ("presentiel" in diction.keys()): if ("presentiel" in diction.keys()):
if diction['presentiel']: if diction['presentiel']:
mydata['presentiel'] = diction['presentiel'] my_presentiel = diction['presentiel']
mydata['presentiel'] = {'presentiel': my_presentiel, 'distantiel': my_distantiel}
if ("price" in diction.keys()): if ("price" in diction.keys()):
if diction['price']: if diction['price']:
@ -138,9 +154,9 @@ def add_class(diction):
if diction['url']: if diction['url']:
mydata['url'] = diction['url'] mydata['url'] = diction['url']
if ("duree_formation" in diction.keys()): if ("duration" in diction.keys()):
if diction['duree_formation']: if diction['duration']:
mydata['duree_formation'] = float(str(diction['duree_formation'])) mydata['duration'] = float(str(diction['duration']))
@ -168,6 +184,57 @@ def add_class(diction):
mydata['domaine'] = diction['domaine'] mydata['domaine'] = diction['domaine']
if ("zone_diffusion" in diction.keys()):
if diction['zone_diffusion']:
tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";")
if (not tmp_str2.endswith(";")):
tmp_str2 = tmp_str2 + ";"
print("tmp_str2 = " + tmp_str2)
if (";" not in tmp_str2):
mycommon.myprint(str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation : A" + str(
diction['external_code']) + " est incorrecte")
return False, "La zone de diffusion de la formation " + str(diction['external_code']) + " est incorrecte"
tmp_str = tmp_str2.split(";") #==> ce qui va donner un tableau de : Country_Code-City : ['fr-paris', 'fr-marseille', 'bn-cotonou']
cpt = 0
tab_country = []
tab_city = []
for val in tmp_str:
print(" val = "+str(val))
if( len(str(val)) <= 0 ):
continue
if( "-" not in str(val)):
mycommon.myprint(str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation : B" + str( diction['external_code']) + " est incorrecte")
return False, "La zone de diffusion de la formation " + str(diction['external_code']) + " est incorrecte"
tab_val = len(val.split("-"))
if( len(val.split("-")) != 1 and len(val.split("-")) != 2 ):
mycommon.myprint( str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation : C" + str(diction['external_code'])+" est incorrecte")
return False, "La zone de diffusion de la formation " + str(diction['external_code'])+" est incorrecte"
if( val.split("-")[0]):
tab_country.append(val.split("-")[0])
else:
tab_country.append("")
if(val.split("-")[1]):
tab_city.append(val.split("-")[1])
else:
tab_city.append("")
mydata['zone_diffusion'] = {'country':tab_country, 'city':tab_city}
mydata['valide'] = '1' mydata['valide'] = '1'
mydata['locked'] = '0' mydata['locked'] = '0'
mydata['indexed'] = '0' mydata['indexed'] = '0'
@ -219,8 +286,8 @@ def update_class(diction):
# field_list. # field_list.
''' '''
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel',
'presentiel','price', 'url', 'duree_formation', 'token','plus_produit', 'mots_cle', 'presentiel','price', 'url', 'duration', 'token','plus_produit', 'mots_cle',
'domaine', 'internal_code'] 'domaine', 'internal_code', 'internal_url','zone_diffusion']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
@ -233,7 +300,7 @@ def update_class(diction):
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, 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 On controle que les champs obligatoires sont presents dans la liste
''' '''
field_list_obligatoire = ['external_code', 'token'] field_list_obligatoire = ['internal_url', 'token']
for val in field_list_obligatoire: for val in field_list_obligatoire:
if val not in diction: if val not in diction:
@ -272,68 +339,113 @@ def update_class(diction):
my_internal_code = "" my_internal_code = ""
if ("internal_code" in diction.keys()): if ("internal_code" in diction.keys()):
if diction['internal_code']: my_internal_code = diction['internal_code']
my_internal_code = diction['internal_code']
my_internal_url = ""
if ("internal_url" in diction.keys()):
my_internal_url = diction['internal_url']
if ("external_code" in diction.keys()): if ("external_code" in diction.keys()):
if diction['external_code']: my_external_code = diction['external_code']
my_external_code = diction['external_code']
if ("title" in diction.keys()): if ("title" in diction.keys()):
if diction['title']: mydata['title'] = diction['title']
mydata['title'] = diction['title']
if ("description" in diction.keys()): if ("description" in diction.keys()):
if diction['description']: mydata['description'] = diction['description']
mydata['description'] = diction['description']
if ("trainer" in diction.keys()): if ("trainer" in diction.keys()):
if diction['trainer']: mydata['trainer'] = diction['trainer']
mydata['trainer'] = diction['trainer']
if ("plus_produit" in diction.keys()):
if diction['plus_produit']:
mydata['plus_produit'] = diction['plus_produit']
if ("institut_formation" in diction.keys()): if ("institut_formation" in diction.keys()):
if diction['institut_formation']: mydata['institut_formation'] = diction['institut_formation']
mydata['institut_formation'] = diction['institut_formation']
my_presentiel = "0"
my_distantiel = "0"
if ("distantiel" in diction.keys()): if ("distantiel" in diction.keys()):
if diction['distantiel']: my_distantiel = diction['distantiel']
mydata['distantiel'] = diction['distantiel']
if ("presentiel" in diction.keys()): if ("presentiel" in diction.keys()):
if diction['presentiel']: my_presentiel = diction['presentiel']
mydata['presentiel'] = diction['presentiel']
mydata['presentiel'] = {'presentiel': my_presentiel, 'distantiel': my_distantiel}
if ("price" in diction.keys()): if ("price" in diction.keys()):
if diction['price']: if( diction['price']):
mydata['price'] = int(str(diction['price'])) mydata['price'] = int(str(diction['price']))
if ("url" in diction.keys()): if ("url" in diction.keys()):
if diction['url']: mydata['url'] = diction['url']
mydata['url'] = diction['url']
if ("duree_formation" in diction.keys()): if ("duration" in diction.keys()):
if diction['duree_formation']: mydata['duration'] = float(str(diction['duration']))
mydata['duree_formation'] = float(str(diction['duree_formation']))
if ("plus_produit" in diction.keys()): if ("plus_produit" in diction.keys()):
if diction['plus_produit']: mydata['plus_produit'] = diction['plus_produit']
mydata['plus_produit'] = diction['plus_produit']
if ("mots_cle" in diction.keys()): if ("mots_cle" in diction.keys()):
if diction['mots_cle']: mydata['mots_cle'] = diction['mots_cle']
mydata['mots_cle'] = diction['mots_cle']
if ("domaine" in diction.keys()): if ("domaine" in diction.keys()):
if diction['domaine']: if diction['domaine']:
mydata['domaine'] = diction['domaine'] mydata['domaine'] = diction['domaine']
if ("zone_diffusion" in diction.keys()):
tmp_str2 = str(diction['zone_diffusion']).lower().replace(",", ";")
if( not tmp_str2.endswith(";")):
tmp_str2 = tmp_str2+";"
print("tmp_str2 = " + tmp_str2)
if (";" not in tmp_str2):
mycommon.myprint(str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation 0: " + str(
my_external_code) + " est incorrecte")
return False, "La zone de diffusion de la formation " + str(my_external_code) + " est incorrecte"
tmp_str = tmp_str2.split(";") #==> ce qui va donner un tableau de : Country_Code-City : ['fr-paris', 'fr-marseille', 'bn-cotonou']
cpt = 0
tab_country = []
tab_city = []
for val in tmp_str:
print(" val = "+str(val))
print(" val = " + str(val))
if (len(str(val)) <= 0):
continue
if( "-" not in str(val)):
mycommon.myprint(str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation 1: " + str( my_external_code) + " est incorrecte")
return False, "La zone de diffusion de la formation " + str(my_external_code) + " est incorrecte"
tab_val = len(val.split("-"))
if( len(val.split("-")) != 1 and len(val.split("-")) != 2 ):
mycommon.myprint( str(inspect.stack()[0][3]) + " - la zone de diffusion de la formation 2: " + str(my_external_code)+" est incorrecte")
return False, "La zone de diffusion de la formation " + str(my_external_code)+" est incorrecte"
if( val.split("-")[0]):
tab_country.append(val.split("-")[0])
else:
tab_country.append("")
if(val.split("-")[1]):
tab_city.append(val.split("-")[1])
else:
tab_city.append("")
mydata['zone_diffusion'] = {'country':tab_country, 'city':tab_city}
mydata['date_update'] = str(datetime.now()) mydata['date_update'] = str(datetime.now())
@ -347,7 +459,7 @@ def update_class(diction):
# seules les formation avec locked = 0 et valide=1 sont modifiables # seules les formation avec locked = 0 et valide=1 sont modifiables
ret_val = coll_name.find_one_and_update({'external_code': str(my_external_code), 'partner_owner_recid':partner_recid, 'locked': '0', 'valide': '1'}, ret_val = coll_name.find_one_and_update({'internal_url': str(my_internal_url), 'partner_owner_recid':partner_recid, 'locked': '0', 'valide': '1'},
{"$set": mydata}, {"$set": mydata},
return_document=ReturnDocument.AFTER return_document=ReturnDocument.AFTER
) )
@ -364,7 +476,8 @@ def update_class(diction):
except Exception as e: except Exception as e:
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(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 mettre à jour la formation " return False, " Impossible de mettre à jour la formation "
@ -383,7 +496,7 @@ def disable_class(diction):
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste # Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list. # field_list.
''' '''
field_list = ['external_code', 'token'] field_list = ['internal_url', 'token']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
if val not in field_list: if val not in field_list:
@ -395,7 +508,7 @@ def disable_class(diction):
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, 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 On controle que les champs obligatoires sont presents dans la liste
''' '''
field_list_obligatoire = ['external_code', 'token'] field_list_obligatoire = ['internal_url', 'token']
for val in field_list_obligatoire: for val in field_list_obligatoire:
if val not in diction: if val not in diction:
@ -404,7 +517,7 @@ def disable_class(diction):
# recuperation des paramettre # recuperation des paramettre
mydata = {} mydata = {}
my_external_code = "" my_internal_url = ""
if ("token" in diction.keys()): if ("token" in diction.keys()):
if diction['token']: if diction['token']:
@ -432,9 +545,9 @@ def disable_class(diction):
partner_recid = user_recid partner_recid = user_recid
if ("external_code" in diction.keys()): if ("internal_url" in diction.keys()):
if diction['external_code']: if diction['internal_url']:
my_external_code = diction['external_code'] my_internal_url = diction['internal_url']
mydata['date_update'] = str(datetime.now()) mydata['date_update'] = str(datetime.now())
@ -446,7 +559,7 @@ def disable_class(diction):
# seules les formation avec locked = 0 et valide=1 sont modifiables # seules les formation avec locked = 0 et valide=1 sont modifiables
ret_val = coll_name.find_one_and_update( ret_val = coll_name.find_one_and_update(
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0', {'internal_url': str(my_internal_url), 'partner_owner_recid': partner_recid, 'locked': '0',
'valide': '1'}, 'valide': '1'},
{"$set": mydata}, {"$set": mydata},
return_document=ReturnDocument.AFTER return_document=ReturnDocument.AFTER
@ -456,16 +569,17 @@ def disable_class(diction):
nb_doc = str(ret_val['_id']) nb_doc = str(ret_val['_id'])
mycommon.myprint( mycommon.myprint(
str(inspect.stack()[0][3]) + " - La formation a bin ete mise à jour =" + str(nb_doc)) str(inspect.stack()[0][3]) + " - La formation a bin ete mise à jour =" + str(nb_doc))
return True, " La formation "+str(my_external_code)+"a été desactivée" return True, " La formation "+str(my_internal_url)+"a été desactivée"
else: else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " +str(my_external_code) ) mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " +str(my_internal_url) )
return False, " Impossible de desactivier la formation : "+str(my_external_code) return False, " Impossible de desactivier la formation : "+str(my_internal_url)
except Exception as e: except Exception as e:
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(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 desactivier la formation " return False, " Impossible de desactivier la formation "
@ -483,7 +597,7 @@ def enable_class(diction):
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste # Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list. # field_list.
''' '''
field_list = ['external_code', 'token'] field_list = ['internal_url', 'token']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
if val not in field_list: if val not in field_list:
@ -495,7 +609,7 @@ def enable_class(diction):
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, 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 On controle que les champs obligatoires sont presents dans la liste
''' '''
field_list_obligatoire = ['external_code', 'token'] field_list_obligatoire = ['internal_url', 'token']
for val in field_list_obligatoire: for val in field_list_obligatoire:
if val not in diction: if val not in diction:
@ -504,7 +618,7 @@ def enable_class(diction):
# recuperation des paramettre # recuperation des paramettre
mydata = {} mydata = {}
my_external_code = "" my_internal_url = ""
if ("token" in diction.keys()): if ("token" in diction.keys()):
if diction['token']: if diction['token']:
@ -532,9 +646,9 @@ def enable_class(diction):
partner_recid = user_recid partner_recid = user_recid
if ("external_code" in diction.keys()): if ("internal_url" in diction.keys()):
if diction['external_code']: if diction['internal_url']:
my_external_code = diction['external_code'] my_internal_url = diction['internal_url']
mydata['date_update'] = str(datetime.now()) mydata['date_update'] = str(datetime.now())
@ -545,7 +659,7 @@ def enable_class(diction):
# seules les formation avec locked = 0 et valide=1 sont modifiables # seules les formation avec locked = 0 et valide=1 sont modifiables
ret_val = coll_name.find_one_and_update( ret_val = coll_name.find_one_and_update(
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0', {'internal_url': str(my_internal_url), 'partner_owner_recid': partner_recid, 'locked': '0',
'valide': '0'}, 'valide': '0'},
{"$set": mydata}, {"$set": mydata},
return_document=ReturnDocument.AFTER return_document=ReturnDocument.AFTER
@ -555,11 +669,11 @@ def enable_class(diction):
nb_doc = str(ret_val['_id']) nb_doc = str(ret_val['_id'])
mycommon.myprint( mycommon.myprint(
str(inspect.stack()[0][3]) + " - La formation a bien ete reactivée =" + str(nb_doc)) str(inspect.stack()[0][3]) + " - La formation a bien ete reactivée =" + str(nb_doc))
return True, " La formation " + str(my_external_code) + "a été reactivée" return True, " La formation " + str(my_internal_url) + "a été reactivée"
else: else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " + str(my_external_code)) mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " + str(my_internal_url))
return False, " Impossible de reactivée la formation : " + str(my_external_code) return False, " Impossible de reactivée la formation : " + str(my_internal_url)
except Exception as e: except Exception as e:
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e)) mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e))
@ -581,7 +695,7 @@ def unlock_class(diction):
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste # Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list. # field_list.
''' '''
field_list = ['external_code', 'token'] field_list = ['internal_url', 'token']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
if val not in field_list: if val not in field_list:
@ -593,7 +707,7 @@ def unlock_class(diction):
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, 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 On controle que les champs obligatoires sont presents dans la liste
''' '''
field_list_obligatoire = ['external_code', 'token'] field_list_obligatoire = ['internal_url', 'token']
for val in field_list_obligatoire: for val in field_list_obligatoire:
if val not in diction: if val not in diction:
@ -602,7 +716,7 @@ def unlock_class(diction):
# recuperation des paramettre # recuperation des paramettre
mydata = {} mydata = {}
my_external_code = "" my_internal_url = ""
if ("token" in diction.keys()): if ("token" in diction.keys()):
if diction['token']: if diction['token']:
@ -632,9 +746,9 @@ def unlock_class(diction):
if ("external_code" in diction.keys()): if ("internal_url" in diction.keys()):
if diction['external_code']: if diction['internal_url']:
my_external_code = diction['external_code'] my_internal_url = diction['internal_url']
mydata['date_update'] = str(datetime.now()) mydata['date_update'] = str(datetime.now())
@ -644,7 +758,7 @@ def unlock_class(diction):
# seules les formation avec locked = 1 et valide=1 sont 'unlockable' # seules les formation avec locked = 1 et valide=1 sont 'unlockable'
ret_val = coll_name.find_one_and_update( ret_val = coll_name.find_one_and_update(
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '1', {'internal_url': str(my_internal_url), 'partner_owner_recid': partner_recid, 'locked': '1',
'valide': '1'}, 'valide': '1'},
{"$set": mydata}, {"$set": mydata},
return_document=ReturnDocument.AFTER return_document=ReturnDocument.AFTER
@ -654,11 +768,11 @@ def unlock_class(diction):
nb_doc = str(ret_val['_id']) nb_doc = str(ret_val['_id'])
mycommon.myprint( mycommon.myprint(
str(inspect.stack()[0][3]) + " - La formation a bien ete debloquée =" + str(nb_doc)) str(inspect.stack()[0][3]) + " - La formation a bien ete debloquée =" + str(nb_doc))
return True, " La formation " + str(my_external_code) + "a été debloquée" return True, " La formation " + str(my_internal_url) + "a été debloquée"
else: else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de debloquer : " + str(my_external_code)) mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de debloquer : " + str(my_internal_url))
return False, " Impossible de debloquer la formation : " + str(my_external_code) return False, " Impossible de debloquer la formation : " + str(my_internal_url)
@ -683,7 +797,7 @@ def lock_class(diction):
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste # Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
# field_list. # field_list.
''' '''
field_list = ['external_code', 'token'] field_list = ['internal_url', 'token']
incom_keys = diction.keys() incom_keys = diction.keys()
for val in incom_keys: for val in incom_keys:
if val not in field_list: if val not in field_list:
@ -696,7 +810,7 @@ def lock_class(diction):
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, 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 On controle que les champs obligatoires sont presents dans la liste
''' '''
field_list_obligatoire = ['external_code', 'token'] field_list_obligatoire = ['internal_url', 'token']
for val in field_list_obligatoire: for val in field_list_obligatoire:
if val not in diction: if val not in diction:
@ -706,7 +820,7 @@ def lock_class(diction):
# recuperation des paramettre # recuperation des paramettre
mydata = {} mydata = {}
my_external_code = "" my_internal_url = ""
if ("token" in diction.keys()): if ("token" in diction.keys()):
if diction['token']: if diction['token']:
@ -734,9 +848,9 @@ def lock_class(diction):
partner_recid = user_recid partner_recid = user_recid
if ("external_code" in diction.keys()): if ("internal_url" in diction.keys()):
if diction['external_code']: if diction['internal_url']:
my_external_code = diction['external_code'] my_internal_url = diction['internal_url']
mydata['date_update'] = str(datetime.now()) mydata['date_update'] = str(datetime.now())
@ -746,7 +860,7 @@ def lock_class(diction):
# seules les formation avec locked = 1 et valide=1 sont 'unlockable' # seules les formation avec locked = 1 et valide=1 sont 'unlockable'
ret_val = coll_name.find_one_and_update( ret_val = coll_name.find_one_and_update(
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0', {'internal_url': str(my_internal_url), 'partner_owner_recid': partner_recid, 'locked': '0',
'valide': '1'}, 'valide': '1'},
{"$set": mydata}, {"$set": mydata},
return_document=ReturnDocument.AFTER return_document=ReturnDocument.AFTER
@ -756,13 +870,11 @@ def lock_class(diction):
nb_doc = str(ret_val['_id']) nb_doc = str(ret_val['_id'])
mycommon.myprint( mycommon.myprint(
str(inspect.stack()[0][3]) + " - La formation a bien ete verrouillée =" + str(nb_doc)) str(inspect.stack()[0][3]) + " - La formation a bien ete verrouillée =" + str(nb_doc))
return True, " La formation " + str(my_external_code) + "a été verrouillée" return True, " La formation " + str(my_internal_url) + "a été verrouillée"
else: else:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de verrouiller la formation : " + str(my_external_code)) mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de verrouiller la formation : " + str(my_internal_url))
return False, " Impossible de verrouiller la formation : " + str(my_external_code) return False, " Impossible de verrouiller la formation : " + str(my_internal_url)
except Exception as e: except Exception as e:
mycommon.myprint(str(inspect.stack()[0][3]) + " - " + str(e)) mycommon.myprint(str(inspect.stack()[0][3]) + " - " + str(e))
@ -1146,9 +1258,9 @@ def get_partner_class(diction):
RetObject = [] RetObject = []
filt_external_code = {} filt_external_code= {}
if ("external_code" in diction.keys()): if ("internal_url" in diction.keys()):
filt_external_code = {'internal_url':{'$regex':str(diction['internal_url'])}} filt_external_code = {'internal_url':str(diction['internal_url'])}
filt_title = {} filt_title = {}
if ("title" in diction.keys()): if ("title" in diction.keys()):
@ -1161,13 +1273,28 @@ def get_partner_class(diction):
" filt_title = "+str(filt_title)) " filt_title = "+str(filt_title))
val_tmp = 1 val_tmp = 1
for retVal in coll_name.find( {'valide':'1'},{'locked':'0'}, for retVal in coll_name.find( {"$and":[ {'valide':'1'},{'locked':'0'},
{'partner_owner_recid':user_recid} , {'partner_owner_recid':user_recid} ,
filt_external_code, filt_external_code, filt_title]},
filt_title): ):
mycommon.myprint(str(retVal)) #mycommon.myprint(str(retVal))
user = retVal user = retVal
user['id'] = str(val_tmp) user['id'] = str(val_tmp)
'''
Pour des facilité d'affichage coté front
on va reformater le champ "zone_diffusion" de sorte à le renvoyer
sous la forme "code_pays-ville"
'''
i = 0
tmp_zone_diffusion = ""
if( "zone_diffusion" in user.keys()):
if( user['zone_diffusion'] and user['zone_diffusion']["city"]):
for tmp_val in user['zone_diffusion']["city"]:
tmp_zone_diffusion = tmp_zone_diffusion + str(user['zone_diffusion']["country"][i])+"-"+str(user['zone_diffusion']["city"][i])+";"
i = i+1
user['zone_diffusion_str'] = str(tmp_zone_diffusion[:-1])
RetObject.append(JSONEncoder().encode(user)) RetObject.append(JSONEncoder().encode(user))
val_tmp = val_tmp + 1 val_tmp = val_tmp + 1
@ -1278,7 +1405,7 @@ def add_class_mass(file=None, Folder=None, diction=None):
# Verification que les noms des colonne sont bien corrects" # Verification que les noms des colonne sont bien corrects"
''' '''
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel', field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel',
'price', 'domaine', 'url','duree_formation', 'plus_produit', 'mots_cle'] 'price', 'domaine', 'url','duration', 'plus_produit', 'mots_cle', 'zone_diffusion']
total_rows = len(df) total_rows = len(df)
@ -1300,11 +1427,15 @@ def add_class_mass(file=None, Folder=None, diction=None):
mydata['description'] = str(df['description'].values[n]) mydata['description'] = str(df['description'].values[n])
mydata['trainer'] = str(df['trainer'].values[n]) mydata['trainer'] = str(df['trainer'].values[n])
mydata['institut_formation'] = str(df['institut_formation'].values[n]) mydata['institut_formation'] = str(df['institut_formation'].values[n])
mydata['distantiel'] = str(df['presentiel'].values[n]) #mydata['distantiel'] = str(df['presentiel'].values[n])
mydata['url'] = str(df['url'].values[n]) mydata['url'] = str(df['url'].values[n])
mydata['duree_formation'] = float(str(df['duree_formation'].values[n])) mydata['duration'] = float(str(df['duration'].values[n]))
mydata['plus_produit'] = str(df['plus_produit'].values[n]) mydata['plus_produit'] = str(df['plus_produit'].values[n])
mydata['mots_cle'] = str(df['mots_cle'].values[n]) mydata['mots_cle'] = str(df['mots_cle'].values[n])
mydata['presentiel'] = str(df['presentiel'].values[n])
mydata['distantiel'] = str(df['distantiel'].values[n])
''' '''
Verification du nombre de mots clée : limite MAX_KEYWORD (3) Verification du nombre de mots clée : limite MAX_KEYWORD (3)
''' '''
@ -1315,8 +1446,13 @@ def add_class_mass(file=None, Folder=None, diction=None):
return False, " La formation "+str(mydata['external_code'])+" a plus de "+ str(MAX_KEYWORD)+" mots clés" return False, " La formation "+str(mydata['external_code'])+" a plus de "+ str(MAX_KEYWORD)+" mots clés"
mydata['distantiel'] = str(df['distantiel'].values[n]) '''
mydata['presentiel'] = str(df['presentiel'].values[n]) Traitement de la zone de diffusion
'''
if ("zone_diffusion" in df.keys()):
if(str(df['zone_diffusion'].values[n])):
mydata['zone_diffusion'] =str(df['zone_diffusion'].values[n])
if ("token" in diction.keys()): if ("token" in diction.keys()):
if diction['token']: if diction['token']:

33
main.py
View File

@ -859,6 +859,39 @@ def add_class_mass():
return jsonify(status=status, message=retval) return jsonify(status=status, message=retval)
'''
test d'enregistrement d'une image
'''
@app.route('/myclass/api/recordImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def recordImage():
# On recupere le corps (payload) de la requete
payload = request.form.to_dict()
print(" ### payload = ",payload)
print(request.files)
if request.method == 'POST':
# Create variable for uploaded file
f = request.files['File']
status= mycommon.recordImage(f, app.config['UPLOAD_FOLDER'], payload)
return jsonify(status=status)
'''
Test de recuperation d'une image enregistrée
'''
@app.route('/myclass/api/getRecodedImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def getRecodedImage():
# On recupere le corps (payload) de la requete
payload = request.form.to_dict()
print(" ### payload = ",payload)
status, myimg= mycommon.getRecodedImage(payload)
return jsonify(status=status, message=myimg)
''' '''

View File

@ -701,7 +701,7 @@ def partner_login(diction):
) )
if ret_val and ret_val['_id']: if ret_val and ret_val['_id']:
mycommon.myprint(str(inspect.stack()[0][3]) + " Connexion partener "+email+" : OK, Date : "+ str(now)+" , _id = " + str(ret_val['_id'])) mycommon.myprint(str(inspect.stack()[0][3]) + " Connexion partnair "+email+" : OK, Date : "+ str(now)+" , _id = " + str(ret_val['_id']))
# Vu que les credentials sont ok, alors enregistrement de la connexion dans la table "partner token" # Vu que les credentials sont ok, alors enregistrement de la connexion dans la table "partner token"
#print(" GRRRRRRRRRRRRRRRRRRR "+str(ret_val)) #print(" GRRRRRRRRRRRRRRRRRRR "+str(ret_val))

View File

@ -1,5 +1,8 @@
import hashlib import hashlib
import _pickle as cPickle
import pickle
import bson
from pymongo import MongoClient from pymongo import MongoClient
import pymongo import pymongo
from difflib import SequenceMatcher from difflib import SequenceMatcher
@ -7,7 +10,7 @@ import textdistance
from datetime import datetime from datetime import datetime
import logging import logging
import secrets import secrets
import base64
from bson import ObjectId from bson import ObjectId
from pymongo import MongoClient from pymongo import MongoClient
import inspect import inspect
@ -27,6 +30,13 @@ import prj_common as mycommon
import re import re
import email_mgt as email_mgt import email_mgt as email_mgt
import random import random
import json
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, ObjectId):
return str(o)
return json.JSONEncoder.default(self, o)
def myprint(message = ""): def myprint(message = ""):
logging.info(str(datetime.now()) + " : "+str(message) ) logging.info(str(datetime.now()) + " : "+str(message) )
@ -81,6 +91,48 @@ def Upload_Save_CSV_File(file=None, Folder=None):
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, None return False, None
'''
Controle de l'import des images.
les formats acceptés sont :
- 'jpg',
- 'jpeg',
- 'png'
'''
def Upload_Save_IMG_File(file=None, Folder=None):
try:
basename = os.path.basename(file.filename)
basename2 = basename.split(".")
'''
Verification qu'il s'agit bien d'un fichier image ('jpg', 'jpeg', 'png', 'jpe', ...), dont le nom ne comporte pas de "."
'''
if(len(basename2) != 2 ):
myprint(str(inspect.stack()[0][3]) + " - : Le nom du fichier est incorret")
return False, None
if( str(basename2[1]).lower() not in MYSY_GV.IMG_FORMAT):
myprint(str(inspect.stack()[0][3]) + " - : Ce n'est pas un fichier image :"+str(MYSY_GV.IMG_FORMAT))
return False, None
timestr = time.strftime("%Y%m%d%H%M%S")
new_file_name = str(basename2[0]) + "_" + str(timestr) + "." + str(basename2[1])
file.filename = new_file_name
file.save(os.path.join(str(Folder), secure_filename(file.filename))) # t
Global_file_name = "./Data/"+file.filename
return True, Global_file_name
except Exception as e :
exc_type, exc_obj, exc_tb = sys.exc_info()
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, None
@ -249,8 +301,8 @@ Cette fonction créer la reference interne d'une formation
def Create_internal_call_ref(): def Create_internal_call_ref():
retval = None retval = None
now = datetime.now() now = datetime.now()
retval = "Mysy_"+now retval = "Mysy_"+str(now)
return retval return str(retval)
def textdist(): def textdist():
val = textdistance.mra("doe", "dough") val = textdistance.mra("doe", "dough")
@ -1138,9 +1190,268 @@ def clean_emoji(sentence=None):
return new_sentence return new_sentence
except Exception as e: except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info() 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)) print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return "" return ""
'''
test d'enregistrement d'une image
'''
def recordImage(file=None, Folder=None, diction=None):
try:
# Dictionnaire des champs utilisables
field_list = ['token']
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']
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 = ""
myuserrecid = ""
# recuperation des paramettre
if ("token" in diction.keys()):
if diction['token']:
mytoken = diction['token']
'''
Verification de la validité du token et recuperation du recid du user
'''
retval = check_user_validity("", str(mytoken))
if retval is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
return False, "L'email ou le token ne sont pas valident"
# Recuperation du recid de la personne
user_recid = get_user_recid_from_token(str(mytoken))
if user_recid is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du user")
return False, " Les informations d'identification sont incorrectes"
myuserrecid = user_recid
status, saved_file = mycommon.Upload_Save_IMG_File(file, Folder)
if (status == False):
return False, "Impossible d'inserer les formation en masse "
# " Lecture du fichier "
print(" Lecture du fichier : " + saved_file+". le token est :"+str(mytoken ))
nb_line = 0
coll_name = MYSY_GV.dbname['image_ch']
with open(saved_file, "rb") as imageFile:
#strimg = base64.b64encode(imageFile.read())
strimg = base64.b64encode(imageFile.read())
new_diction = {}
new_diction['img'] = strimg
new_diction['type'] = 'profil'
new_diction['recid'] = myuserrecid
new_diction['valide'] = '1'
new_diction['date_update'] = str(datetime.now())
new_diction['locked'] = "0"
ret_val = coll_name.find_one_and_update({"recid":myuserrecid, "valide":"1", "locked":"0"},
{"$set": {"img":strimg, "date_update":str(datetime.now()),
"type":"profil","recid":myuserrecid, "valide":"1",
"locked":"0" }},
upsert=True,
return_document=ReturnDocument.AFTER
)
if ret_val and ret_val['_id']:
mycommon.myprint(" L'image a bien ete enregistrée. ")
return True
else:
mycommon.myprint(" IMPOSSIBLE D'ENREGISTRER L'IMAGE")
return False
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
'''
Test de recuperation d'une image
'''
def getRecodedImage(diction=None):
try:
# Dictionnaire des champs utilisables
field_list = ['token']
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']
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 = ""
myuserrecid = ""
# recuperation des paramettre
if ("token" in diction.keys()):
if diction['token']:
mytoken = diction['token']
'''
Verification de la validité du token et recuperation du recid du user
'''
retval = check_user_validity("", str(mytoken))
if retval is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
return False, "L'email ou le token ne sont pas valident"
# Recuperation du recid de la personne
user_recid = get_user_recid_from_token(str(mytoken))
if user_recid is False:
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid du user")
return False, " Les informations d'identification sont incorrectes"
myuserrecid = user_recid
coll_name = MYSY_GV.dbname['image_ch']
RetObject = []
for retVal in coll_name.find({'recid':myuserrecid, "type":"profil"} ):
user2={}
user2['date_update'] = retVal['date_update']
decode = retVal['img'].decode()
user2['img'] = decode
data1 = json.loads(json.dumps(user2))
return True, data1
return False, ""
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, ""
'''
Cette fonction replace les caractères speciaux et ponctuation par des space
'''
def Ela_Remove_Ponct_Special_Caractere(sentence):
try:
text = sentence.lower() # mettre les mots en minuscule
# Retirons les caractères spéciaux :
text = re.sub(r"[,\!\?\%\(\)\/\"]", " ", text)
text = re.sub(r"\&\S*\s", " ", text)
text = re.sub(r"\-", " ", text)
list_noises = ['...', '.', ';', ',', ':', '!', '?', ')', '(', '[', ']', '\'', '"', '', '`','©', '',
'{', '}', '-', '=', '°', '#', '-', '/', '~', '&', '\\', '.', '^', '$', '*', '+','\\n','\n',
'?', '{', '}', '[', ']', '|', '(', ')', '-', '>', '<', '@','®', '', '«', '»']
sentence = text
for noise in list_noises:
#print(" suppression de : '"+str(noise)+"' ")
sentence = sentence.replace(str(noise), " ")
#print(" AFTER REPLACE NOISES = "+str(sentence))
return True, sentence
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
print(str(inspect.stack()[0][3]) + " -" + str(e)+" - Line : "+ str(exc_tb.tb_lineno) )
return False, " Impossible Ela_Remove_Ponct_Special_Caractere"
'''
Cette fonction prend un titre (une phrase) et retrounre
l'internal url associé
'''
def CreateInternalUrl(sentence=None):
try:
internal_url = ""
if( len(sentence) <= 0 ):
return False, ""
my_internal_url = sentence
local_status, my_internal_url = Ela_Remove_Ponct_Special_Caractere(my_internal_url)
my_internal_url = unidecode(my_internal_url.lower())
my_internal_url = my_internal_url.replace("--", "-")
my_internal_url = my_internal_url.replace(" ", "-")
my_internal_url = my_internal_url.replace("/", "-")
if (my_internal_url.startswith('-')):
my_internal_url = my_internal_url[1:]
if (my_internal_url.endswith('-')):
my_internal_url = my_internal_url[:-1]
suffix = hashlib.md5(my_internal_url.encode()).hexdigest()
final_internal_url = str(my_internal_url) + "-" + str(suffix[-3:])
final_internal_url = final_internal_url.replace("--", "-")
internal_url = final_internal_url
return True, internal_url
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, ""

View File

@ -179,16 +179,23 @@ def get_all_class(diction):
#print(" My Data ="+str(mydata)) #print(" My Data ="+str(mydata))
status, tab_training_inzone = get_training_in_user_zone(diction)
nb_formation_a_jouter = MYSY_GV.MAINPAGE_QUERY_LIMIT_ROW - len(tab_training_inzone)
print(" NB = tab_training_inzone : "+str(len(tab_training_inzone)))
print(" tab_training_inzone = ############# "+str(tab_training_inzone))
coll_name = MYSY_GV.dbname['myclass'] coll_name = MYSY_GV.dbname['myclass']
val_tmp = 1 val_tmp = len(tab_training_inzone)
insertObject = [] insertObject = []
for x in coll_name.find({ "$or": [ {'valide':'1', 'locked':'0', 'isalaune':'1'}, { 'coeur': 1 } ] }, for x in coll_name.find({ "$or": [ {'valide':'1', 'locked':'0', 'isalaune':'1'}, { 'coeur': 1 } ] },
{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0, {"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }).\ "valide": 0, "locked": 0, "partner_owner_recid": 0, }).\
limit(MYSY_GV.MAINPAGE_QUERY_LIMIT_ROW).\ limit(nb_formation_a_jouter).\
sort( sort(
[ ("coeur", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING),]): [ ("coeur", pymongo.DESCENDING), ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING),]):
@ -207,16 +214,132 @@ def get_all_class(diction):
user = x user = x
user['id'] = str(val_tmp) user['id'] = str(val_tmp)
insertObject.append(JSONEncoder().encode(user)) insertObject.append(JSONEncoder().encode(user))
tab_training_inzone.append(JSONEncoder().encode(user))
val_tmp = val_tmp + 1 val_tmp = val_tmp + 1
#print(" insertObject = ", str(insertObject)) #print(" insertObject = ", str(tab_training_inzone))
return True, insertObject #return True, insertObject
return True, tab_training_inzone
except Exception as e: except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info() 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)) mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de recuperer les formations" return False, " Impossible de recuperer les formations"
'''
Cette Fonction recuperer les formation dans la zone de l'utilisateur.
Par zone utilisateur j'entends : ville or pays
/!\ IMPORTANT :
Si on veut UNIQUEMENT diffuser une formation dans une ville, alors il faut :
- reseigner le champs : zone_diffusion.city
- Laisser le champs : zone_diffusion.country à VIDE.
Par defaut, le système cherche les diffuser dans un pays ou dans une ville.
le champs pays est renseigner, alors la formation a est diffuser dans tous le pays.
Si le la collection "zone_diffusion" est vide ou n'existe pas, alors les formations sont diffusées partout dans le monde.
'''
def get_training_in_user_zone(diction):
try:
insertObject = []
# Dictionnaire des champs utilisables
field_list = ['token', 'user_ip', 'user_country_code', 'user_country_name', 'user_city',
'user_postal', 'user_latitude', 'user_longitude', 'user_state', 'search_text', 'certif',
'support', 'type', 'lang', 'price', 'distance', 'duration']
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 autorisé")
return False, " Recherche impossible"
# Recuperation des parametres
mydata = {}
if ("user_ip" in diction.keys()):
if diction['user_ip']:
mydata['user_ip'] = diction['user_ip']
if ("user_country_code" in diction.keys()):
if diction['user_country_code']:
mydata['user_country_code'] = diction['user_country_code']
if ("user_country_name" in diction.keys()):
if diction['user_country_name']:
mydata['user_country_name'] = diction['user_country_name']
if ("user_city" in diction.keys()):
if diction['user_city']:
mydata['user_city'] = diction['user_city']
if ("user_postal" in diction.keys()):
if diction['user_postal']:
mydata['user_postal'] = diction['user_postal']
if ("user_latitude" in diction.keys()):
if diction['user_latitude']:
mydata['user_latitude'] = diction['user_latitude']
if ("user_longitude" in diction.keys()):
if diction['user_longitude']:
mydata['user_longitude'] = diction['user_longitude']
if ("user_state" in diction.keys()):
if diction['user_state']:
mydata['user_state'] = diction['user_state']
# print(" My Data ="+str(mydata))
coll_name = MYSY_GV.dbname['myclass']
val_tmp = 1
insertObject = []
print(" critère de recherche : user_country_code = "+str(mydata['user_country_code']).lower()+" ---- user_city = "+str(mydata['user_city']).lower())
for x in coll_name.find({ "$or": [ {'valide':'1', 'locked':'0', "zone_diffusion.country":str(mydata['user_country_code']).lower()},
{'valide':'1', 'locked':'0', "zone_diffusion.city":str(mydata['user_city']).lower()} ] },
{"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0,
"valide": 0, "locked": 0, "partner_owner_recid": 0, }).\
limit(MYSY_GV.MAINPAGE_QUERY_LIMIT_ROW).\
sort(
[ ("price", pymongo.ASCENDING), ("date_update", pymongo.DESCENDING),]):
#print("AVANT ==> "+str(x['description']))
val = x['description']
if( len(x['description']) > MYSY_GV.MAX_CARACT ):
x['description'] = val[:MYSY_GV.MAX_CARACT]+" ..."
else:
x['description'] = val[:MYSY_GV.MAX_CARACT]
#mycommon.myprint("APRES ==> " + str(x['description']))
user = x
user['id'] = str(val_tmp)
insertObject.append(JSONEncoder().encode(user))
val_tmp = val_tmp + 1
return True, insertObject
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 recuperer les formations dans la zone de l'utilisateur"
''' '''
Cette fonction recherche les formations correspondant à un text Cette fonction recherche les formations correspondant à un text