898 lines
32 KiB
Python
898 lines
32 KiB
Python
"""
|
||
Ce fichier permet de gerer les notes de apprenants dans le système
|
||
Principe de base :
|
||
• On crée les types de d’évaluation. Par exemple : TD, TP, Projet, Projet_UE (le projet à l’intérieur d’une UE), Stage, Contrôle_Continue etc.
|
||
• Pour chaque UE, créer les évaluations associées. Par exemple certaines UE n’ont pas de TP, donc pas d’évaluation TP,
|
||
• Pour chaque Evaluation d’une EU, on associe une liste de notes.
|
||
|
||
"""
|
||
import bson
|
||
import pymongo
|
||
from pymongo import MongoClient
|
||
import json
|
||
from bson import ObjectId
|
||
import re
|
||
from datetime import datetime
|
||
import prj_common as mycommon
|
||
import secrets
|
||
import inspect
|
||
import sys, os
|
||
import csv
|
||
import pandas as pd
|
||
from pymongo import ReturnDocument
|
||
import GlobalVariable as MYSY_GV
|
||
from math import isnan
|
||
import GlobalVariable as MYSY_GV
|
||
import ela_index_bdd_classes as eibdd
|
||
import email_mgt as email
|
||
import jinja2
|
||
from flask import send_file
|
||
from xhtml2pdf import pisa
|
||
from email.message import EmailMessage
|
||
from email.mime.text import MIMEText
|
||
from email import encoders
|
||
import smtplib
|
||
from email.mime.multipart import MIMEMultipart
|
||
from email.mime.text import MIMEText
|
||
from email.mime.base import MIMEBase
|
||
from email import encoders
|
||
|
||
|
||
|
||
"""
|
||
Ajout d'un type d'evaluation
|
||
"""
|
||
|
||
def Add_Evaluation_Type(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'code', 'nom', 'description']
|
||
|
||
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', 'code', 'nom', ]
|
||
|
||
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 la liste des arguments ")
|
||
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 ce code n'existe pas déjà
|
||
is_existe_type_evaluation = MYSY_GV.dbname['type_evaluation'].count_documents({'code':str(diction['code']),
|
||
'valide':'1',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
|
||
if( is_existe_type_evaluation > 0 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " Un type d'évaluation avec le code '" + str(diction['code']) + "' existe déjà ")
|
||
return False, " Un type d'évaluation avec le code '" + str(diction['code']) + "' existe déjà "
|
||
|
||
|
||
|
||
|
||
new_data = diction
|
||
del diction['token']
|
||
|
||
# Initialisation des champs non envoyés à vide
|
||
for val in field_list:
|
||
if val not in diction.keys():
|
||
new_data[str(val)] = ""
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
|
||
new_data['date_update'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
inserted_id = MYSY_GV.dbname['type_evaluation'].insert_one(new_data).inserted_id
|
||
if (not inserted_id):
|
||
mycommon.myprint(
|
||
" Impossible de créer le type d'évaluation (2) ")
|
||
return False, " Impossible de créer le type d'évaluation (2) "
|
||
|
||
|
||
return True, " Le type d'évaluation a été correctement ajouté"
|
||
|
||
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 type d'évaluation "
|
||
|
||
|
||
"""
|
||
Mise à jour d'un type d'évaluation
|
||
"""
|
||
|
||
def Update_Evaluation_Type(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_id', 'code', 'nom', 'description',]
|
||
|
||
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', '_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 la liste des arguments ")
|
||
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
|
||
|
||
new_data = diction
|
||
|
||
# Verifier que le type d'évaluation
|
||
is_existe_type_evaluation = MYSY_GV.dbname['type_evaluation'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_type_evaluation < 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du type d'évaluation est invalide ")
|
||
return False, " L'identifiant du type d'évaluation est invalide "
|
||
|
||
|
||
|
||
local_id = str(diction['_id'])
|
||
|
||
del diction['token']
|
||
del diction['_id']
|
||
|
||
|
||
new_data['date_update'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['_id'] = ObjectId(local_id)
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
result = MYSY_GV.dbname['type_evaluation'].find_one_and_update(
|
||
data_cle,
|
||
{"$set": new_data},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if ("_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible de mettre à jour le type d'évaluation (2) ")
|
||
return False, " Impossible de mettre à jour le type d'évaluation (2) "
|
||
|
||
return True, " Le type d'évaluation 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 type d'évaluation "
|
||
|
||
|
||
|
||
"""
|
||
Suppression d'un type d'évaluation
|
||
regles :
|
||
|
||
"""
|
||
|
||
def Delete_Type_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_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', '_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 la liste des arguments ")
|
||
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 la codition de paiement existe
|
||
is_existe_type_eval = MYSY_GV.dbname['type_evaluation'].count_documents(
|
||
{'_id': ObjectId(str(diction['_id'])),
|
||
'valide': '1',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (is_existe_type_eval < 0):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du type d'évaluation n'est pas valide ")
|
||
return False, " L'identifiant du type d'évaluation n'est pas valide "
|
||
|
||
|
||
|
||
|
||
|
||
|
||
delete = MYSY_GV.dbname['type_evaluation'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
||
'partner_owner_recid': str(my_partner['recid']),
|
||
}, )
|
||
|
||
|
||
|
||
return True, " Le type d'évaluation a été correctement supprimé"
|
||
|
||
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 supprimer type d'évaluation "
|
||
|
||
|
||
"""
|
||
Recuperer la liste des type d'evaluation d'un partenaire
|
||
"""
|
||
def Get_List_Type_Evaluation(diction):
|
||
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 and val.startswith('my_') is False:
|
||
mycommon.myprint(str(
|
||
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
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 la liste des arguments ")
|
||
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
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['type_evaluation'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer la liste des type d'évaluation "
|
||
|
||
|
||
"""
|
||
Recuperer les données d'un type d'évaluation donné
|
||
"""
|
||
def Get_Given_Type_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', '_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'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', '_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 la liste des arguments ")
|
||
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
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
data_cle['_id'] = ObjectId(str(diction['_id']))
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['type_evaluation'].find(data_cle):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer le types d'évaluation "
|
||
|
||
|
||
"""
|
||
Ajout ou mettre à jour une evaluation à une l'UE d'une formation.
|
||
les champs :
|
||
- class_id,
|
||
- class_ue_id,
|
||
- type_evaluation_id,
|
||
- max_note
|
||
"""
|
||
|
||
def Add_Class_UE_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'class_id', 'class_ue_id', 'type_evaluation_id', 'max_note',
|
||
]
|
||
|
||
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', 'class_id', 'class_ue_id', 'type_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 la liste des arguments ")
|
||
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 class_ue_id est valide
|
||
"""
|
||
is_ue_id_existe_class = MYSY_GV.dbname['myclass'].count_documents({ '_id':ObjectId(str(diction['class_id'])),
|
||
'list_unite_enseignement._id': str(diction['class_ue_id']),
|
||
'partner_owner_recid':my_partner['recid'],
|
||
'valide':'1',
|
||
'locked':'0'})
|
||
|
||
if (is_ue_id_existe_class != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'unité d'enseignement n'existe pas dans la formation ")
|
||
return False, " L'unité d'enseignement n'existe pas dans la formation "
|
||
|
||
|
||
"""
|
||
Verifier que le type d'évaluation existe
|
||
"""
|
||
is_type_eval_existe = MYSY_GV.dbname['type_evaluation'].count_documents({'_id':ObjectId(str(diction['type_evaluation_id'])),
|
||
'partner_owner_recid':my_partner['recid'],
|
||
'valide': '1',
|
||
'locked': '0'
|
||
})
|
||
|
||
if( is_type_eval_existe != 1 ):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant du type de formation est invalide ")
|
||
return False, " L'identifiant du type de formation est invalide "
|
||
|
||
new_data = diction
|
||
del diction['token']
|
||
|
||
# Initialisation des champs non envoyés à vide
|
||
for val in field_list:
|
||
if val not in diction.keys():
|
||
new_data[str(val)] = ""
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
|
||
new_data['date_update'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
inserted_id = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].insert_one(new_data).inserted_id
|
||
if (not inserted_id):
|
||
mycommon.myprint(
|
||
" Impossible de créer l'évaluation pour l'UE (2) ")
|
||
return False, " Impossible de créer l'évaluation pour l'UE (2) "
|
||
|
||
|
||
return True, " L'évaluation a été correctement ajoutée"
|
||
|
||
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 l'évaluation pour l'UE "
|
||
|
||
|
||
"""
|
||
Mise à jour d'une evaluation d'une formation
|
||
"""
|
||
def Update_Class_UE_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'max_note', 'class_ue_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', 'class_ue_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 la liste des arguments ")
|
||
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 class_ue_id est valide
|
||
"""
|
||
is_ue_id_existe_class = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].count_documents({ '_id':ObjectId(str(diction['class_ue_evaluation_id'])),
|
||
'partner_owner_recid':my_partner['recid'],
|
||
'valide': '1',
|
||
'locked': '0'
|
||
})
|
||
|
||
if (is_ue_id_existe_class != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'évaluation est invalide ")
|
||
return False, " L'identifiant de l'évaluation est invalide "
|
||
|
||
|
||
local_class_ue_evaluation_id = diction['class_ue_evaluation_id']
|
||
new_data = diction
|
||
del diction['token']
|
||
del diction['class_ue_evaluation_id']
|
||
|
||
|
||
new_data['valide'] = "1"
|
||
new_data['locked'] = "0"
|
||
|
||
new_data['date_update'] = str(datetime.now())
|
||
new_data['update_by'] = str(my_partner['_id'])
|
||
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
||
|
||
result = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].find_one_and_update(
|
||
{'_id': ObjectId(str(local_class_ue_evaluation_id)),
|
||
'partner_owner_recid': my_partner['recid'],
|
||
'valide': '1',
|
||
'locked': '0'
|
||
},
|
||
{"$set": new_data},
|
||
upsert=False,
|
||
return_document=ReturnDocument.AFTER
|
||
)
|
||
|
||
if ("_id" not in result.keys()):
|
||
mycommon.myprint(
|
||
" Impossible de mettre à jour l'évaluation (2) ")
|
||
return False, " Impossible de mettre à jour l'évaluation (2) "
|
||
|
||
|
||
|
||
return True, " L'évaluation a été correctement mise à 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 l'évaluation "
|
||
|
||
|
||
"""
|
||
Recuperation de la liste des evaluations d'une formation
|
||
"""
|
||
def Get_List_Class_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'class_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'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'class_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 la liste des arguments ")
|
||
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
|
||
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['class_id'] = str(diction['class_id'])
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
|
||
type_evaluation_code = ""
|
||
if( "type_evaluation_id" in retval.keys() and retval['type_evaluation_id']):
|
||
type_evaluation_data = MYSY_GV.dbname['type_evaluation'].find_one({'_id':ObjectId(str(retval['type_evaluation_id'])),
|
||
'valide':'1',
|
||
'locked':'0',
|
||
'partner_owner_recid':str(my_partner['recid'])})
|
||
|
||
if( type_evaluation_data and 'code' in type_evaluation_data.keys() ):
|
||
type_evaluation_code= type_evaluation_data['code']
|
||
|
||
user['type_evaluation_code'] = type_evaluation_code
|
||
|
||
class_ue_code = ""
|
||
if ("class_ue_id" in retval.keys() and retval['class_ue_id']):
|
||
class_ue_data = MYSY_GV.dbname['unite_enseignement'].find_one(
|
||
{'_id': ObjectId(str(retval['class_ue_id'])),
|
||
'valide': '1',
|
||
'locked': '0',
|
||
'partner_owner_recid': str(my_partner['recid'])})
|
||
|
||
if (class_ue_data and 'code' in class_ue_data.keys()):
|
||
class_ue_code = class_ue_data['code']
|
||
|
||
user['class_ue_code'] = class_ue_code
|
||
|
||
|
||
val_tmp = val_tmp + 1
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer la liste des évaluations de la formation "
|
||
|
||
|
||
|
||
"""
|
||
Recuperation de la liste des evaluations d'une UE
|
||
"""
|
||
def Get_List_UE_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'class_ue_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'existe pas")
|
||
return False, " Les informations fournies sont incorrectes",
|
||
|
||
"""
|
||
Verification des champs obligatoires
|
||
"""
|
||
field_list_obligatoire = ['token', 'class_ue_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 la liste des arguments ")
|
||
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
|
||
|
||
|
||
"""
|
||
Clés de mise à jour
|
||
"""
|
||
data_cle = {}
|
||
data_cle['class_ue_id'] = str(diction['class_ue_id'])
|
||
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
||
data_cle['valide'] = "1"
|
||
data_cle['locked'] = "0"
|
||
|
||
|
||
RetObject = []
|
||
val_tmp = 0
|
||
|
||
for retval in MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
||
user = retval
|
||
user['id'] = str(val_tmp)
|
||
val_tmp = val_tmp + 1
|
||
|
||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||
|
||
return True, RetObject
|
||
|
||
|
||
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 récupérer la liste des évaluation de l'UE "
|
||
|
||
|
||
"""
|
||
Suppression d'une evaluation d'une formation.
|
||
|
||
/!\ : les regles ne sont pas encore implément. il faut le faire
|
||
"""
|
||
def Delete_Class_UE_Evaluation(diction):
|
||
try:
|
||
diction = mycommon.strip_dictionary(diction)
|
||
|
||
"""
|
||
Verification des input acceptés
|
||
"""
|
||
field_list = ['token', 'class_ue_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', 'class_ue_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 la liste des arguments ")
|
||
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 class_ue_id est valide
|
||
"""
|
||
is_ue_id_existe_class = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].count_documents({ '_id':ObjectId(str(diction['class_ue_evaluation_id'])),
|
||
'partner_owner_recid':my_partner['recid'],
|
||
'valide': '1',
|
||
'locked': '0'
|
||
})
|
||
|
||
if (is_ue_id_existe_class != 1):
|
||
mycommon.myprint(
|
||
str(inspect.stack()[0][3]) + " L'identifiant de l'évaluation est invalide ")
|
||
return False, " L'identifiant de l'évaluation est invalide "
|
||
|
||
delete = MYSY_GV.dbname['class_unite_enseignement_type_evaluation'].delete_one({ '_id':ObjectId(str(diction['class_ue_evaluation_id'])),
|
||
'partner_owner_recid':my_partner['recid'],
|
||
'valide': '1',
|
||
'locked': '0'
|
||
} )
|
||
|
||
|
||
return True, " La évaluation a été correctement supprimée"
|
||
|
||
|
||
|
||
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 supprimer l'évaluation "
|