20/05/2024 - 14h00

master
cherif 2024-05-20 13:56:31 +02:00
parent 52fcecb308
commit 94408efd1c
4 changed files with 4158 additions and 14 deletions

View File

@ -1,13 +1,11 @@
<?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="18/05/2024 - 22h30">
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="19/05/2024 - 22h15">
<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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/note_evaluation_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/note_evaluation_mgt.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/unite_enseignement_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/unite_enseignement_mgt.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -77,13 +75,6 @@
<option name="presentableId" value="Default" />
<updated>1680804787304</updated>
</task>
<task id="LOCAL-00257" summary="04/04/24 - 21h30">
<created>1712258561441</created>
<option name="number" value="00257" />
<option name="presentableId" value="LOCAL-00257" />
<option name="project" value="LOCAL" />
<updated>1712258561443</updated>
</task>
<task id="LOCAL-00258" summary="06/04/2024 - 21h19">
<created>1712431177613</created>
<option name="number" value="00258" />
@ -420,7 +411,14 @@
<option name="project" value="LOCAL" />
<updated>1716064737343</updated>
</task>
<option name="localTasksCounter" value="306" />
<task id="LOCAL-00306" summary="19/05/2024 - 22h15">
<created>1716149736394</created>
<option name="number" value="00306" />
<option name="presentableId" value="LOCAL-00306" />
<option name="project" value="LOCAL" />
<updated>1716149736394</updated>
</task>
<option name="localTasksCounter" value="307" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -462,7 +460,6 @@
</option>
</component>
<component name="VcsManagerConfiguration">
<MESSAGE value="28/04/2024 - 22h" />
<MESSAGE value="02/05/2024 - 22h" />
<MESSAGE value="sss" />
<MESSAGE value="vvvv" />
@ -487,6 +484,7 @@
<MESSAGE value="17/05/2024 - 21h30" />
<MESSAGE value="sdf" />
<MESSAGE value="18/05/2024 - 22h30" />
<option name="LAST_COMMIT_MESSAGE" value="18/05/2024 - 22h30" />
<MESSAGE value="19/05/2024 - 22h15" />
<option name="LAST_COMMIT_MESSAGE" value="19/05/2024 - 22h15" />
</component>
</project>

File diff suppressed because it is too large Load Diff

24
main.py
View File

@ -9525,6 +9525,30 @@ def Get_List_Participant_To_Evaluation():
"""
API pour exporter les notes d'une évaluation
"""
@app.route('/myclass/api/Export_To_Excel_List_Participant_To_Evaluation/<token>/<evaluation_id>/', methods=['POST','GET'])
@crossdomain(origin='*')
def Export_To_Excel_List_Participant_To_Evaluation(token, evaluation_id):
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
payload = {}
payload['token'] = str(token)
payload['evaluation_id'] = str(evaluation_id)
print(" ### Export_To_Excel_List_Participant_To_Evaluation payload = ",payload)
status, retval = note_evaluation_mgt.Export_To_Excel_List_Participant_To_Evaluation(payload)
if(status ):
return retval
else:
return False
if __name__ == '__main__':
print(" debut api")
context = SSL.Context(SSL.SSLv23_METHOD)

View File

@ -18,6 +18,7 @@ import ast
import bson
import pymongo
import xlsxwriter
from pymongo import MongoClient
import json
from bson import ObjectId
@ -1147,7 +1148,7 @@ def Update_Participant_Evaluation_Note(diction):
for val in JSON_tab_participant_note:
if( '_id' in val.keys() and val['_id'] ):
print(" #### VAL = ", val)
#print(" #### VAL = ", val)
new_data = {}
if("note" in val.keys() ):
new_data['note'] = str(val['note'])
@ -1282,3 +1283,227 @@ def Get_List_Participant_To_Evaluation(diction):
"""
Fonction qui permet d'exporter les notes dans un fichier excel
"""
def Export_To_Excel_List_Participant_To_Evaluation(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'evaluation_id', ]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes"
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', 'evaluation_id', ]
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 incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
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
"""
Verifier que l'evaluation est valide
"""
is_evaluation_valide = MYSY_GV.dbname['note_evaluation'].count_documents(
{"_id": ObjectId(str(diction['evaluation_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
if (is_evaluation_valide != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " L'identifiant de l'évaluation n'est pas valide ")
return False, " L'identifiant de l'évaluation n'est pas valide "
evaluation_data = MYSY_GV.dbname['note_evaluation'].find_one(
{"_id": ObjectId(str(diction['evaluation_id'])),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
RetObject = []
val_tmp = 0
ts = datetime.now().timestamp()
ts = str(ts).replace(".", "").replace(",", "")[-5:]
orig_file_name = "Export_Reponse_" + str(ts) + ".xlsx"
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
tab_exported_fields_header = ["formation", "classe", "evaluation_code","evaluation_titre",
"evaluation_eval_date_heure_debut", "evaluation_eval_date_heure_fin", "nom_apprenant",
"prenom_apprenant", "email_apprenant", "evaluation_note",]
# Create a workbook and add a worksheet.
workbook = xlsxwriter.Workbook(outputFilename)
worksheet = workbook.add_worksheet()
nb_val = 0
row = 0
column = 0
evaluation_formation = ""
evaluation_code_session = ""
# Recuperer les données de la formation
qry_class = {'_id': ObjectId(str(evaluation_data['class_id'])),
'valide': '1', 'locked': '0',
'partner_owner_recid': str(my_partner['recid'])}
class_data = MYSY_GV.dbname['myclass'].find_one({'_id': ObjectId(str(evaluation_data['class_id'])),
'valide': '1', 'locked': '0',
'partner_owner_recid': str(my_partner['recid'])})
if (class_data and "title" in class_data.keys()):
evaluation_formation = class_data['title']
# Recuperation des données de la session
session_data = MYSY_GV.dbname['session_formation'].find_one(
{'_id': ObjectId(str(evaluation_data['session_id'])),
'valide': '1',
'partner_owner_recid': str(my_partner['recid'])})
if (session_data and "code_session" in session_data.keys()):
evaluation_code_session = session_data['code_session']
"""
Creation de l'entete du fichier excel
"""
for header_item in tab_exported_fields_header:
worksheet.write(row, column, header_item)
column += 1
"""
Creation des data du fichier excel
"""
for retval in MYSY_GV.dbname['note_evaluation_participant'].find(
{'evaluation_id': str(diction['evaluation_id']),
'valide': '1',
'locked': '0',
'partner_owner_recid': str(my_partner['recid']),
}):
user = retval
nom_apprenant = ""
prenom_apprenant = ""
email_apprenant = ""
groupe = ""
if ("inscription_id" in retval and retval['inscription_id']):
# Recuprer les données de l'inscrit
inscription_data = MYSY_GV.dbname['inscription'].find_one(
{'_id': ObjectId(str(retval['inscription_id']))},
{'_id': 1, 'apprenant_id': 1})
apprenant_data = MYSY_GV.dbname['apprenant'].find_one(
{'_id': ObjectId(str(inscription_data['apprenant_id']))},
{'_id': 1, 'nom': 1, 'prenom': 1, 'email': 1})
nom_apprenant = apprenant_data['nom']
prenom_apprenant = apprenant_data['prenom']
email_apprenant = apprenant_data['email']
user['nom'] = nom_apprenant
user['prenom'] = prenom_apprenant
user['email'] = email_apprenant
user['id'] = str(nb_val)
if ("note" not in retval.keys()):
user['note'] = "-1"
nb_val = nb_val + 1
column = 0
row = row + 1
# Champ : formation
worksheet.write(row, column, evaluation_formation)
column += 1
# Champ : classe / evaluation_code_session
worksheet.write(row, column, evaluation_code_session)
column += 1
# Champ : evaluation_code
worksheet.write(row, column, str(evaluation_data['code']))
column += 1
# Champ : evaluation_titre
worksheet.write(row, column, str(evaluation_data['titre']))
column += 1
# Champ : evaluation_eval_date_heure_debut
worksheet.write(row, column, str(evaluation_data['eval_date_heure_debut']))
column += 1
# Champ : evaluation_eval_date_heure_fin
worksheet.write(row, column, str(evaluation_data['eval_date_heure_fin']))
column += 1
# Champ : nom
worksheet.write(row, column, user['nom'])
column += 1
# Champ : prenom
worksheet.write(row, column, user['prenom'])
column += 1
# Champ : email
worksheet.write(row, column, user['email'])
column += 1
# Champ : note
worksheet.write(row, column, user['note'])
column += 1
workbook.close()
if os.path.exists(outputFilename):
# print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
return True, send_file(outputFilename, as_attachment=True)
return False, "Impossible de générer l'export (2) "
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 générer l'export "