25/04/23 - 21h
parent
e240f32c3e
commit
6642c2adbe
|
@ -1,8 +1,13 @@
|
|||
<?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="23/04/23 - 19h">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="24/04/23 - 21h">
|
||||
<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$/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$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
@ -136,7 +141,14 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1682267594180</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="12" />
|
||||
<task id="LOCAL-00012" summary="24/04/23 - 21h">
|
||||
<created>1682362261760</created>
|
||||
<option name="number" value="00012" />
|
||||
<option name="presentableId" value="LOCAL-00012" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1682362261760</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="13" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
|
@ -161,6 +173,7 @@
|
|||
<MESSAGE value="20/04/23 - 20h" />
|
||||
<MESSAGE value="22/04/23 - 19h" />
|
||||
<MESSAGE value="23/04/23 - 19h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="23/04/23 - 19h" />
|
||||
<MESSAGE value="24/04/23 - 21h" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="24/04/23 - 21h" />
|
||||
</component>
|
||||
</project>
|
|
@ -145,7 +145,10 @@ Les formats d'image accepté
|
|||
'''
|
||||
IMG_FORMAT=['jpg', 'jpeg', 'png', 'jpe', 'webp', 'gif']
|
||||
|
||||
|
||||
"""
|
||||
Image au formation PNG UNIQUEMENT
|
||||
"""
|
||||
IMG_PNG_FORMAT=['png']
|
||||
|
||||
'''
|
||||
Sendinblue clea API
|
||||
|
|
1747
Log/log_file.log
1747
Log/log_file.log
File diff suppressed because it is too large
Load Diff
|
@ -1,4 +1,5 @@
|
|||
import pymongo
|
||||
import pysftp
|
||||
import zeep
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
|
@ -2511,9 +2512,227 @@ def Duplicate_LMS_Theme_Design(diction):
|
|||
print(" ### OKK Connection to the SSH Server")
|
||||
client.close()
|
||||
|
||||
"""
|
||||
Mise à jour du compte du partenaire avec le nom du theme.
|
||||
le champ : lms_theme_name
|
||||
"""
|
||||
new_data_theme = {}
|
||||
new_data_theme['lms_theme_name'] = str(new_theme_name).strip()
|
||||
|
||||
ret_val = MYSY_GV.dbname['partnair_account'].find_one_and_update({'recid': str(partner_recid), 'active': '1'},
|
||||
{"$set": new_data_theme},
|
||||
upsert=False,
|
||||
return_document=ReturnDocument.AFTER
|
||||
)
|
||||
|
||||
|
||||
return True, " Le theme a été correctement dupliqué"
|
||||
|
||||
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 dupliquer le theme "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de recuperer et mettre à jour le fichier du logo
|
||||
"""
|
||||
def Lms_Add_Logo_File(file=None, Folder=None, diction=None):
|
||||
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']
|
||||
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, mise à jour logo lms annulée")
|
||||
return False, " Les informations fournies sont incorrecte",
|
||||
|
||||
'''
|
||||
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, " Les informations fournies sont incorrecte",
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
||||
return False, " Les information de connexion sont incorrectes.",
|
||||
|
||||
# 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",
|
||||
|
||||
# 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"
|
||||
|
||||
lms_theme_name = ""
|
||||
if ("lms_theme_name" in my_partner.keys()):
|
||||
if my_partner['lms_theme_name']:
|
||||
lms_theme_name = my_partner['lms_theme_name']
|
||||
|
||||
if( lms_theme_name == ""):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce partenaire n'a pas de theme associé")
|
||||
return False, str(inspect.stack()[0][
|
||||
3]) + " - Ce partenaire n'a pas de theme associé"
|
||||
|
||||
|
||||
status, saved_file = mycommon.Upload_Save_IMG_PNG_File(file, Folder)
|
||||
if (status == False):
|
||||
return False, "Impossible de recuperer le fichier de configuration de l'image"
|
||||
|
||||
|
||||
|
||||
"""
|
||||
A present que le fichier est recuperé, on va deplacer vers le serveur LMS
|
||||
Dans le repertoire : MYSY_GV.MYSY_LMS_BASE_DIRECTORY/str(theme_name)
|
||||
"""
|
||||
cnopts = pysftp.CnOpts()
|
||||
cnopts.hostkeys = None
|
||||
with pysftp.Connection(host=MYSY_GV.MYSY_FTP_HOST, username=MYSY_GV.MYSY_FTP_LOGIN,
|
||||
password=MYSY_GV.MYSY_FTP_PWD, cnopts=cnopts) as session:
|
||||
print("Connection successfully established ... ")
|
||||
localFilePath = saved_file
|
||||
remoteFilePath = str(MYSY_GV.MYSY_LMS_BASE_DIRECTORY)+"web/css/themes/"+str(lms_theme_name)+"/images/header-logo_test.png"
|
||||
|
||||
print(" ### DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(remoteFilePath) + " AVANTTT TRAITEMENT")
|
||||
# Use put method to upload a file
|
||||
session.put(localFilePath, remoteFilePath)
|
||||
# Switch to a remote directory
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(
|
||||
remoteFilePath) + " EST OKKKK")
|
||||
|
||||
return True, " Le logo a été correctement mis à jour"
|
||||
|
||||
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 mettre à jour le logo "
|
||||
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet de recuperer et mettre à jour le fichier du background
|
||||
"""
|
||||
def Lms_Add_BG_File(file=None, Folder=None, diction=None):
|
||||
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']
|
||||
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, mise à jour logo lms annulée")
|
||||
return False, " Les informations fournies sont incorrecte",
|
||||
|
||||
'''
|
||||
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, " Les informations fournies sont incorrecte",
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_token = diction['token']
|
||||
|
||||
|
||||
partner_recid = mycommon.get_parnter_recid_from_token(my_token)
|
||||
if (partner_recid is False):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - partner_recid KO : Impossible d'importer la liste des participants ")
|
||||
return False, " Les information de connexion sont incorrectes.",
|
||||
|
||||
# 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",
|
||||
|
||||
# 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"
|
||||
|
||||
lms_theme_name = ""
|
||||
if ("lms_theme_name" in my_partner.keys()):
|
||||
if my_partner['lms_theme_name']:
|
||||
lms_theme_name = my_partner['lms_theme_name']
|
||||
|
||||
if( lms_theme_name == ""):
|
||||
mycommon.myprint(str(inspect.stack()[0][3]) + " - Ce partenaire n'a pas de theme associé")
|
||||
return False, str(inspect.stack()[0][
|
||||
3]) + " - Ce partenaire n'a pas de theme associé"
|
||||
|
||||
|
||||
status, saved_file = mycommon.Upload_Save_IMG_PNG_File(file, Folder)
|
||||
if (status == False):
|
||||
return False, "Impossible de recuperer le fichier de configuration de l'image"
|
||||
|
||||
|
||||
"""
|
||||
A present que le fichier est recuperé, on va deplacer vers le serveur LMS
|
||||
Dans le repertoire : MYSY_GV.MYSY_LMS_BASE_DIRECTORY/str(theme_name)
|
||||
"""
|
||||
cnopts = pysftp.CnOpts()
|
||||
cnopts.hostkeys = None
|
||||
with pysftp.Connection(host=MYSY_GV.MYSY_FTP_HOST, username=MYSY_GV.MYSY_FTP_LOGIN,
|
||||
password=MYSY_GV.MYSY_FTP_PWD, cnopts=cnopts) as session:
|
||||
print("Connection successfully established ... ")
|
||||
localFilePath = saved_file
|
||||
remoteFilePath = str(MYSY_GV.MYSY_LMS_BASE_DIRECTORY)+"web/css/themes/"+str(lms_theme_name)+"/images/background_test.png"
|
||||
|
||||
print(" ### DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(remoteFilePath) + " AVANTTT TRAITEMENT")
|
||||
# Use put method to upload a file
|
||||
session.put(localFilePath, remoteFilePath)
|
||||
# Switch to a remote directory
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(
|
||||
remoteFilePath) + " EST OKKKK")
|
||||
|
||||
return True, " Le logo a été correctement mis à jour"
|
||||
|
||||
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 mettre à jour le logo "
|
||||
|
||||
|
|
29
main.py
29
main.py
|
@ -2876,8 +2876,37 @@ def Duplicate_LMS_Theme_Design():
|
|||
localStatus, message = mysy_lms.Duplicate_LMS_Theme_Design(payload)
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
"""
|
||||
API de recuperation du logo pour configuration du LMS
|
||||
"""
|
||||
@app.route('/myclass/api/Lms_Add_Logo_File/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Lms_Add_Logo_File():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### Lms_Add_Logo_File : payload = ",payload)
|
||||
if request.method == 'POST':
|
||||
# Create variable for uploaded file
|
||||
f = request.files['File']
|
||||
localStatus, message = mysy_lms.Lms_Add_Logo_File(f, app.config['UPLOAD_FOLDER'], payload)
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
|
||||
"""
|
||||
API de recuperation du background pour configuration du LMS
|
||||
"""
|
||||
@app.route('/myclass/api/Lms_Add_BG_File/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Lms_Add_BG_File():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = request.form.to_dict()
|
||||
print(" ### Lms_Add_BG_File : payload = ",payload)
|
||||
if request.method == 'POST':
|
||||
# Create variable for uploaded file
|
||||
f = request.files['File']
|
||||
localStatus, message = mysy_lms.Lms_Add_BG_File(f, app.config['UPLOAD_FOLDER'], payload)
|
||||
return jsonify(status=localStatus, message=message)
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(" debut api")
|
||||
context = SSL.Context(SSL.SSLv23_METHOD)
|
||||
|
|
|
@ -149,6 +149,45 @@ def Upload_Save_IMG_File(file=None, Folder=None):
|
|||
|
||||
|
||||
|
||||
"""
|
||||
Controle de l'import des images UNIQUEMENT ET EXCLUSIVEMENT PNG
|
||||
les formats acceptés sont : PNG
|
||||
"""
|
||||
def Upload_Save_IMG_PNG_File(file=None, Folder=None):
|
||||
try:
|
||||
basename = os.path.basename(file.filename)
|
||||
basename2 = basename.split(".")
|
||||
|
||||
'''
|
||||
Verification qu'il s'agit bien d'un fichier image (PNG), dont le nom ne comporte pas de "."
|
||||
'''
|
||||
if(len(basename2) != 2 ):
|
||||
myprint(str(inspect.stack()[0][3]) + " - : Le nom du fichier "+str(file.filename)+" est incorret")
|
||||
return False, None
|
||||
|
||||
if( str(basename2[1]).lower() not in MYSY_GV.IMG_PNG_FORMAT):
|
||||
myprint(str(inspect.stack()[0][3]) + " - : le ficier "+str(file.filename)+ ". L'extention '"+str(basename2[1])+"' n'est pas un fichier image. Les extentions autorisées sont :"+str(MYSY_GV.IMG_FORMAT))
|
||||
return False, None
|
||||
|
||||
|
||||
|
||||
timestr = time.strftime("%Y%m%d%H%M%S")
|
||||
new_file_name = str(basename2[0]) + "_" + str(timestr) + "." + str(basename2[1])
|
||||
file.filename = new_file_name
|
||||
file.save(os.path.join(str(Folder), secure_filename(file.filename))) # t
|
||||
|
||||
Global_file_name = "./Data/"+file.filename
|
||||
|
||||
|
||||
|
||||
return True, Global_file_name
|
||||
|
||||
except Exception as e :
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||
return False, None
|
||||
|
||||
|
||||
|
||||
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue