update 18/02/2022 - 15h00
parent
b5f8091a67
commit
fa33a46065
4724
Log/log_file.log
4724
Log/log_file.log
File diff suppressed because it is too large
Load Diff
473
class_mgt.py
473
class_mgt.py
|
@ -11,9 +11,10 @@ from datetime import datetime
|
|||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
import os
|
||||
import sys, os
|
||||
import csv
|
||||
import pandas as pd
|
||||
from pymongo import ReturnDocument
|
||||
|
||||
class JSONEncoder(json.JSONEncoder):
|
||||
def default(self, o):
|
||||
|
@ -43,7 +44,7 @@ def add_class(diction):
|
|||
# field_list.
|
||||
'''
|
||||
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel', 'presentiel',
|
||||
'price', 'url','duree_formation','partner_mail', 'token', 'plus_produit', 'mots_cle']
|
||||
'price', 'url','duree_formation','token', 'plus_produit', 'mots_cle']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
|
@ -54,8 +55,7 @@ def add_class(diction):
|
|||
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 = ['external_code', 'title', 'description', 'trainer', 'distantiel', 'presentiel',
|
||||
'partner_mail', 'token']
|
||||
field_list_obligatoire = ['external_code', 'title', 'description', 'trainer', 'distantiel', 'presentiel', 'token']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -70,6 +70,34 @@ def add_class(diction):
|
|||
# recuperation des paramettre
|
||||
mydata = {}
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour créer une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT LES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
mydata['partner_owner_recid'] = user_recid
|
||||
|
||||
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
mydata['external_code'] = diction['external_code']
|
||||
|
@ -114,9 +142,6 @@ def add_class(diction):
|
|||
if diction['duree_formation']:
|
||||
mydata['duree_formation'] = diction['duree_formation']
|
||||
|
||||
if ("partner_mail" in diction.keys()):
|
||||
if diction['partner_mail']:
|
||||
mydata['partner_mail'] = diction['partner_mail']
|
||||
|
||||
|
||||
if ("plus_produit" in diction.keys()):
|
||||
|
@ -128,9 +153,6 @@ def add_class(diction):
|
|||
if diction['mots_cle']:
|
||||
mydata['mots_cle'] = diction['mots_cle']
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
mydata['active'] = '1'
|
||||
mydata['locked'] = '0'
|
||||
|
@ -139,18 +161,7 @@ def add_class(diction):
|
|||
mydata['indexed_desc'] = '0'
|
||||
mydata['indexed_obj'] = '0'
|
||||
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
coll_token = dbname['user_token']
|
||||
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
retval = mycommon.check_token_validity(str(mydata['partner_mail']), str(mydata['token'] ) )
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - L'email ou le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Verification si cette formation exite deja .
|
||||
|
@ -165,12 +176,11 @@ def add_class(diction):
|
|||
|
||||
coll_name.insert_one(mydata)
|
||||
|
||||
|
||||
|
||||
return True, "La formation a bien été ajouté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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "Impossible d'ajouter la formation"
|
||||
|
||||
|
||||
|
@ -190,7 +200,7 @@ def update_class(diction):
|
|||
# field_list.
|
||||
'''
|
||||
field_list = ['external_code', 'title', 'description', 'trainer', 'institut_formation', 'distantiel',
|
||||
'presentiel','price', 'url', 'duree_formation', 'partner_mail','token','plus_produit', 'mots_cle']
|
||||
'presentiel','price', 'url', 'duree_formation', 'token','plus_produit', 'mots_cle']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
|
@ -202,7 +212,7 @@ def update_class(diction):
|
|||
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 = ['external_code', 'partner_mail', 'token']
|
||||
field_list_obligatoire = ['external_code', 'token']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -213,6 +223,34 @@ def update_class(diction):
|
|||
mydata = {}
|
||||
my_external_code = ""
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour modifier une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION / MODIFICATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT CELLES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
partner_recid = user_recid
|
||||
|
||||
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
@ -257,14 +295,6 @@ def update_class(diction):
|
|||
if diction['duree_formation']:
|
||||
mydata['duree_formation'] = diction['duree_formation']
|
||||
|
||||
if ("partner_mail" in diction.keys()):
|
||||
if diction['partner_mail']:
|
||||
mydata['partner_mail'] = diction['partner_mail']
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
|
||||
if ("plus_produit" in diction.keys()):
|
||||
if diction['plus_produit']:
|
||||
|
@ -284,40 +314,35 @@ def update_class(diction):
|
|||
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
coll_token = dbname['user_token']
|
||||
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
retval = mycommon.check_token_validity(str(mydata['partner_mail']), str(mydata['token']) )
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - L'email ou le token ne sont pas valident")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
|
||||
# seules les formation avec locked = 0 et valide=1 sont modifiables
|
||||
ret_val = coll_name.find_and_modify(query={'external_code': str(my_external_code), 'locked': '0', 'valide': '1'},
|
||||
update={"$set": mydata}
|
||||
)
|
||||
ret_val = coll_name.find_one_and_update({'external_code': str(my_external_code), 'partner_owner_recid':partner_recid, 'locked': '0', 'valide': '1'},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint( str(inspect.stack()[0][3])+" - La formation a bin ete mise à jour =" + str(ret_val['_id']))
|
||||
return True, " La formation a été mise à jour"
|
||||
nb_doc = str(ret_val['_id'])
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - La formation a bin ete mise à jour =" + str(nb_doc))
|
||||
return True, " La formation a été mise à jour"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - Mise à jour formation ==> KO ")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour la formation : "+str(my_external_code) )
|
||||
return False, "Impossible de mettre à jour la formation "+str(my_external_code)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e))
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
return False, " Impossible de mettre à jour la formation "
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Desactivation d'une formation
|
||||
|
||||
Disable a training
|
||||
Disable a training, set mydata['valide'] = '0'
|
||||
'''
|
||||
def disable_class(diction):
|
||||
try:
|
||||
|
@ -351,55 +376,76 @@ def disable_class(diction):
|
|||
mydata = {}
|
||||
my_external_code = ""
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour modifier une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION / MODIFICATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT CELLES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
partner_recid = user_recid
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
mydata['valide'] = '0'
|
||||
|
||||
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
coll_token = dbname['user_token']
|
||||
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']) )
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - L'email ou le token ne sont pas valident")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
|
||||
# seules les formation avec locked = 0 et valide=1 sont modifiables
|
||||
ret_val = coll_name.find_and_modify(query={'external_code': str(my_external_code), 'locked': '0', 'valide': '0'},
|
||||
update={"$set": mydata}
|
||||
)
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0',
|
||||
'valide': '1'},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint( str(inspect.stack()[0][3])+" - La formation a bin ete mise à jour =" + str(ret_val['_id']))
|
||||
return True, " La formation a été desactivée"
|
||||
nb_doc = str(ret_val['_id'])
|
||||
mycommon.myprint(
|
||||
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"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - Mise à jour formation ==> KO ")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " +str(my_external_code) )
|
||||
return False, " Impossible de desactivier la formation : "+str(my_external_code)
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e))
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
|
||||
return False, " Impossible de desactivier la formation "
|
||||
|
||||
|
||||
'''
|
||||
reactivation d'une formation
|
||||
|
||||
Enable a training
|
||||
Enable a training set mydata['valide'] = '1'
|
||||
'''
|
||||
def enable_class(diction):
|
||||
try:
|
||||
|
@ -433,55 +479,71 @@ def enable_class(diction):
|
|||
mydata = {}
|
||||
my_external_code = ""
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour modifier une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION / MODIFICATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT CELLES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
partner_recid = user_recid
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
mydata['valide'] = '1'
|
||||
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
coll_token = dbname['user_token']
|
||||
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']) )
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - L'email ou le token ne sont pas valident")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
|
||||
# seules les formation avec locked = 0 et valide=1 sont modifiables
|
||||
ret_val = coll_name.find_and_modify(query={'external_code': str(my_external_code), 'locked': '0', 'valide': '1'},
|
||||
update={"$set": mydata}
|
||||
)
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0',
|
||||
'valide': '0'},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint( str(inspect.stack()[0][3])+" - La formation a bin ete mise à jour =" + str(ret_val['_id']))
|
||||
return True, " La formation a été desactivée"
|
||||
nb_doc = str(ret_val['_id'])
|
||||
mycommon.myprint(
|
||||
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"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - Mise à jour formation ==> KO ")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactivier : " + str(my_external_code))
|
||||
return False, " Impossible de reactivée la formation : " + str(my_external_code)
|
||||
|
||||
except Exception as e:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e))
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
return False, " Impossible de reactiver la formation"
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Desactivation d'une formation
|
||||
|
||||
unlock a training
|
||||
unlock a training set mydata['locked'] = '0'
|
||||
'''
|
||||
def unlock_class(diction):
|
||||
try:
|
||||
|
@ -515,48 +577,169 @@ def unlock_class(diction):
|
|||
mydata = {}
|
||||
my_external_code = ""
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour modifier une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION / MODIFICATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT CELLES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
coll_token = dbname['user_token']
|
||||
|
||||
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']) )
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - L'email ou le token ne sont pas valident")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
partner_recid = user_recid
|
||||
|
||||
|
||||
|
||||
# seules les formation avec locked = 0 et valide=1 sont modifiables
|
||||
ret_val = coll_name.find_and_modify(query={'external_code': str(my_external_code), 'locked': '0', 'valide': '1'},
|
||||
update={"$set": mydata}
|
||||
)
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
mydata['locked'] = '0'
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
|
||||
# seules les formation avec locked = 1 et valide=1 sont 'unlockable'
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '1',
|
||||
'valide': '1'},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
mycommon.myprint( str(inspect.stack()[0][3])+" - La formation a bin ete mise à jour =" + str(ret_val['_id']))
|
||||
return True, " La formation a été desactivée"
|
||||
nb_doc = str(ret_val['_id'])
|
||||
mycommon.myprint(
|
||||
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"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - Mise à jour formation ==> KO ")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de debloquer : " + str(my_external_code))
|
||||
return False, " Impossible de debloquer la formation : " + str(my_external_code)
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
mycommon.myprint(str(inspect.stack()[0][3])+" - " +str(e))
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
'''
|
||||
Verrouillage d'une formation
|
||||
|
||||
lock a training set mydata['locked'] = '1'
|
||||
'''
|
||||
|
||||
|
||||
def lock_class(diction):
|
||||
try:
|
||||
|
||||
'''
|
||||
# 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.
|
||||
'''
|
||||
field_list = ['external_code', 'token']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " - Creation partner account : Le champ '" + val + "' n'existe pas, Creation formation annulée")
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
'''
|
||||
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 = ['external_code', '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, " Impossible de mettre à jour la formation"
|
||||
|
||||
# recuperation des paramettre
|
||||
mydata = {}
|
||||
my_external_code = ""
|
||||
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
mydata['token'] = diction['token']
|
||||
|
||||
# Verification de la validité du token
|
||||
'''
|
||||
Important : pour modifier une formation, il faut obligatoirement avoir un token.
|
||||
PAS DE CREATION / MODIFICATION DE FORMATION EN MODE NON CONNECTE.
|
||||
|
||||
CONCERNANT CELLES CREEES PAR NOS SYSTEME AUTOMATIQUE, IL FAUDRA LEUR PASSER UNE VALEUR MALGRE TOUT
|
||||
|
||||
'''
|
||||
retval = mycommon.check_token_validity("", str(mydata['token']))
|
||||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token ne sont pas valident")
|
||||
return False, "L'email ou le token ne sont pas valident"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
user_recid = mycommon.get_user_recid_from_token(str(mydata['token']))
|
||||
if user_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le recid de l'utilisateur")
|
||||
return False, " Les informations d'identification sont incorrectes"
|
||||
|
||||
partner_recid = user_recid
|
||||
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
my_external_code = diction['external_code']
|
||||
|
||||
mydata['date_update'] = str(datetime.now())
|
||||
|
||||
mydata['locked'] = '1'
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
|
||||
# seules les formation avec locked = 1 et valide=1 sont 'unlockable'
|
||||
ret_val = coll_name.find_one_and_update(
|
||||
{'external_code': str(my_external_code), 'partner_owner_recid': partner_recid, 'locked': '0',
|
||||
'valide': '1'},
|
||||
{"$set": mydata},
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val and ret_val['_id']):
|
||||
nb_doc = str(ret_val['_id'])
|
||||
mycommon.myprint(
|
||||
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"
|
||||
|
||||
else:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de verrouiller la formation : " + str(my_external_code))
|
||||
return False, " Impossible de verrouiller la formation : " + str(my_external_code)
|
||||
|
||||
|
||||
|
||||
except Exception as e:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - " + str(e))
|
||||
return False, " Impossible de mettre à jour la formation"
|
||||
|
||||
|
||||
'''
|
||||
|
@ -574,7 +757,7 @@ def get_class(diction):
|
|||
# Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste
|
||||
# field_list.
|
||||
'''
|
||||
field_list = ['external_code', 'token']
|
||||
field_list = ['external_code', 'token', 'title', 'valide', 'locked']
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
if val not in field_list:
|
||||
|
@ -585,7 +768,7 @@ def get_class(diction):
|
|||
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 = ['external_code', 'token']
|
||||
field_list_obligatoire = ['token']
|
||||
|
||||
for val in field_list_obligatoire:
|
||||
if val not in diction:
|
||||
|
@ -606,6 +789,17 @@ def get_class(diction):
|
|||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
|
||||
'''
|
||||
Gestion des filters.
|
||||
'''
|
||||
|
||||
external_code_crit = {}
|
||||
if ("external_code" in diction.keys()):
|
||||
if diction['external_code']:
|
||||
external_code_crit['external_code'] = diction['external_code']
|
||||
|
||||
|
||||
coll_name = dbname['myclass']
|
||||
|
||||
# verifier que le token et l'email sont ok
|
||||
|
@ -634,17 +828,14 @@ def get_class(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3])+" - Impossible de recuperer le token de l'utilisateur")
|
||||
return False, " Impossible de recuperer la formation"
|
||||
|
||||
|
||||
# verifier que la formation existe bien et qu'elle n'est bloquée ni verroulée
|
||||
tmp = coll_name.find( {'external_code': my_external_code, 'valide':'1', 'locked':'0'})
|
||||
|
||||
if (tmp.count() <= 0):
|
||||
mycommon.myprint( str(inspect.stack()[0][3])+" - La formation '"+my_external_code+"' n'existe pas")
|
||||
return False, " Impossible de recuperer la formation"
|
||||
|
||||
|
||||
RetObject = []
|
||||
for retVal in coll_name.find({'external_code': my_external_code}):
|
||||
filt_external_code = {}
|
||||
if ("external_code" in diction.keys()):
|
||||
filt_external_code = {'external_code':{'$regex':str(diction['external_code'])}}
|
||||
|
||||
|
||||
for retVal in coll_name.find(({"$and": [ {'valide':'1'},{'locked':'0'},
|
||||
{'partner_owner_recid':user_recid} ,filt_external_code ]})):
|
||||
mycommon.myprint(str(retVal))
|
||||
user = retVal
|
||||
RetObject.append(JSONEncoder().encode(user))
|
||||
|
@ -653,7 +844,8 @@ def get_class(diction):
|
|||
|
||||
|
||||
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)+" - Line : "+ str(exc_tb.tb_lineno) )
|
||||
return False, " Impossible de recuperer la formation"
|
||||
|
||||
|
||||
|
@ -679,7 +871,8 @@ def get_class_global_search(search_string):
|
|||
#mycommon.myprint(" insertObject = ", insertObject)
|
||||
return insertObject
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False
|
||||
|
||||
|
||||
|
@ -701,7 +894,8 @@ def get_all_class_by_attribut(attribut, value):
|
|||
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False
|
||||
|
||||
|
||||
|
@ -800,5 +994,6 @@ def add_class_mass(file=None, Folder=None, diction=None):
|
|||
return True, str(total_rows)+" formations ont été inserées"
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "Impossible d'inserer les formation en masse "
|
||||
|
|
28
main.py
28
main.py
|
@ -255,7 +255,20 @@ def update_class():
|
|||
|
||||
|
||||
'''
|
||||
Verroue d'une formation - lock training
|
||||
deverrouillage d'une formation - unlock training
|
||||
|
||||
'''
|
||||
@app.route('/myclass/api/unlock_class/', methods=['POST'])
|
||||
@crossdomain(origin='*')
|
||||
def unlock_class():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### payload = ",payload)
|
||||
status, retval = cm.unlock_class(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
'''
|
||||
Verrouillage d'une formation - lock training
|
||||
|
||||
'''
|
||||
@app.route('/myclass/api/lock_class/', methods=['POST'])
|
||||
|
@ -269,19 +282,6 @@ def lock_class():
|
|||
|
||||
|
||||
|
||||
'''
|
||||
deverrouillage d'une formation - unlock training
|
||||
|
||||
'''
|
||||
@app.route('/myclass/api/unlock_class/', methods=['POST'])
|
||||
@crossdomain(origin='*')
|
||||
def unlock_class():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### payload = ",payload)
|
||||
status, retval = cm.unlock_class(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
'''
|
||||
Desactivé une formation - disable training
|
||||
|
|
|
@ -123,7 +123,8 @@ def add_user_message(diction):
|
|||
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "Impossible d'ajouter le message"
|
||||
|
||||
|
||||
|
|
12
wrapper.py
12
wrapper.py
|
@ -334,7 +334,8 @@ def recherche_text_simple(diction):
|
|||
return True, insertObject
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "Impossible de lancer la recherche"
|
||||
|
||||
|
||||
|
@ -631,7 +632,8 @@ def recherche_tips_ret_ref(diction):
|
|||
#return True, str(tab_ret)
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "N/A"
|
||||
|
||||
|
||||
|
@ -769,7 +771,8 @@ def recherche_tips(diction):
|
|||
#return True, str(tab_ret)
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "N/A"
|
||||
|
||||
|
||||
|
@ -848,6 +851,7 @@ def get_stored_recherche(diction):
|
|||
return True, RetObject
|
||||
|
||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, "Impossible de recuperer les recherches du user "
|
||||
|
||||
|
|
Loading…
Reference in New Issue