24/03/23 - 17h
parent
9d998e6e36
commit
ab53b25ed4
|
@ -3,14 +3,11 @@
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="21/03/23 - 22h">
|
<list default="true" id="1122d9e2-679f-46d6-8c4f-97e9ae4041b5" name="Changes" comment="21/03/23 - 22h">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" 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$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Template/MySy_Create_PRO_account_tpl.html" beforeDir="false" afterPath="$PROJECT_DIR$/Template/MySy_Create_PRO_account_tpl.html" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Session_Formation.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Template/MySy_account_pro_enabled_tpl.html" beforeDir="false" afterPath="$PROJECT_DIR$/Template/MySy_account_pro_enabled_tpl.html" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/data_indexees.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data_indexees.csv" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/ela_output_test_file_pandas_2.txt" beforeDir="false" afterPath="$PROJECT_DIR$/ela_output_test_file_pandas_2.txt" 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$/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" />
|
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/partners.py" beforeDir="false" afterPath="$PROJECT_DIR$/partners.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
|
|
@ -26,6 +26,7 @@ import jinja2
|
||||||
import ftplib
|
import ftplib
|
||||||
import pysftp
|
import pysftp
|
||||||
import email_mgt as email_mgt
|
import email_mgt as email_mgt
|
||||||
|
import lms_chamilo.mysy_lms as mys_lms
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Enregistrement d'un stagiaire
|
Enregistrement d'un stagiaire
|
||||||
|
@ -219,6 +220,14 @@ Mettre à jour les infomration d'un stgiaire
|
||||||
# status : 1 ==> Inscription validée
|
# status : 1 ==> Inscription validée
|
||||||
# status : -1 ==> Inscription annulée
|
# status : -1 ==> Inscription annulée
|
||||||
|
|
||||||
|
/!\ Inscription sur le LMS :
|
||||||
|
Si la session de formation possede un code de formation lms 'lms_class_code'
|
||||||
|
|
||||||
|
Alors cela veut dire que c'est une formation qui est gérée avec le LMS de MYSY.
|
||||||
|
Donc l'inscription va generer :
|
||||||
|
1 - La creation du compte LMS participant
|
||||||
|
2 - L'inscription de l'utilisateur à la formation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def UpdateStagiairetoClass(diction):
|
def UpdateStagiairetoClass(diction):
|
||||||
try:
|
try:
|
||||||
|
@ -267,8 +276,6 @@ def UpdateStagiairetoClass(diction):
|
||||||
query_key['session_id'] = diction['session_id']
|
query_key['session_id'] = diction['session_id']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||||
if (partner_recid is False):
|
if (partner_recid is False):
|
||||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le stagiaire ")
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour le stagiaire ")
|
||||||
|
@ -336,6 +343,9 @@ def UpdateStagiairetoClass(diction):
|
||||||
|
|
||||||
local_retval = coll_inscription.find_one(query_key)
|
local_retval = coll_inscription.find_one(query_key)
|
||||||
old_status = local_retval['status']
|
old_status = local_retval['status']
|
||||||
|
inscription_line_id = local_retval['_id']
|
||||||
|
|
||||||
|
|
||||||
if( new_status != old_status ):
|
if( new_status != old_status ):
|
||||||
# Il y a eu un changement de status
|
# Il y a eu un changement de status
|
||||||
if( new_status == "1"):
|
if( new_status == "1"):
|
||||||
|
@ -438,17 +448,81 @@ def UpdateStagiairetoClass(diction):
|
||||||
presentiel = local_tmp_session['presentiel']
|
presentiel = local_tmp_session['presentiel']
|
||||||
email_data['presentiel'] = presentiel
|
email_data['presentiel'] = presentiel
|
||||||
|
|
||||||
|
lms_class_code = ""
|
||||||
|
if ("lms_class_code" in local_tmp_session.keys() and local_tmp_session['lms_class_code']):
|
||||||
|
lms_class_code = local_tmp_session['lms_class_code']
|
||||||
|
|
||||||
|
|
||||||
if ( diction['status'] == "1" ):
|
if ( diction['status'] == "1" ):
|
||||||
# Il s'agit d'envoyer le message de confirmation d'une inscription
|
# Il s'agit d'envoyer le message de confirmation d'une inscription
|
||||||
local_status, local_message = email_session.incription_training_confirmation_mail(email_data)
|
local_status, local_message = email_session.incription_training_confirmation_mail(email_data)
|
||||||
|
|
||||||
|
""""
|
||||||
|
Inscription sur le LMS :
|
||||||
|
Si la session de formation possede un code de formation lms 'lms_class_code'
|
||||||
|
|
||||||
|
Alors cela veut dire que c'est une formation qui est gérée avec le LMS de MYSY.
|
||||||
|
Donc l'inscription va generer :
|
||||||
|
1 - La creation du compte LMS participant
|
||||||
|
2 - L'inscription de l'utilisateur à la formation.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if( lms_class_code.strip() != ""):
|
||||||
|
print(" ### Debut creation lms_class_code.strip() pour le code class ", lms_class_code)
|
||||||
|
new_diction = {}
|
||||||
|
new_diction['token'] = diction['token']
|
||||||
|
new_diction['lastname'] = user_nom
|
||||||
|
new_diction['firstname'] = user_prenom
|
||||||
|
new_diction['email'] = myemail
|
||||||
|
new_diction['password'] = secrets.token_urlsafe(6)
|
||||||
|
new_diction['locked'] = "0"
|
||||||
|
new_diction['username'] = myemail
|
||||||
|
|
||||||
|
local_status, local_message, local_participant_lms_id = mys_lms.Create_MySy_LMS_Apprenant(new_diction)
|
||||||
|
|
||||||
|
if( local_status is False ):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) +" WARNING : le compte LSM n'a pas été correctement crée")
|
||||||
|
else:
|
||||||
|
# Mettre à jour la collection "inscription" en ajoutant local_participant_lms_id et et le mot de passe
|
||||||
|
print(" ### Mise à jour 'inscription' pour inscription_line_id = ", inscription_line_id,
|
||||||
|
" local_participant_lms_id = ", local_participant_lms_id, " str(new_diction['password'] ", str(new_diction['password']))
|
||||||
|
local_ret_val = MYSY_GV.dbname['inscription'].find_one_and_update({'_id':ObjectId(str(inscription_line_id))},
|
||||||
|
{"$set":{'lms_class_code':str(local_participant_lms_id),
|
||||||
|
'lms_pwd':str(new_diction['password'])}
|
||||||
|
},
|
||||||
|
upsert=False,
|
||||||
|
return_document=ReturnDocument.AFTER
|
||||||
|
)
|
||||||
|
if (local_ret_val and local_ret_val['_id']):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " Le compte LMS du participant a été correctement mis à jour : local_ret_val['_id'] = "+str( local_ret_val['_id']))
|
||||||
|
""""
|
||||||
|
A present, on va proceder à l'inscription à la formation
|
||||||
|
"""
|
||||||
|
print(" ### Debut de l'inscription au à la formation dans le LMS ")
|
||||||
|
new_diction = {}
|
||||||
|
new_diction['token'] = diction['token']
|
||||||
|
new_diction['user_lms_id'] = local_participant_lms_id
|
||||||
|
new_diction['course_code'] = lms_class_code
|
||||||
|
|
||||||
|
|
||||||
|
local_status2, local_message2 = mys_lms.Add_User_To_LMS_Class(new_diction)
|
||||||
|
if (local_status2 is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " WARNING : Impossbile de finaliser l'incription dans le LMS")
|
||||||
|
else:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " TOP, l'inscription dans le LMS a ete correctement faite")
|
||||||
|
|
||||||
|
else:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - WARNING : Impossible de mettre à jour le compte LMS ")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif ( diction['status'] == "-1" ):
|
elif ( diction['status'] == "-1" ):
|
||||||
# Il s'agit d'envoyer le message de refus d'une inscription
|
# Il s'agit d'envoyer le message de refus d'une inscription
|
||||||
local_status, local_message = email_session.incription_training_refused_mail(email_data)
|
local_status, local_message = email_session.incription_training_refused_mail(email_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mycommon.myprint(" Les données du stagiaire ont été correctement mise à jour")
|
mycommon.myprint(" Les données du stagiaire ont été correctement mise à jour")
|
||||||
return True, "Les données du stagiaire ont été correctement mise à jour"
|
return True, "Les données du stagiaire ont été correctement mise à jour"
|
||||||
|
|
||||||
|
|
1788
Log/log_file.log
1788
Log/log_file.log
File diff suppressed because one or more lines are too long
|
@ -41,13 +41,13 @@ def Add_Update_SessionFormation(diction):
|
||||||
field_list = ['token', 'date_debut', 'date_fin', 'nb_participant', 'formation_session_id', 'adresse',
|
field_list = ['token', 'date_debut', 'date_fin', 'nb_participant', 'formation_session_id', 'adresse',
|
||||||
'code_postal', 'ville', 'formateur', 'code_session',
|
'code_postal', 'ville', 'formateur', 'code_session',
|
||||||
'class_internal_url', 'session_status', 'date_debut_inscription', 'date_fin_inscription',
|
'class_internal_url', 'session_status', 'date_debut_inscription', 'date_fin_inscription',
|
||||||
'attestation_certif', "distantiel", "presentiel", "prix_session", 'contenu_ftion']
|
'attestation_certif', "distantiel", "presentiel", "prix_session", 'contenu_ftion', 'lms_class_code']
|
||||||
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:
|
||||||
mycommon.myprint(str(inspect.stack()[0][
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
3]) + " - Creation partner account : Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
3]) + " - Creation partner account : Le champ '" + val + "' n'est pas autorisé, Creation partenaire annulée")
|
||||||
return False, "Impossible de créer le stagiaire. Toutes les informations fournies ne sont pas valables"
|
return False, "Impossible de créer/mettre à jour la session. Toutes les informations fournies ne sont pas valables"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Verification de la liste des champs obligatoires
|
Verification de la liste des champs obligatoires
|
||||||
|
@ -58,7 +58,7 @@ def Add_Update_SessionFormation(diction):
|
||||||
if val not in diction:
|
if val not in diction:
|
||||||
mycommon.myprint(
|
mycommon.myprint(
|
||||||
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
str(inspect.stack()[0][3]) + " - : La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
return False, "Impossible de créer le stagiaire, Toutes les informations necessaires n'ont pas été fournies"
|
return False, "Impossible de créer/mettre à jour la session, Toutes les informations necessaires n'ont pas été fournies"
|
||||||
|
|
||||||
mydata = {}
|
mydata = {}
|
||||||
query_key = {}
|
query_key = {}
|
||||||
|
@ -82,8 +82,8 @@ def Add_Update_SessionFormation(diction):
|
||||||
|
|
||||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||||
if (partner_recid is False):
|
if (partner_recid is False):
|
||||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de créer la liste d'emargement ")
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de recuperer les données du partenaire ")
|
||||||
return False, "Impossible de créer la liste d'emargement "
|
return False, "Impossible de recuperer les données du partenaire "
|
||||||
|
|
||||||
formation_session_id = ""
|
formation_session_id = ""
|
||||||
if ("formation_session_id" in diction.keys()):
|
if ("formation_session_id" in diction.keys()):
|
||||||
|
@ -106,10 +106,12 @@ def Add_Update_SessionFormation(diction):
|
||||||
if ("presentiel" in diction.keys()):
|
if ("presentiel" in diction.keys()):
|
||||||
mydata['presentiel'] = diction['presentiel']
|
mydata['presentiel'] = diction['presentiel']
|
||||||
|
|
||||||
|
if ("lms_class_code" in diction.keys()):
|
||||||
|
mydata['lms_class_code'] = diction['lms_class_code']
|
||||||
|
|
||||||
if ("nb_participant" in diction.keys()):
|
if ("nb_participant" in diction.keys()):
|
||||||
mydata['nb_participant'] = diction['nb_participant']
|
mydata['nb_participant'] = diction['nb_participant']
|
||||||
|
|
||||||
|
|
||||||
if ("prix_session" in diction.keys()):
|
if ("prix_session" in diction.keys()):
|
||||||
mydata['prix_session'] = diction['prix_session']
|
mydata['prix_session'] = diction['prix_session']
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ from pymongo import ReturnDocument
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Cette fonction créer un utilisateur lms mysy, donc dans chamilo
|
Cette fonction créer un utilisateur (editeur de formation) lms mysy, donc dans chamilo
|
||||||
"""
|
"""
|
||||||
def Create_MySy_LMS_User(diction):
|
def Create_MySy_LMS_User(diction):
|
||||||
try:
|
try:
|
||||||
|
@ -175,6 +175,7 @@ def Create_MySy_LMS_User(diction):
|
||||||
query_compte_exist_exec_val = "0"
|
query_compte_exist_exec_val = "0"
|
||||||
for query_compte_exist_exec in cur:
|
for query_compte_exist_exec in cur:
|
||||||
query_compte_exist_exec_val = query_compte_exist_exec[0]
|
query_compte_exist_exec_val = query_compte_exist_exec[0]
|
||||||
|
if (int(mycommon.tryInt(query_compte_exist_exec_val)) > 0):
|
||||||
new_lms_user_id = query_compte_exist_exec[1]
|
new_lms_user_id = query_compte_exist_exec[1]
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
@ -732,7 +733,6 @@ def Update_Pack_MySy_LMS_User(diction):
|
||||||
|
|
||||||
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
conn = mariadb.connect(
|
conn = mariadb.connect(
|
||||||
user=MYSY_GV.MYSY_MARIADB_USER,
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
@ -797,14 +797,6 @@ def Update_Pack_MySy_LMS_User(diction):
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""" MISE à JOUR DU mysy_nb_formation """
|
""" MISE à JOUR DU mysy_nb_formation """
|
||||||
query_get_mysy_pack_id = "select id from extra_field where variable = '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)
|
#print(" ### query_get_mysy_pack_id = ", query_get_mysy_pack_id)
|
||||||
|
@ -1181,3 +1173,529 @@ def Get_Active_Ftions_Mysy_and_Lms(diction):
|
||||||
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) + " - Line : " + str(exc_tb.tb_lineno))
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||||
return False, False, False, " Impossible de recuperer le nombre de formations actives dans mysy et le lms "
|
return False, False, False, " Impossible de recuperer le nombre de formations actives dans mysy et le lms "
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction permet d'inscrire un utilisateur à une formation.
|
||||||
|
cas d'utilisation :
|
||||||
|
Lorque le formateur valide l'inscription sur Mysy, on va aller inscrire l'utilisateur
|
||||||
|
à la formation
|
||||||
|
"""
|
||||||
|
def Add_User_To_LMS_Class(diction):
|
||||||
|
try:
|
||||||
|
|
||||||
|
# Verification des champs
|
||||||
|
field_list = ['token', 'user_lms_id', 'course_code']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé"
|
||||||
|
|
||||||
|
'''
|
||||||
|
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', 'user_lms_id', 'course_code']
|
||||||
|
|
||||||
|
for val in field_list_obligatoire:
|
||||||
|
if val not in diction:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
return False, str(
|
||||||
|
inspect.stack()[0][3]) + " Toutes les informations obligatoire n'ont pas été fournies"
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
course_code = ""
|
||||||
|
if ("course_code" in diction.keys()):
|
||||||
|
if diction['course_code']:
|
||||||
|
course_code = diction['course_code']
|
||||||
|
|
||||||
|
user_lms_id = ""
|
||||||
|
if ("user_lms_id" in diction.keys()):
|
||||||
|
if diction['user_lms_id']:
|
||||||
|
user_lms_id = diction['user_lms_id']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, str(inspect.stack()[0][3]) + " - Le token n'est pas valide"
|
||||||
|
|
||||||
|
# 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, str(
|
||||||
|
inspect.stack()[0][3]) + " - 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, str(inspect.stack()[0][3]) + " - Le token est vide"
|
||||||
|
|
||||||
|
# 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, " - 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 my_partner['mysy_lms_user_id']:
|
||||||
|
mysy_lms_user_id = my_partner['mysy_lms_user_id']
|
||||||
|
|
||||||
|
|
||||||
|
updated_at = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur2 = conn.cursor()
|
||||||
|
|
||||||
|
""" Verifier si l'utilisateur n'est pas deja inscrit à cette formation """
|
||||||
|
#query = "select count(*) from course_rel_user where user_id = '"+str(user_lms_id)+"' and c_id = '"+str(course_code)+"' "
|
||||||
|
query = "select count(*), b.id from course_rel_user as a left join course as b on a.c_id = b.id where user_id = '"+str(user_lms_id)+"' and b.code = '"+str(course_code)+"'"
|
||||||
|
#print(" ### query_get_mysy_pack_id = ", query)
|
||||||
|
cur.execute(query)
|
||||||
|
|
||||||
|
count_inscription_user = ""
|
||||||
|
count_inscription_user_val = ""
|
||||||
|
|
||||||
|
for count_inscription_user in cur:
|
||||||
|
count_inscription_user_val = count_inscription_user[0]
|
||||||
|
|
||||||
|
if (int(mycommon.tryInt(count_inscription_user_val)) > 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cet utilisateur est déjà inscrit à cette formation")
|
||||||
|
return False, " - Cet utilisateur est déjà inscrit à cette formation"
|
||||||
|
|
||||||
|
""" Verifier que la formation existe et est valide """
|
||||||
|
query = "select count(*), id from course where visibility != '0' and code = '" + str(course_code) + "' "
|
||||||
|
print(" ### query = ", query)
|
||||||
|
cur.execute(query)
|
||||||
|
|
||||||
|
count_course_valide = ""
|
||||||
|
count_course_valide_val = ""
|
||||||
|
course_id = ""
|
||||||
|
|
||||||
|
for count_course_valide in cur:
|
||||||
|
#print(" ### count_course_valide = ", count_course_valide)
|
||||||
|
count_course_valide_val = count_course_valide[0]
|
||||||
|
course_id = count_course_valide[1]
|
||||||
|
|
||||||
|
if (int(mycommon.tryInt(count_course_valide_val)) <= 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cette formation n'est pas valide/active")
|
||||||
|
return False, " - Cette formation n'est pas valide/active"
|
||||||
|
|
||||||
|
if (int(mycommon.tryInt(count_course_valide_val)) < 1):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce code formation correspond à plusieurs formations actives")
|
||||||
|
return False, " - Ce code formation correspond à plusieurs formations actives"
|
||||||
|
|
||||||
|
my_query = " INSERT INTO course_rel_user (user_id, c_id, relation_type, status ) " \
|
||||||
|
" VALUES('"+str(user_lms_id)+"', '"+str(course_id)+"', 0, 5 );"
|
||||||
|
cur2 = conn.cursor()
|
||||||
|
try:
|
||||||
|
print(" ### my_query = ", my_query)
|
||||||
|
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur2.execute(my_query)
|
||||||
|
|
||||||
|
except mariadb.Error as e:
|
||||||
|
# print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS " + str({e}))
|
||||||
|
return False, "Impossible d'inscrire l'utilisateur à la formation " + str({e})
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return True, " 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 d'inscrire l'utilisateur à la formation "
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction permet de desincrire un utilisateur à une formation
|
||||||
|
important : c'est un simple delete qu'il faut faire sur la table "course_rel_user"
|
||||||
|
"""
|
||||||
|
def Remove_User_From_LMS_Class(diction):
|
||||||
|
try:
|
||||||
|
# Verification des champs
|
||||||
|
field_list = ['token', 'user_lms_id', 'course_code']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, False, False, str(inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé"
|
||||||
|
|
||||||
|
'''
|
||||||
|
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', 'user_lms_id', 'course_code']
|
||||||
|
|
||||||
|
for val in field_list_obligatoire:
|
||||||
|
if val not in diction:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
return False, False, False, str(
|
||||||
|
inspect.stack()[0][3]) + " Toutes les informations obligatoire n'ont pas été fournies"
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
course_code = ""
|
||||||
|
if ("course_code" in diction.keys()):
|
||||||
|
if diction['course_code']:
|
||||||
|
course_code = diction['course_code']
|
||||||
|
|
||||||
|
user_lms_id = ""
|
||||||
|
if ("user_lms_id" in diction.keys()):
|
||||||
|
if diction['user_lms_id']:
|
||||||
|
user_lms_id = diction['user_lms_id']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
if retval is False:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Le token n'est pas valide")
|
||||||
|
return False, False, False, str(inspect.stack()[0][3]) + " - Le token n'est pas valide"
|
||||||
|
|
||||||
|
# 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, False, False, str(
|
||||||
|
inspect.stack()[0][3]) + " - 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, False, False, str(inspect.stack()[0][3]) + " - Le token est vide"
|
||||||
|
|
||||||
|
# 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, False, False, " - 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 my_partner['mysy_lms_user_id']:
|
||||||
|
mysy_lms_user_id = my_partner['mysy_lms_user_id']
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
|
||||||
|
""" Verifier si l'utilisateur est deja inscrit à cette formation """
|
||||||
|
query = "select count(*), a.id from course_rel_user as a left join course as b on a.c_id = b.id where user_id = '" + str(
|
||||||
|
user_lms_id) + "' and b.code = '" + str(course_code) + "'"
|
||||||
|
print(" ### query_get_mysy_pack_id = ", query)
|
||||||
|
cur.execute(query)
|
||||||
|
|
||||||
|
count_inscription_user = ""
|
||||||
|
count_inscription_user_val = ""
|
||||||
|
course_rel_user_id = ""
|
||||||
|
|
||||||
|
for count_inscription_user in cur:
|
||||||
|
count_inscription_user_val = count_inscription_user[0]
|
||||||
|
course_rel_user_id = count_inscription_user[1]
|
||||||
|
|
||||||
|
|
||||||
|
if (int(mycommon.tryInt(count_inscription_user_val)) < 0):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Cet utilisateur n'est pas à cette formation")
|
||||||
|
return True, " - Cet utilisateur n'est pas à cette formation"
|
||||||
|
|
||||||
|
my_query = " Delete from course_rel_user WHERE id = '" + str(course_rel_user_id) + "';"
|
||||||
|
cur2 = conn.cursor()
|
||||||
|
try:
|
||||||
|
print(" ### my_query = ", my_query)
|
||||||
|
# cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur2.execute(my_query)
|
||||||
|
|
||||||
|
except mariadb.Error as e:
|
||||||
|
# print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS " + str({e}))
|
||||||
|
return False, "Impossible d'inscrire l'utilisateur à la formation " + str({e})
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
return True, " 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, False, False, " Impossible de desincrire l'utilisateur à la formation "
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction permet de créer un apprenant.
|
||||||
|
use case :
|
||||||
|
Lorsqu'une inscription est validée sur mysy, on va créer le user apprenant
|
||||||
|
:!\ : a ne pas confondre avec la creation d'un utilisateur enseignat """
|
||||||
|
def Create_MySy_LMS_Apprenant(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 = ['token', 'lastname', 'firstname', 'email', 'password', 'locked', 'username']
|
||||||
|
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][
|
||||||
|
3]) + " Le champ '" + val + "' n'est pas autorisé")
|
||||||
|
return False, " Le champ '" + val + "' n'est pas autorisé", False
|
||||||
|
|
||||||
|
'''
|
||||||
|
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', 'lastname', 'firstname', 'email', 'password', 'locked']
|
||||||
|
|
||||||
|
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, " Toutes les informations obligatoire n'ont pas été fournies", False
|
||||||
|
|
||||||
|
# recuperation des paramettre
|
||||||
|
my_token = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
my_token = diction['token']
|
||||||
|
|
||||||
|
partner_recid = ""
|
||||||
|
# Verification de la validité du token/mail dans le cas des user en mode connecté
|
||||||
|
if (len(str(my_token)) > 0):
|
||||||
|
retval = mycommon.check_partner_token_validity("", my_token)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
lastname = ""
|
||||||
|
if ("lastname" in diction.keys()):
|
||||||
|
if diction['lastname']:
|
||||||
|
lastname = diction['lastname']
|
||||||
|
|
||||||
|
firstname = ""
|
||||||
|
if ("firstname" in diction.keys()):
|
||||||
|
if diction['firstname']:
|
||||||
|
firstname = diction['firstname']
|
||||||
|
|
||||||
|
password = ""
|
||||||
|
if ("password" in diction.keys()):
|
||||||
|
if diction['password']:
|
||||||
|
password = diction['password']
|
||||||
|
|
||||||
|
email = ""
|
||||||
|
if ("email" in diction.keys()):
|
||||||
|
if diction['email']:
|
||||||
|
email = diction['email']
|
||||||
|
|
||||||
|
locked = ""
|
||||||
|
if ("locked" in diction.keys()):
|
||||||
|
if diction['email']:
|
||||||
|
locked = diction['locked']
|
||||||
|
|
||||||
|
official_code = ""
|
||||||
|
if ("official_code" in diction.keys()):
|
||||||
|
if diction['official_code']:
|
||||||
|
official_code = diction['official_code']
|
||||||
|
|
||||||
|
username = ""
|
||||||
|
if ("username" in diction.keys()):
|
||||||
|
if diction['username']:
|
||||||
|
username = diction['username']
|
||||||
|
|
||||||
|
registration_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
|
# Rcuperation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
retval = MYSY_GV.dbname['mysy_sequence'].find_one({'related_mysy_object':'lms_user_id', 'valide':'1'})
|
||||||
|
|
||||||
|
|
||||||
|
mypasswd = password.encode('UTF-8')
|
||||||
|
|
||||||
|
salt = bcrypt.gensalt()
|
||||||
|
hashed_pwd = bcrypt.hashpw(mypasswd, salt)
|
||||||
|
|
||||||
|
|
||||||
|
if (type(salt) is bytes):
|
||||||
|
salt = salt.decode("UTF-8")
|
||||||
|
hashed_pwd = hashed_pwd.decode("UTF-8")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (retval is None or "current_val" not in retval.keys()):
|
||||||
|
mycommon.myprint(" Impossible de recuperer la sequence 'mysy_sequence' ")
|
||||||
|
return False, "Impossible de recuperer la sequence 'mysy_sequence'",False
|
||||||
|
|
||||||
|
new_lms_user_id = str(retval['prefixe'])+str(retval['current_val'])
|
||||||
|
local_status, local_val = mycommon.IsInt(new_lms_user_id)
|
||||||
|
if( local_status is False):
|
||||||
|
mycommon.myprint(" Impossible de generer l'ID du user LMS. La valeur actuelle est ", new_lms_user_id)
|
||||||
|
return False, " Impossible de generer l'ID du user LMS", False
|
||||||
|
|
||||||
|
current_seq_value = str(retval['current_val'])
|
||||||
|
|
||||||
|
conn = mariadb.connect(
|
||||||
|
user=MYSY_GV.MYSY_MARIADB_USER,
|
||||||
|
password=MYSY_GV.MYSY_MARIADB_USER_PASS,
|
||||||
|
host=MYSY_GV.MYSY_MARIADB_HOST,
|
||||||
|
port=MYSY_GV.MYSY_MARIADB_PORT,
|
||||||
|
database=MYSY_GV.MYSY_LMS_BDD
|
||||||
|
)
|
||||||
|
cur = conn.cursor()
|
||||||
|
"""
|
||||||
|
# retrieving information
|
||||||
|
cur.execute("SELECT username, email_canonical FROM user WHERE id=?", (2,))
|
||||||
|
|
||||||
|
for username, email_canonical in cur:
|
||||||
|
print(f"username: {username}, email_canonical : {email_canonical}")
|
||||||
|
"""
|
||||||
|
# Verification d'abord si le compte exite.
|
||||||
|
query_compte_exist = " Select count(*), user_id From user WHERE username = '"+username+"' "
|
||||||
|
print(" ### query_compte_exist = ", query_compte_exist)
|
||||||
|
query_compte_exist_exec = cur.execute(query_compte_exist)
|
||||||
|
|
||||||
|
query_compte_exist_exec = ""
|
||||||
|
query_compte_exist_exec_val = "0"
|
||||||
|
for query_compte_exist_exec in cur:
|
||||||
|
query_compte_exist_exec_val = query_compte_exist_exec[0]
|
||||||
|
if (int(mycommon.tryInt(query_compte_exist_exec_val)) > 0):
|
||||||
|
new_lms_user_id = query_compte_exist_exec[1]
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
|
||||||
|
if( int(mycommon.tryInt(query_compte_exist_exec_val)) > 0 ):
|
||||||
|
# Le compte existe, il faut donc faire une mise à jour
|
||||||
|
my_query = "UPDATE user SET salt = '" + str(salt) + "', credentials_expired='0', " \
|
||||||
|
"updated_at='" + str(registration_date) + " ', " \
|
||||||
|
"password = '" + str(
|
||||||
|
hashed_pwd) + "', " \
|
||||||
|
"enabled='1', " \
|
||||||
|
"expired='0', " \
|
||||||
|
"locked = '0', " \
|
||||||
|
"auth_source = 'platform'," \
|
||||||
|
"roles = 'a:0:{}', " \
|
||||||
|
"language = 'french'," \
|
||||||
|
"username_canonical = '" + username + "', " \
|
||||||
|
" email_canonical = '" + email + "', " \
|
||||||
|
"email = '" + email + "'," \
|
||||||
|
" official_code = '" + official_code + "', " \
|
||||||
|
"active = '1' WHERE username='" + str(
|
||||||
|
email) + "' ;"
|
||||||
|
else:
|
||||||
|
# Le compte n'existe pas, il faut le créer
|
||||||
|
|
||||||
|
|
||||||
|
# insert information
|
||||||
|
my_query = "INSERT INTO user SET id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"user_id='"+str(new_lms_user_id)+"' , " \
|
||||||
|
"lastname = '"+lastname+"', " \
|
||||||
|
"firstname = '"+firstname+"', " \
|
||||||
|
"username = '"+username+"', " \
|
||||||
|
"salt = '"+str(salt)+"'," \
|
||||||
|
" registration_date = '"+registration_date+"'," \
|
||||||
|
" credentials_expired='0', " \
|
||||||
|
"enabled='1', " \
|
||||||
|
"expired='0', " \
|
||||||
|
"created_at='" + str( registration_date) + "'," \
|
||||||
|
" updated_at='" + str( registration_date) + "', " \
|
||||||
|
" status = '5', " \
|
||||||
|
"password = '"+str(hashed_pwd)+"', " \
|
||||||
|
"locked = '0', " \
|
||||||
|
"username_canonical = '"+username+"', " \
|
||||||
|
" email_canonical = '"+email+"', " \
|
||||||
|
"email = '"+email+"'," \
|
||||||
|
" official_code = '"+official_code+"', " \
|
||||||
|
"creator_id = '1', " \
|
||||||
|
"auth_source = 'platform'," \
|
||||||
|
"roles = 'a:0:{}', " \
|
||||||
|
"language = 'french'," \
|
||||||
|
"active = '1';"
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(" ### my_query = ", my_query)
|
||||||
|
#cur.execute("INSERT INTO employees (first_name,last_name) VALUES (?, ?)", ("Maria", "DB"))
|
||||||
|
cur.execute(my_query)
|
||||||
|
except mariadb.Error as e:
|
||||||
|
#print(f"Error: {e}")
|
||||||
|
mycommon.myprint(" Impossible de créer l'utilisateur LMS "+str({e}))
|
||||||
|
return False, "Impossible de créer l'utilisateur LMS "+str({e}), False
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
#print(f"Last Inserted ID: {cur.lastrowid}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lastrowid = cur.lastrowid
|
||||||
|
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# Crementation de la sequence de l'objet "lms_user_id" dans la collection : "mysy_sequence"
|
||||||
|
|
||||||
|
#print(" ### current_seq_value = ", current_seq_value)
|
||||||
|
new_sequence_value = int(mycommon.tryInt(current_seq_value))+1
|
||||||
|
|
||||||
|
mydata = {'current_val':new_sequence_value}
|
||||||
|
ret_val2 = MYSY_GV.dbname['mysy_sequence'].find_one_and_update({'related_mysy_object':'lms_user_id', 'valide':'1'},
|
||||||
|
{"$set": mydata},
|
||||||
|
return_document=ReturnDocument.AFTER,
|
||||||
|
upsert= False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
return True, " Creation du compte LMS OK. l'id = "+str(new_lms_user_id), str(new_lms_user_id)
|
||||||
|
|
||||||
|
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", False
|
||||||
|
|
36
main.py
36
main.py
|
@ -2721,6 +2721,42 @@ def strip_update_subscription_plan():
|
||||||
return jsonify(status=localStatus, message=message)
|
return jsonify(status=localStatus, message=message)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API permet d'inscrire un utilisateur à une formation LMS chamilo
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Add_User_To_LMS_Class/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Add_User_To_LMS_Class():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Add_User_To_LMS_Class : payload = ",payload)
|
||||||
|
localStatus, message = mysy_lms.Add_User_To_LMS_Class(payload)
|
||||||
|
return jsonify(status=localStatus, message=message)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API permet de desinscrire un utilisateur à une formation LMS chamilo
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Remove_User_From_LMS_Class/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Remove_User_From_LMS_Class():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Remove_User_From_LMS_Class : payload = ",payload)
|
||||||
|
localStatus, message = mysy_lms.Remove_User_From_LMS_Class(payload)
|
||||||
|
return jsonify(status=localStatus, message=message)
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette API permet de créer un utilisateur apprenant dans le LMS
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/Create_MySy_LMS_Apprenant/', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def Create_MySy_LMS_Apprenant():
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
print(" ### Create_MySy_LMS_Participant : payload = ",payload)
|
||||||
|
localStatus, message, lms_user_id = mysy_lms.Create_MySy_LMS_Apprenant(payload)
|
||||||
|
return jsonify(status=localStatus, message=message, lms_user_id=lms_user_id)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(" debut api")
|
print(" debut api")
|
||||||
|
|
|
@ -56,8 +56,6 @@ def create_order_id():
|
||||||
return secrets.token_urlsafe(3)
|
return secrets.token_urlsafe(3)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_token_urlsafe():
|
def create_token_urlsafe():
|
||||||
return secrets.token_urlsafe(MYSY_GV.TOKEN_SIZE)
|
return secrets.token_urlsafe(MYSY_GV.TOKEN_SIZE)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue