27/07/23 - 17h

master
cherif 2023-07-27 17:14:41 +02:00
parent edf852c265
commit b14bf52d2a
7 changed files with 3045 additions and 13 deletions

View File

@ -1,10 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="25/07/23 - 21h">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="26/07/23 - 23h">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/GlobalVariable.py" beforeDir="false" afterPath="$PROJECT_DIR$/GlobalVariable.py" 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$/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$/partner_client.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_client.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -68,13 +72,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00003" summary="07/04/23 - 11h">
<created>1680858757338</created>
<option name="number" value="00003" />
<option name="presentableId" value="LOCAL-00003" />
<option name="project" value="LOCAL" />
<updated>1680858757338</updated>
</task>
<task id="LOCAL-00004" summary="10/04/23 - 17h">
<created>1681138622687</created>
<option name="number" value="00004" />
@ -411,7 +408,14 @@
<option name="project" value="LOCAL" />
<updated>1690313186731</updated>
</task>
<option name="localTasksCounter" value="52" />
<task id="LOCAL-00052" summary="26/07/23 - 23h">
<created>1690405587653</created>
<option name="number" value="00052" />
<option name="presentableId" value="LOCAL-00052" />
<option name="project" value="LOCAL" />
<updated>1690405587654</updated>
</task>
<option name="localTasksCounter" value="53" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -426,7 +430,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="25/05/23 - 17h" />
<MESSAGE value="28/05/23 - 15h" />
<MESSAGE value="29/0523 - 20h" />
<MESSAGE value="30/05/23 - 22h" />
@ -451,6 +454,7 @@
<MESSAGE value="23/07/2023 - 21h" />
<MESSAGE value="24/07/23 - 17h" />
<MESSAGE value="25/07/23 - 21h" />
<option name="LAST_COMMIT_MESSAGE" value="25/07/23 - 21h" />
<MESSAGE value="26/07/23 - 23h" />
<option name="LAST_COMMIT_MESSAGE" value="26/07/23 - 23h" />
</component>
</project>

View File

@ -264,6 +264,12 @@ Nombre maximum de participants importable par csv
"""
MAX_PARTICIPANT_BY_CSV = 50
"""
Nombre maximum de clients de partner importable par csv
"""
MAX_PARTNER_CLIENT_BY_CSV = 100
"""
Stripe : Nom des produits et prix et la clé de config

View File

@ -1492,6 +1492,7 @@ def AddStagiairetoClass_mass(file=None, Folder=None, diction=None):
status, saved_file = mycommon.Upload_Save_CSV_File(file, Folder)
if (status == False):
mycommon.myprint("Impossible de recuperer correctement le fichier à importer")
return False, "Impossible d'importer la liste des participants, le nom du fichier est incorrect "
#" Lecture du fichier "

File diff suppressed because one or more lines are too long

View File

