18/03/23 - 21h45
parent
b2594e981b
commit
66a1a793b7
|
@ -2,7 +2,6 @@
|
|||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="16/03/23 - 17h45">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" beforeDir="false" afterPath="$PROJECT_DIR$/lms_chamilo/mysy_lms.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
|
|
5087
Log/log_file.log
5087
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -24,7 +24,7 @@ import requests
|
|||
import mariadb
|
||||
import hashlib
|
||||
import bcrypt
|
||||
|
||||
from pymongo import ReturnDocument
|
||||
|
||||
|
||||
"""
|
||||
|
@ -198,6 +198,28 @@ def Create_MySy_LMS_User(diction):
|
|||
|
||||
conn.commit()
|
||||
print(f"Last Inserted ID: {cur.lastrowid}")
|
||||
|
||||
|
||||
""""
|
||||
Creaion des valeur 'nb_formation' et pack dans la table 'extra_field_values'
|
||||
"""
|
||||
# Recuperation des données du partenaire
|
||||
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire"
|
||||
|
||||
|
||||
new_dicton = {}
|
||||
new_dicton['token'] = my_token
|
||||
new_dicton['lms_user_id'] = str(cur.lastrowid)
|
||||
new_dicton['mysy_pack'] = my_partner['pack_service']
|
||||
new_dicton['mysy_nb_formation'] = my_partner['nb_formation']
|
||||
|
||||
local_status, local_message, local_value = Update_Pack_MySy_LMS_User(new_dicton)
|
||||
if( local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : impossible de créer les varibblers")
|
||||
|
||||
lastrowid = cur.lastrowid
|
||||
|
||||
conn.close()
|
||||
|
@ -607,6 +629,8 @@ def Update_Pack_MySy_LMS_User(diction):
|
|||
print(f"mysy_pack_id: ", mysy_pack_id[0] )
|
||||
mysy_pack_id_val = mysy_pack_id[0]
|
||||
|
||||
|
||||
|
||||
query_2 = "select id from extra_field_values where field_id = '"+str(mysy_pack_id_val)+"' and item_id = '"+str(lms_user_id)+"' "
|
||||
print(" ### query_2 = ", query_2)
|
||||
mysy_pack_id2 = cur.execute(query_2)
|
||||
|
@ -620,7 +644,22 @@ def Update_Pack_MySy_LMS_User(diction):
|
|||
|
||||
query_get_mysy_nb_formation_id = "select id from extra_field where variable = '" + str(mysy_nb_formation) + "' "
|
||||
|
||||
localquery = "update extra_field_values set extra_field_values.value ='"+str(mysy_pack)+"' where id = '"+str(mysy_pack_id_val2)+"' "
|
||||
now = date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
localquery = ""
|
||||
|
||||
if( str(mysy_pack_id_val2).strip() != ""):
|
||||
localquery = "update extra_field_values set extra_field_values.value ='" + str(
|
||||
mysy_pack) + "' where id = '" + str(mysy_pack_id_val2) + "' "
|
||||
|
||||
elif( str(mysy_pack_id_val2).strip() == ""):
|
||||
print(" #### la ligne n'existe pas, il faut la créer ")
|
||||
localquery = " INSERT INTO extra_field_values SET field_id = '"+str(mysy_pack_id_val)+"' , " \
|
||||
" item_id = '"+str(lms_user_id)+"'," \
|
||||
" created_at = '"+now+"', updated_at = '" + now + "', " \
|
||||
" value = '"+str(mysy_pack)+"' "
|
||||
|
||||
|
||||
|
||||
print(" ### localquery = ", localquery)
|
||||
|
||||
try:
|
||||
|
@ -635,6 +674,14 @@ def Update_Pack_MySy_LMS_User(diction):
|
|||
|
||||
conn.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
""" MISE à JOUR DU mysy_nb_formation """
|
||||
query_get_mysy_pack_id = "select id from extra_field where variable = 'mysy_nb_formation' "
|
||||
print(" ### query_get_mysy_pack_id = ", query_get_mysy_pack_id)
|
||||
|
@ -658,8 +705,22 @@ def Update_Pack_MySy_LMS_User(diction):
|
|||
query_get_mysy_nb_formation_id = "select id from extra_field where variable = '" + str(
|
||||
mysy_nb_formation) + "' "
|
||||
|
||||
localquery = "update extra_field_values set extra_field_values.value ='" + str(
|
||||
mysy_nb_formation) + "' where id = '" + str(mysy_pack_id_val2) + "' "
|
||||
localquery = ""
|
||||
|
||||
if (str(mysy_pack_id_val2).strip() != ""):
|
||||
localquery = "update extra_field_values set extra_field_values.value ='" + str(
|
||||
mysy_nb_formation) + "' where id = '" + str(mysy_pack_id_val2) + "' "
|
||||
|
||||
elif (str(mysy_pack_id_val2).strip() == ""):
|
||||
print(" #### la ligne n'existe pas, il faut la créer ")
|
||||
localquery = " INSERT INTO extra_field_values SET field_id = '" + str(mysy_pack_id_val) + "' , " \
|
||||
" item_id = '" + str(
|
||||
lms_user_id) + "'," \
|
||||
" created_at = '" + now + "', updated_at = '" + now + "', " \
|
||||
" value = '" + str(mysy_nb_formation) + "' "
|
||||
|
||||
|
||||
|
||||
print(" ### localquery = ", localquery)
|
||||
|
||||
try:
|
||||
|
@ -673,9 +734,6 @@ def Update_Pack_MySy_LMS_User(diction):
|
|||
|
||||
conn.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
return True, " Creation du compte LMS OK. l'id modifié est = ", 1
|
||||
|
||||
except Exception as e:
|
||||
|
@ -690,8 +748,14 @@ Si le client n'existe pas, il le crée avec le pack et le bon nombre de formatio
|
|||
/!\ : On stock dans mysy (collection partnair_account) l'id chamilo du user.
|
||||
le nom du champ est : mysy_lms_user_id/
|
||||
|
||||
"""
|
||||
def Check_MySy_LMS_User(diction):
|
||||
/!\ : si le pack utilisateur necessite d'avoir un compte LMS, 3 cas de figures se posent :
|
||||
1 - C'est un tout nouveau compte, alors on le crée simplement
|
||||
2 - CAS CRITIQUE : C'est un ancien compte qui a changé plusieurs de fois de pack. il est passé d'un pack avec LMS vers un compte sans LMS puis vers un compte avec LMS.
|
||||
dans cas, on reative simplement le compte.
|
||||
|
||||
3 - Cas d'un client qui passe d'un pack avec LMS vers un pack sans LMS, dans ce cas on desactive le compte LSM, on desacrive ses formations aussi.
|
||||
"""
|
||||
def Check_MySy_LMS_Account(diction):
|
||||
try:
|
||||
|
||||
# Verification des champs
|
||||
|
@ -729,17 +793,17 @@ def Check_MySy_LMS_User(diction):
|
|||
|
||||
if retval is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||
return False, " Impossible de créer le compte LMS", False
|
||||
return False, " Impossible de créer le compte LMS"
|
||||
|
||||
# Recuperation du recid de l'utilisateur
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if partner_recid is False:
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer le token du partenaire")
|
||||
return False, " Impossible de recuperer le token du partenaire", False
|
||||
return False, " Impossible de recuperer le token du partenaire"
|
||||
|
||||
if (len(str(my_token)) <= 0):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token est vide")
|
||||
return False, " Impossible de créer le compte LMS", False
|
||||
return False, " Impossible de créer le compte LMS"
|
||||
|
||||
|
||||
# Recuperation des données du partenaire
|
||||
|
@ -748,16 +812,17 @@ def Check_MySy_LMS_User(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
||||
return False, str(inspect.stack()[0][3]) +" - impossible de recuperer les données du partenaire"
|
||||
|
||||
#print(" ### my_partner = ", str(my_partner))
|
||||
mysy_lms_user_id = ""
|
||||
if ("mysy_lms_user_id" in my_partner.keys()):
|
||||
if diction['mysy_lms_user_id']:
|
||||
mysy_lms_user_id = diction['mysy_lms_user_id']
|
||||
if my_partner['mysy_lms_user_id']:
|
||||
mysy_lms_user_id = my_partner['mysy_lms_user_id']
|
||||
|
||||
|
||||
pack_service = ""
|
||||
if ("pack_service" in my_partner.keys()):
|
||||
if diction['pack_service']:
|
||||
pack_service = diction['pack_service']
|
||||
if my_partner['pack_service']:
|
||||
pack_service = my_partner['pack_service']
|
||||
|
||||
|
||||
# Recuperation des caracterisques du pack
|
||||
|
@ -766,39 +831,129 @@ def Check_MySy_LMS_User(diction):
|
|||
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du pack (1)")
|
||||
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du pack (1)"
|
||||
|
||||
lms_count = ""
|
||||
if ("lms_count" in pack_data.keys()):
|
||||
if diction['lms_count']:
|
||||
lms_count = diction['lms_count']
|
||||
lms_account = ""
|
||||
if ("lms_account" in pack_data.keys()):
|
||||
if pack_data['lms_account']:
|
||||
lms_account = pack_data['lms_account']
|
||||
|
||||
if (lms_count != "0" and lms_count != "1") :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - lms_count est incorrecte ")
|
||||
return False, str(inspect.stack()[0][3]) + " - lms_count est incorrecte "
|
||||
if (lms_account != "0" and lms_account != "1") :
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - lms_account est incorrecte ")
|
||||
return False, str(inspect.stack()[0][3]) + " - lms_account est incorrecte "
|
||||
|
||||
if( lms_account == "1"):
|
||||
"""
|
||||
Ce pack necessite un compte LMS
|
||||
"""
|
||||
if( mysy_lms_user_id.strip() == ""):
|
||||
print(" ### ce partenaire n'as pas de compte LMS, il faut en créer 1 ")
|
||||
|
||||
new_diction = {}
|
||||
lastname = ""
|
||||
if ("contact_nom" in my_partner.keys()):
|
||||
if my_partner['contact_nom']:
|
||||
lastname = my_partner['contact_nom']
|
||||
if( lastname == ""):
|
||||
lastname = my_partner['invoice_nom']
|
||||
|
||||
|
||||
if( mysy_lms_user_id.strip() == ""):
|
||||
print(" ### ce partenaire n'as pas de compte LMS ")
|
||||
else:
|
||||
print(" ### ce partenaire A un compte. ")
|
||||
firstname = ""
|
||||
if ("contact_prenom" in my_partner.keys()):
|
||||
if my_partner['contact_prenom']:
|
||||
firstname = my_partner['contact_prenom']
|
||||
if (firstname == ""):
|
||||
firstname = my_partner['invoice_nom']
|
||||
|
||||
new_diction['token'] = my_partner['token']
|
||||
new_diction['lastname'] = lastname
|
||||
new_diction['firstname'] = firstname
|
||||
new_diction['email'] = my_partner['email']
|
||||
new_diction['password'] = my_partner['pwd']
|
||||
new_diction['locked'] = "0"
|
||||
new_diction['official_code'] = ""
|
||||
new_diction['username'] = my_partner['email']
|
||||
|
||||
|
||||
local_status, local_retval, new_lms_use_id = Create_MySy_LMS_User(new_diction)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de créer le compte LSM ")
|
||||
return False, str(inspect.stack()[0][3]) + " - Impossible de créer le compte LSM "
|
||||
|
||||
# Apres la creation du compte LSM, on met à jour le compte mysy avec la valeur du champs : mysy_lms_user_id
|
||||
mysy_coll_query = {}
|
||||
mysy_coll_query['mysy_lms_user_id'] = str(new_lms_use_id)
|
||||
mysy_coll_query['date_update'] = str(datetime.now())
|
||||
ret_val = MYSY_GV.dbname['partnair_account'].find_one_and_update(
|
||||
{'recid': my_partner['recid'], 'active': '1', 'locked': '0'},
|
||||
{"$set": mysy_coll_query},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
if (ret_val['_id'] is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " : WARNING : Impossible de mettre à jour le compte MySy avec le mysy_lms_user_id = ",
|
||||
str(mysy_lms_user_id))
|
||||
|
||||
|
||||
"""
|
||||
/!\ : si le pack utilisateur necessite d'avoir un compte LMS, 3 cas de figures se posent :
|
||||
1 - C'est un tout nouveau compte, alors on le crée simplement
|
||||
2 - CAS CRITIQUE : C'est un ancien compte qui a changé plusieurs de fois de pack. il est passé d'un pack avec LMS vers un compte sans LMS puis vers un compte avec LMS.
|
||||
dans cas, on reative simplement le compte.
|
||||
else:
|
||||
print(" ### ce partenaire A un compte. il faut mettre à jour le compte LMS avec le nouveau pack, le nombre max de formation")
|
||||
"""
|
||||
/!\ il ne faut pas oublier de gerer le cas ou le client à plus de cours de activé dans chamilo.
|
||||
une solition est serai de refuser tout changement tant que le nombre de formation dans mysy et dans lms ne sont pas cohérent.
|
||||
DONC LE CONTROLE EST A FAIRE BIEN EN AMONT
|
||||
|
||||
3 - Cas d'un client qui passe d'un pack avec LMS vers un pack sans LMS, dans ce cas on desactive le compte LSM, on desacrive ses formations aussi.
|
||||
"""
|
||||
"""
|
||||
# Reactivation du compte utilisateur
|
||||
new_diction = {}
|
||||
new_diction['password'] = my_partner['pwd']
|
||||
new_diction['lms_user_id'] = my_partner['mysy_lms_user_id']
|
||||
print(" ### Ractivation du compte utilisation mysy_lms_user_id = ", my_partner['mysy_lms_user_id'])
|
||||
local_status, local_retval = Enable_MySy_LMS_User(new_diction)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de reactiver le compte LSM ")
|
||||
return False, str(inspect.stack()[0][3]) + " - Impossible de reactiver le compte LSM "
|
||||
|
||||
# Mise à jour des autres info.
|
||||
new_diction = {}
|
||||
new_diction['token'] = my_partner['token']
|
||||
new_diction['lms_user_id'] = my_partner['mysy_lms_user_id']
|
||||
new_diction['mysy_pack'] = my_partner['pack_service']
|
||||
new_diction['mysy_nb_formation'] = my_partner['nb_formation']
|
||||
|
||||
print(" ### stored mysy_nb_formation = ", my_partner['nb_formation'])
|
||||
|
||||
local_status, local_retval, new_lms_use_id = Update_Pack_MySy_LMS_User(new_diction)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le compte LSM ")
|
||||
return False, str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le compte LSM "
|
||||
|
||||
|
||||
|
||||
elif (lms_account == "0"):
|
||||
print(" ### Ce pack NE necessite PAS un compte LMS ")
|
||||
"""
|
||||
Ce pack NE necessite PAS un compte LMS. il faut donc verifier si le partenaire à deja un compte, au quel
|
||||
cas il faut le desactiver
|
||||
"""
|
||||
if (mysy_lms_user_id.strip() != ""):
|
||||
print(" ### Ce partenaire a deja un compte LMS, il faut donc le desactiver ")
|
||||
"""
|
||||
Ce partenaire a deja un compte LMS, c'est donc une mise à jour qu'il faut faire
|
||||
"""
|
||||
new_diction = {}
|
||||
|
||||
return True, " Creation du compte LMS OK. l'id = "
|
||||
new_diction['lms_user_id'] = my_partner['mysy_lms_user_id']
|
||||
|
||||
local_status, local_retval = Disable_MySy_LMS_User(new_diction)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de desactiver le compte LSM ")
|
||||
return False, str(inspect.stack()[0][3]) + " - Impossible de desactiver le compte LSM "
|
||||
|
||||
|
||||
return True, " Creation/mise à jour du compte LSM ok"
|
||||
|
||||
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 créer le compte LMS : Check_MySy_LMS_User ", False
|
||||
return False, " Impossible de créer le compte LMS : Check_MySy_LMS_User "
|
18
main.py
18
main.py
|
@ -2652,6 +2652,24 @@ def recherche_business_price():
|
|||
return jsonify(status=localStatus, message=message )
|
||||
|
||||
|
||||
"""
|
||||
Cette API verifie si un client mysy existe sur chamilo.
|
||||
Si le client n'existe pas, il le crée avec le pack et le bon nombre de formation
|
||||
/!\ : On stock dans mysy (collection partnair_account) l'id chamilo du user.
|
||||
le nom du champ est : mysy_lms_user_id/
|
||||
"""
|
||||
@app.route('/myclass/api/Check_MySy_LMS_Account/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Check_MySy_LMS_Account():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### Check_MySy_LMS_User : payload = ",payload)
|
||||
localStatus, message = mysy_lms.Check_MySy_LMS_Account(payload)
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
|
|
Loading…
Reference in New Issue