@ -3510,7 +3510,7 @@ def Push_Class_To_MySy_LMS(diction):
# Verifier si la formation a un code 'LMS', au quel cas, on fait des mises à jour coté LMS
lms_class_code = ""
if ("lms_class_code" in Class_To_Push.keys()):
lms_class_code = Class_To_Push['lms_class_id']
lms_class_code = Class_To_Push['lms_class_code']
update_push = True
@ -3530,6 +3530,7 @@ def Push_Class_To_MySy_LMS(diction):
data_to_push['plus_produit'] = Class_To_Push['plus_produit']
data_to_push['mysy_lms_user_id'] = my_partner['mysy_lms_user_id']
data_to_push['lms_virtualhost_id'] = my_partner['lms_virtualhost_id']
data_to_push['partner_owner_recid'] = Class_To_Push['partner_owner_recid']
query_insert_class = ""
if( update_push is False):
@ -3547,6 +3548,10 @@ def Push_Class_To_MySy_LMS(diction):
"internal_url = '"+str(data_to_push['internal_url'])+"'," \
" visual_code = '"+str( data_to_push['lms_class_code'] )+"';" \
else:
mycommon.myprint(" La mise à jour n'est pas autorisée. lms_class_code " + str(lms_class_code))
return False, " La mise à jour n'est pas autorisée. "
print(" #### query_insert_class = ", query_insert_class)
try:
cur.execute(query_insert_class)
@ -3575,7 +3580,7 @@ def Push_Class_To_MySy_LMS(diction):
conn.commit()
query_course_rel_user = "insert into course_rel_user set user_id='"+ str( data_to_push['mysy_lms_user_id']) +"', c_id='" +str(new_class_id)+ "' , relation_type = '3', status = '3', is_tutor = '3'"
query_course_rel_user = "insert into course_rel_user set user_id='"+ str( data_to_push['mysy_lms_user_id']) +"', c_id='" +str(new_class_id)+ "' , relation_type = '0', status = '1', is_tutor = '0', sort = '1' "
print(" #### query_course_rel_user = ", query_course_rel_user)
try:
@ -3711,6 +3716,31 @@ def Push_Class_To_MySy_LMS(diction):
conn.commit()
# Si la publication se passe bien alors, on met à jour la collection MyClass avec le statut et la date.
data_update = {}
data_update['lms_class_code'] = lms_class_code
data_update['date_update'] = str(datetime.now())
data_cle = {}
data_cle['internal_url'] = str(Class_To_Push['internal_url'])
data_cle['partner_owner_recid'] = str(Class_To_Push['partner_owner_recid'])
data_cle['valide'] = "1"
data_cle['locked'] = "0"
print(" #### data_cle 11 = ", data_cle)
local_ret_val = MYSY_GV.dbname['myclass'].find_one_and_update(data_cle,
{"$set": data_update},
upsert=False,
return_document=ReturnDocument.AFTER
)
if( local_ret_val is None or "_id" not in local_ret_val.keys() ):
mycommon.myprint(
" WARNING : Impossible de mettre à jour le partner_account avec le champs lms_class_code = "+str( lms_class_code) )
return True, " La formation " + str(lms_class_code) + "a été correctement Ajoutée/Mise à jour sur la plateforme de E-Learning"

14
main.py
View File

@ -3251,6 +3251,20 @@ def Add_Partner_Client():
return jsonify(status=localStatus, message=message)
"""
Creation en mass des clients d'un partner
"""
@app.route('/myclass/api/Add_Partner_Client_mass/', methods=['POST','GET'])
@crossdomain(origin='*')
def Add_Partner_Client_mass():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Add_Partner_Client_mass : payload = ",payload)
localStatus, message = partner_client.Add_Partner_Client_mass(payload)
return jsonify(status=localStatus, message=message)
"""
API de mise à jour du client d'un partner
"""

View File

@ -871,3 +871,190 @@ def Get_Given_Partner_Client(diction):
""""
Cette fonction permet d'importer des clients de partner en masse avec un fichier excel
"""
def Add_Partner_Client_mass(file=None, Folder=None, diction=None):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', ]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas, Creation participants annulée")
return False, " Verifier votre API"
'''
Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente,
On controle que les champs obligatoires sont presents dans la liste
'''
field_list_obligatoire = ['token', ]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Verifier votre API, Toutes les informations techniques ne sont pas fournies"
my_token = ""
if ("token" in diction.keys()):
if diction['token']:
my_token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
status, saved_file = mycommon.Upload_Save_CSV_File(file, Folder)
if (status is False):
mycommon.myprint("Impossible de recuperer correctement le fichier à importer")
return False, "Impossible de recuperer correctement le fichier à importer"
df = pd.read_csv(saved_file, encoding='utf8', on_bad_lines='skip', sep=';', encoding_errors='ignore')
# Dictionnaire des champs utilisables
'''
# Verification que les noms des colonne sont bien corrects"
'''
field_list = ['nom', 'raison_sociale', 'email', 'adresse', 'code_postal', 'ville', 'pays', 'siret', 'telephone', 'tva', 'website', 'invoice_adresse',
'invoice_code_postal', 'invoice_email', 'invoice_nom', 'invoice_siret', 'invoice_tva', 'invoice_ville', 'invoice_pays']
# Controle du nombre de lignes dans le fichier.
total_rows = len(df)
if (total_rows > MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV):
mycommon.myprint(
str(inspect.stack()[0][3]) + " Le fichier comporte plus de " + str(
MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV) + " lignes.")
return False, " Le fichier comporte plus de " + str(MYSY_GV.MAX_PARTNER_CLIENT_BY_CSV) + " lignes."
for val in df.columns:
if str(val).lower() not in field_list:
mycommon.myprint(
str(inspect.stack()[0][3]) + " : entete du fichier csv. '" + val + "' n'est pas acceptée")
return False, " Entete du fichier csv. '" + val + "' n'est pas acceptée"
# Verification des champs obligatoires dans le fichier
field_list_obligatoire_file = ['nom', 'email', 'adresse', 'code_postal', 'ville', 'pays', 'telephone', ]
for val in field_list_obligatoire_file:
if val not in df.columns:
mycommon.myprint(
str(inspect.stack()[0][
3]) + " : Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire")
return False, " Le champ '" + val + "' n'est pas présent dans le fichier. Il est obligatoire "
# Traitement des données du fichier
warning_msg = ""
nb_warning_msg = 0
x = range(0, total_rows)
for n in x:
mydata = {}
mydata['nom'] = str(df['nom'].values[n])
mydata['email'] = str(df['email'].values[n])
mydata['adresse'] = str(df['adresse'].values[n])
mydata['code_postal'] = str(df['code_postal'].values[n])
mydata['ville'] = str(df['ville'].values[n])
mydata['pays'] = str(df['pays'].values[n])
mydata['telephone'] = str(df['telephone'].values[n])
mydata['token'] = str(my_token)
raison_sociale = ""
if ("raison_sociale" in df.keys()):
if (str(df['raison_sociale'].values[n])):
raison_sociale = str(df['raison_sociale'].values[n])
mydata['raison_sociale'] = raison_sociale
siret = ""
if ("siret" in df.keys()):
if (str(df['siret'].values[n])):
siret = str(df['siret'].values[n])
mydata['siret'] = siret
tva = ""
if ("tva" in df.keys()):
if (str(df['tva'].values[n])):
tva = str(df['tva'].values[n])
mydata['tva'] = tva
website = ""
if ("website" in df.keys()):
if (str(df['website'].values[n])):
website = str(df['website'].values[n])
mydata['website'] = website
invoice_adresse = ""
if ("invoice_adresse" in df.keys()):
if (str(df['invoice_adresse'].values[n])):
invoice_adresse = str(df['invoice_adresse'].values[n])
mydata['invoice_adresse'] = invoice_adresse
invoice_code_postal = ""
if ("invoice_code_postal" in df.keys()):
if (str(df['invoice_code_postal'].values[n])):
invoice_code_postal = str(df['invoice_code_postal'].values[n])
mydata['invoice_code_postal'] = invoice_code_postal
invoice_email = ""
if ("invoice_email" in df.keys()):
if (str(df['invoice_email'].values[n])):
invoice_email = str(df['invoice_email'].values[n])
mydata['invoice_email'] = invoice_email
invoice_nom = ""
if ("invoice_nom" in df.keys()):
if (str(df['invoice_nom'].values[n])):
invoice_nom = str(df['invoice_nom'].values[n])
mydata['invoice_nom'] = invoice_nom
invoice_siret = ""
if ("invoice_siret" in df.keys()):
if (str(df['invoice_siret'].values[n])):
invoice_siret = str(df['invoice_siret'].values[n])
mydata['invoice_siret'] = invoice_siret
invoice_tva = ""
if ("invoice_tva" in df.keys()):
if (str(df['invoice_tva'].values[n])):
invoice_tva = str(df['invoice_tva'].values[n])
mydata['invoice_tva'] = invoice_tva
invoice_ville = ""
if ("invoice_ville" in df.keys()):
if (str(df['invoice_ville'].values[n])):
invoice_ville = str(df['invoice_ville'].values[n])
mydata['invoice_ville'] = invoice_ville
invoice_pays = ""
if ("invoice_pays" in df.keys()):
if (str(df['invoice_pays'].values[n])):
invoice_pays = str(df['invoice_pays'].values[n])
mydata['invoice_pays'] = invoice_pays
clean_dict = {k: mydata[k] for k in mydata if (str(mydata[k]) != "nan")}
print("#### clean_dict ", clean_dict)
status, retval = Add_Partner_Client( clean_dict)
if (status is False):
warning_msg = warning_msg + " Line "+str(n)+" : "+str(retval)
nb_warning_msg = nb_warning_msg + 1
if( nb_warning_msg > 0 ):
mycommon.myprint(
str(inspect.stack()[0][3]) + "Toutes les lignes ont été correctement traités, sauf : "+str(warning_msg))
return True, "Toutes les lignes ont été correctement traités, sauf : "+str(warning_msg)
return True, " Toutes les lignes ont été correctement traitées"
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'importer les client en masse "