1293 lines
55 KiB
Python
1293 lines
55 KiB
Python
"""
|
|
Ce fichier permet de gerer le suivi pédagogique d'un apprenant
|
|
Un suivi pédagique est defini par par :
|
|
- apprenant_id, (pour le suivi d'un apprenant)
|
|
- employee_id, (pour le suivi d'un autre employe)
|
|
- class_id (pas obligatoire)
|
|
- session_id (pas obligatoire)
|
|
- class_eu_id (pas obligatoire)
|
|
- ressources_humaine_id (l'enseignant qui responsable de ce suivi)
|
|
- date_heure_debut
|
|
- date_heure_fin
|
|
- observation
|
|
- commentaire
|
|
"""
|
|
import ast
|
|
|
|
import bson
|
|
import pymongo
|
|
import xlsxwriter
|
|
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
|
|
import agenda as agenda
|
|
|
|
"""
|
|
Ajout d'un suivi pédagogique
|
|
"""
|
|
def Add_Suivi_Pedagogique(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'apprenant_id', 'class_id', 'session_id', 'class_eu_id', 'responsable_id',
|
|
'date_heure_debut', 'date_heure_fin', 'observation',
|
|
'commentaire', 'employee_id', 'sujet']
|
|
|
|
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', 'apprenant_id', 'responsable_id', 'date_heure_debut', 'date_heure_fin', 'observation' , 'employee_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
|
|
|
|
|
|
"""
|
|
On suit pedagogiquement soit un apprenant, soit un employé. Donc si les deux sont renseigné, le système
|
|
doit mettre une erreur
|
|
"""
|
|
if( diction['apprenant_id'] and diction['employee_id']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Vous devez préciser l'entité qui doit être suivie ")
|
|
return False, " Vous devez préciser l'entité qui doit être suivie "
|
|
|
|
|
|
# Verifier que la formation et l'ue de la formation existe et sont valides
|
|
|
|
if( "class_id" in diction.keys() and "class_eu_id" in diction.keys() and diction['class_id'] and diction['class_eu_id']):
|
|
is_existe_class_and_class_ue = MYSY_GV.dbname['myclass'].count_documents({ '_id':ObjectId(str(diction['class_id'])),
|
|
'list_unite_enseignement._id': str(diction['class_eu_id']),
|
|
'partner_owner_recid':my_partner['recid'],
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
|
|
if( is_existe_class_and_class_ue != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La formation et l'UE ne sont pas cohérents ")
|
|
return False, " La formation et l'UE ne sont pas cohérents "
|
|
|
|
elif ("class_id" in diction.keys() and diction['class_id'] ):
|
|
is_existe_class_and_class_ue = MYSY_GV.dbname['myclass'].count_documents(
|
|
{'_id': ObjectId(str(diction['class_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_existe_class_and_class_ue != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La formation est invalide ")
|
|
return False, " La formation est invalide "
|
|
|
|
local_eu_data = None
|
|
if( "class_eu_id" in diction.keys() and diction['class_eu_id']):
|
|
local_eu_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id': ObjectId(str(diction['class_eu_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
"""
|
|
Verifier que le l'apprenant est valide
|
|
"""
|
|
|
|
cible_evaluation_data = None
|
|
if( diction["apprenant_id"]):
|
|
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents(
|
|
{'_id': ObjectId(str(diction['apprenant_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_apprenant != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant est invalide ")
|
|
return False, " L'identifiant de l'apprenant est invalide "
|
|
|
|
cible_evaluation_data = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'_id': ObjectId(str(diction['apprenant_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
elif( diction["employee_id"]):
|
|
is_valide_employee_id = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(diction['employee_id'])),
|
|
'partner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_employee_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'employé est invalide ")
|
|
return False, " L'identifiant de l'employé est invalide "
|
|
|
|
cible_evaluation_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(diction['employee_id'])),
|
|
'partner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Impossible d'identifier la cible du suivi pédagogique ")
|
|
return False, " Impossible d'identifier la cible du suivi pédagogique "
|
|
|
|
"""
|
|
Verifier que le responsable est valide
|
|
"""
|
|
is_valide_responsable = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(diction['responsable_id'])),
|
|
'partner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_responsable != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du responsable de l'évaluation est invalide ")
|
|
return False, " L'identifiant du responsable de l'évaluation est invalide "
|
|
|
|
is_valide_responsable_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(diction['responsable_id'])),
|
|
'partner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
"""
|
|
Si session_id, verifier la validité de la session
|
|
"""
|
|
if ('session_id' in diction.keys() and diction['session_id']):
|
|
is_valide_session_id = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
})
|
|
|
|
if (is_valide_session_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session (class) est invalide ")
|
|
return False, " L'identifiant de la session (class) est invalide "
|
|
|
|
"""
|
|
Verifier que les date_heure_debut et date_heure_fin sont ok
|
|
"""
|
|
date_heure_debut = str(diction['date_heure_debut']).strip()[0:16]
|
|
local_status = mycommon.CheckisDate_Hours(date_heure_debut)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de début n'est pas au format jj/mm/aaaa hh:mm")
|
|
|
|
return False, " La date de début n'est pas au format jj/mm/aaaa hh:mm"
|
|
|
|
date_heure_fin = str(diction['date_heure_fin']).strip()[0:16]
|
|
local_status = mycommon.CheckisDate_Hours(date_heure_fin)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin n'est pas au format jj/mm/aaaa hh:mm")
|
|
|
|
return False, " La date de fin n'est pas au format jj/mm/aaaa hh:mm"
|
|
|
|
## Verification de la cohérence des dates. Date_du doit <= Date_au
|
|
if (datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M') > datetime.strptime(
|
|
str(date_heure_fin).strip(), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date debut " + str(date_heure_debut) + " est postérieure à la date de fin " + str(date_heure_fin) + " ")
|
|
|
|
return False, " La date debut " + str(date_heure_debut) + " est postérieure à la date de fin " + str(date_heure_fin) + " "
|
|
|
|
|
|
new_data = diction
|
|
my_token = str(diction['token'])
|
|
my_sujet = ""
|
|
|
|
if( "sujet" in diction.keys() ):
|
|
my_sujet = diction['sujet']
|
|
|
|
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['suivi_pedagogique'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le suivi pédagogique (2) ")
|
|
return False, " Impossible de créer le suivi pédagogique (2) "
|
|
|
|
|
|
|
|
"""
|
|
Ajouter le suivi pédagogique dans l'agenda de
|
|
l'apprenant et du responsable
|
|
"""
|
|
if( diction['apprenant_id']):
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "apprenant"
|
|
new_event['related_role'] = "target"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime("%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime("%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['apprenant_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : "+str(is_valide_responsable_data['civilite']) +" "+str(is_valide_responsable_data['prenom'])+" "+str(is_valide_responsable_data['nom'])+" "
|
|
comment = comment+ "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str( cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
|
|
if( local_eu_data and "titre" in local_eu_data.keys() ):
|
|
comment = comment +"\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = ""
|
|
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(inserted_id)
|
|
|
|
|
|
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
if( add_agenda_status is False ):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda de l'apprenant ")
|
|
|
|
elif( diction['employee_id']):
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "ressource_humaine"
|
|
new_event['related_role'] = "target"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['employee_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : " + str(is_valide_responsable_data['civilite']) + " " + str(
|
|
is_valide_responsable_data['prenom']) + " " + str(is_valide_responsable_data['nom']) + " "
|
|
comment = comment + "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str(
|
|
cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
|
|
if (local_eu_data and "titre" in local_eu_data.keys()):
|
|
comment = comment + "\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = ""
|
|
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(inserted_id)
|
|
|
|
print(" ### employee_id agenda = ", new_event)
|
|
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
if (add_agenda_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda de l'apprenant ")
|
|
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "ressource_humaine"
|
|
new_event['related_role'] = "responsable"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime("%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime("%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['responsable_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : " + str(is_valide_responsable_data['civilite']) + " " + str(
|
|
is_valide_responsable_data['prenom']) + " " + str(is_valide_responsable_data['nom']) + " "
|
|
comment = comment + "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str( cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
if( local_eu_data and "titre" in local_eu_data.keys() ):
|
|
comment = comment + "\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = ""
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(inserted_id)
|
|
|
|
print(" ### responsible agenda = ", new_event)
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
|
|
|
|
if (add_agenda_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda du responsable ")
|
|
|
|
return True, " Le suivi pédagoqique 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 suivi pédagogique "
|
|
|
|
|
|
|
|
"""
|
|
Mettre à jour d'un suivi pédagoqique
|
|
"""
|
|
def Update_Suivi_Pedagogique(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'apprenant_id', 'class_id', 'session_id', 'class_eu_id', 'responsable_id',
|
|
'date_heure_debut', 'date_heure_fin', 'observation',
|
|
'commentaire', '_id', 'employee_id', 'sujet']
|
|
|
|
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', 'apprenant_id', 'responsable_id', 'date_heure_debut', 'date_heure_fin',
|
|
'observation', '_id', 'employee_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
|
|
|
|
"""
|
|
On suit pedagogiquement soit un apprenant, soit un employé. Donc si les deux sont renseigné, le système
|
|
doit mettre une erreur
|
|
"""
|
|
if (diction['apprenant_id'] and diction['employee_id']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Vous devez préciser l'entité qui doit être suivie ")
|
|
return False, " Vous devez préciser l'entité qui doit être suivie "
|
|
|
|
"""
|
|
Verifier que le suivi pédagogique exite
|
|
"""
|
|
is_valide_suivi_peda_count = MYSY_GV.dbname['suivi_pedagogique'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_suivi_peda_count != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du suivi pédagogique est invalide ")
|
|
return False, " L'identifiant du suivi pédagogique est invalide "
|
|
|
|
|
|
|
|
# Verifier que la formation et l'ue de la formation existe et sont valides
|
|
if( "class_id" in diction.keys() and "class_eu_id" in diction.keys() ):
|
|
is_existe_class_and_class_ue = MYSY_GV.dbname['myclass'].count_documents({ '_id':ObjectId(str(diction['class_id'])),
|
|
'list_unite_enseignement._id': str(diction['class_eu_id']),
|
|
'partner_owner_recid':my_partner['recid'],
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
|
|
if( is_existe_class_and_class_ue != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La formation et l'UE ne sont pas cohérents ")
|
|
return False, " La formation et l'UE ne sont pas cohérents "
|
|
|
|
elif ("class_id" in diction.keys() ):
|
|
is_existe_class_and_class_ue = MYSY_GV.dbname['myclass'].count_documents(
|
|
{'_id': ObjectId(str(diction['class_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_existe_class_and_class_ue != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La formation est invalide ")
|
|
return False, " La formation est invalide "
|
|
|
|
local_eu_data = None
|
|
if( "class_eu_id" in diction.keys() and diction['class_eu_id']):
|
|
local_eu_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id': ObjectId(str(diction['class_eu_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
"""
|
|
Verifier que le l'apprenant est valide
|
|
"""
|
|
|
|
cible_evaluation_data = None
|
|
|
|
if (diction["apprenant_id"]):
|
|
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents(
|
|
{'_id': ObjectId(str(diction['apprenant_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_apprenant != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant est invalide ")
|
|
return False, " L'identifiant de l'apprenant est invalide "
|
|
|
|
cible_evaluation_data = MYSY_GV.dbname['apprenant'].find_one(
|
|
{'_id': ObjectId(str(diction['apprenant_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
elif (diction["employee_id"]):
|
|
is_valide_employee_id = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(diction['employee_id'])),
|
|
'partner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_employee_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'employé est invalide ")
|
|
return False, " L'identifiant de l'employé est invalide "
|
|
|
|
cible_evaluation_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(diction['employee_id'])),
|
|
'partner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
else:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Impossible d'identifier la cible du suivi pédagogique ")
|
|
return False, " Impossible d'identifier la cible du suivi pédagogique "
|
|
|
|
"""
|
|
Verifier que le responsable est valide
|
|
"""
|
|
is_valide_responsable = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(diction['responsable_id'])),
|
|
'partner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_valide_responsable != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du responsable de l'évaluation est invalide ")
|
|
return False, " L'identifiant du responsable de l'évaluation est invalide "
|
|
|
|
is_valide_responsable_data = MYSY_GV.dbname['ressource_humaine'].find_one(
|
|
{'_id': ObjectId(str(diction['responsable_id'])),
|
|
'partner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
"""
|
|
Si session_id, verifier la validité de la session
|
|
"""
|
|
if ('session_id' in diction.keys() and diction['session_id']):
|
|
is_valide_session_id = MYSY_GV.dbname['session_formation'].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': my_partner[
|
|
'recid'],
|
|
'valide': '1',
|
|
})
|
|
|
|
if (is_valide_session_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session (class) est invalide ")
|
|
return False, " L'identifiant de la session (class) est invalide "
|
|
|
|
"""
|
|
Verifier que les date_heure_debut et date_heure_fin sont ok
|
|
"""
|
|
date_heure_debut = str(diction['date_heure_debut']).strip()[0:16]
|
|
local_status = mycommon.CheckisDate_Hours(date_heure_debut)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de début n'est pas au format jj/mm/aaaa hh:mm")
|
|
|
|
return False, " La date de début n'est pas au format jj/mm/aaaa hh:mm"
|
|
|
|
date_heure_fin = str(diction['date_heure_fin']).strip()[0:16]
|
|
local_status = mycommon.CheckisDate_Hours(date_heure_fin)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin n'est pas au format jj/mm/aaaa hh:mm")
|
|
|
|
return False, " La date de fin n'est pas au format jj/mm/aaaa hh:mm"
|
|
|
|
## Verification de la cohérence des dates. Date_du doit <= Date_au
|
|
if (datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M') > datetime.strptime(
|
|
str(date_heure_fin).strip(), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La date debut " + str(date_heure_debut) + " est postérieure à la date de fin " + str(date_heure_fin) + " ")
|
|
|
|
return False, " La date debut " + str(date_heure_debut) + " est postérieure à la date de fin " + str(date_heure_fin) + " "
|
|
|
|
|
|
local_suivi_peda_id = diction['_id']
|
|
my_token = diction['token']
|
|
|
|
my_sujet = ""
|
|
if( "sujet" in diction.keys() ):
|
|
my_sujet = diction['sujet']
|
|
|
|
|
|
new_data = diction
|
|
del diction['token']
|
|
del diction['_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['suivi_pedagogique'].find_one_and_update(
|
|
{'_id': ObjectId(str(local_suivi_peda_id)),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'
|
|
},
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
|
|
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le suivi pédagogique (2) ")
|
|
return False, " Impossible de mettre à jour le suivi pédagogique (2) "
|
|
|
|
"""
|
|
Ajouter le suivi pédagogique dans l'agenda de
|
|
l'apprenant et du responsable
|
|
"""
|
|
|
|
if (diction['apprenant_id']):
|
|
event_to_update = MYSY_GV.dbname['agenda'].find_one({
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'related_collection':'apprenant',
|
|
'related_role':'target',
|
|
'linked_collection':'suivi_pedagogique',
|
|
'linked_collection_recid':str(local_suivi_peda_id)})
|
|
|
|
|
|
|
|
if( event_to_update ):
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "apprenant"
|
|
new_event['related_role'] = "target"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['apprenant_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : " + str(is_valide_responsable_data['civilite']) + " " + str(
|
|
is_valide_responsable_data['prenom']) + " " + str(is_valide_responsable_data['nom']) + " "
|
|
comment = comment + "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str(
|
|
cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
|
|
if( local_eu_data and "titre" in local_eu_data.keys() ):
|
|
comment = comment + "\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = str(event_to_update['_id'])
|
|
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(local_suivi_peda_id)
|
|
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
if (add_agenda_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda de l'apprenant ")
|
|
|
|
elif (diction['employee_id']):
|
|
event_to_update = MYSY_GV.dbname['agenda'].find_one({
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'related_collection': 'ressource_humaine',
|
|
'related_role': 'target',
|
|
'linked_collection': 'suivi_pedagogique',
|
|
'linked_collection_recid': str(local_suivi_peda_id)})
|
|
|
|
if (event_to_update):
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "ressource_humaine"
|
|
new_event['related_role'] = "target"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['employee_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : " + str(is_valide_responsable_data['civilite']) + " " + str(
|
|
is_valide_responsable_data['prenom']) + " " + str(is_valide_responsable_data['nom']) + " "
|
|
comment = comment + "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str(
|
|
cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
|
|
if (local_eu_data and "titre" in local_eu_data.keys()):
|
|
comment = comment + "\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = str(event_to_update['_id'])
|
|
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(local_suivi_peda_id)
|
|
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
if (add_agenda_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda de l'apprenant ")
|
|
|
|
|
|
|
|
event_to_update = MYSY_GV.dbname['agenda'].find_one({
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'related_role': 'responsable',
|
|
'related_collection': 'ressource_humaine',
|
|
'linked_collection': 'suivi_pedagogique',
|
|
'linked_collection_recid': str(local_suivi_peda_id)})
|
|
|
|
print({
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'related_role': 'responsable',
|
|
'related_collection': 'ressource_humaine',
|
|
'linked_collection': 'suivi_pedagogique',
|
|
'linked_collection_recid': str(local_suivi_peda_id)})
|
|
|
|
|
|
if (event_to_update):
|
|
new_event = {}
|
|
new_event['token'] = str(my_token)
|
|
new_event['related_collection'] = "ressource_humaine"
|
|
new_event['related_role'] = "responsable"
|
|
new_event['event_title'] = "Suivi Pédagogique "+str(my_sujet)
|
|
new_event['event_start'] = datetime.strptime(str(date_heure_debut).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['event_end'] = datetime.strptime(str(date_heure_fin).strip(), '%d/%m/%Y %H:%M').strftime(
|
|
"%Y-%m-%dT%H:%M")
|
|
new_event['related_collection_recid'] = str(diction['responsable_id'])
|
|
new_event['event_type'] = "autre"
|
|
|
|
comment = " Responsable : " + str(is_valide_responsable_data['civilite']) + " " + str(
|
|
is_valide_responsable_data['prenom']) + " " + str(is_valide_responsable_data['nom']) + " "
|
|
comment = comment + "\n Pour : " + str(cible_evaluation_data['civilite']) + " " + str(
|
|
cible_evaluation_data['prenom']) + " " + str(cible_evaluation_data['nom']) + " \n "
|
|
|
|
if( local_eu_data and "titre" in local_eu_data.keys() ):
|
|
comment = comment + "\n Unite Enseignement : " + str(local_eu_data['titre'])
|
|
|
|
new_event['comment'] = comment
|
|
new_event['_id'] = str(event_to_update['_id'])
|
|
new_event['linked_collection'] = "suivi_pedagogique"
|
|
new_event['linked_collection_recid'] = str(local_suivi_peda_id)
|
|
|
|
print(" ### new_event update repon = ", new_event)
|
|
|
|
add_agenda_status, add_agenda_retval = agenda.Add_Update_Agenda_Event(new_event)
|
|
|
|
if (add_agenda_status is False):
|
|
mycommon.myprint(
|
|
" WARNING : Impossible d'ajouter la suivi pédagogique dans l'agenda du responsable ")
|
|
|
|
|
|
|
|
return True, " Le suivi pédagogique 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 suivi pédagogique "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des suivis pédagoqiques d'un apprenant
|
|
"""
|
|
|
|
def Get_List_Suivi_Pedagogique_No_Filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'apprenant_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', 'apprenant_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 le l'apprenant est valide
|
|
"""
|
|
|
|
|
|
is_valide_apprenant = MYSY_GV.dbname['apprenant'].count_documents(
|
|
{'_id': ObjectId(str(diction['apprenant_id'])),
|
|
'partner_owner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
|
|
if (is_valide_apprenant != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'apprenant est invalide ")
|
|
return False, " L'identifiant de l'apprenant est invalide "
|
|
|
|
|
|
"""
|
|
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['apprenant_id'] = str(diction['apprenant_id'])
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['suivi_pedagogique'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Recuperer l'internal url de la formation
|
|
class_title = ""
|
|
if ("class_id" in retval.keys() and retval['class_id']):
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'_id': ObjectId(str(retval['class_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'title': 1})
|
|
|
|
if (class_data and 'title' in class_data.keys()):
|
|
class_title = class_data['title']
|
|
|
|
user['class_title'] = str(class_title)
|
|
|
|
# Recuperer session_code
|
|
session_code = ""
|
|
if ("session_id" in retval.keys() and retval['session_id']):
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(retval['session_id'])),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])},
|
|
{'code_session': 1})
|
|
|
|
if (session_data and 'code_session' in session_data.keys()):
|
|
session_code = session_data['code_session']
|
|
user['session_code'] = str(session_code)
|
|
|
|
# Recuperer ue_code
|
|
ue_code = ""
|
|
ue_titre = ""
|
|
if ("class_eu_id" in retval.keys() and retval['class_eu_id']):
|
|
unite_enseignement_data = MYSY_GV.dbname['unite_enseignement'].find_one(
|
|
{'_id': ObjectId(str(retval['class_eu_id'])),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])},
|
|
{'code': 1, 'titre': 1})
|
|
|
|
|
|
|
|
if (unite_enseignement_data and 'code' in unite_enseignement_data.keys()):
|
|
ue_code = unite_enseignement_data['code']
|
|
|
|
if (unite_enseignement_data and 'titre' in unite_enseignement_data.keys()):
|
|
ue_titre = unite_enseignement_data['titre']
|
|
|
|
user['ue_code'] = str(ue_code)
|
|
user['ue_titre'] = str(ue_titre)
|
|
|
|
if ("sujet" not in user.keys()):
|
|
user['sujet'] = ""
|
|
|
|
|
|
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 suivis pédagogique "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation de la liste des suivis pédagoqiques d'un employee
|
|
"""
|
|
def Get_List_Employee_Suivi_Pedagogique_No_Filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'employee_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', 'employee_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 le l'apprenant est valide
|
|
"""
|
|
|
|
|
|
is_valide_employee = MYSY_GV.dbname['ressource_humaine'].count_documents(
|
|
{'_id': ObjectId(str(diction['employee_id'])),
|
|
'partner_recid': my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
|
|
if (is_valide_employee != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'employé est invalide ")
|
|
return False, " L'identifiant de l'employé est invalide "
|
|
|
|
|
|
"""
|
|
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['employee_id'] = str(diction['employee_id'])
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
for retval in MYSY_GV.dbname['suivi_pedagogique'].find(data_cle).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Recuperer l'internal url de la formation
|
|
class_title = ""
|
|
if ("class_id" in retval.keys() and retval['class_id']):
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'_id': ObjectId(str(retval['class_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'title': 1})
|
|
|
|
if (class_data and 'title' in class_data.keys()):
|
|
class_title = class_data['title']
|
|
|
|
user['class_title'] = str(class_title)
|
|
|
|
# Recuperer session_code
|
|
session_code = ""
|
|
if ("session_id" in retval.keys() and retval['session_id']):
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(retval['session_id'])),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])},
|
|
{'code_session': 1})
|
|
|
|
if (session_data and 'code_session' in session_data.keys()):
|
|
session_code = session_data['code_session']
|
|
user['session_code'] = str(session_code)
|
|
|
|
# Recuperer ue_code
|
|
ue_code = ""
|
|
ue_titre = ""
|
|
if ("class_eu_id" in retval.keys() and retval['class_eu_id']):
|
|
unite_enseignement_data = MYSY_GV.dbname['unite_enseignement'].find_one(
|
|
{'_id': ObjectId(str(retval['class_eu_id'])),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])},
|
|
{'code': 1, 'titre': 1})
|
|
|
|
|
|
|
|
if (unite_enseignement_data and 'code' in unite_enseignement_data.keys()):
|
|
ue_code = unite_enseignement_data['code']
|
|
|
|
if (unite_enseignement_data and 'titre' in unite_enseignement_data.keys()):
|
|
ue_titre = unite_enseignement_data['titre']
|
|
|
|
user['ue_code'] = str(ue_code)
|
|
user['ue_titre'] = str(ue_titre)
|
|
|
|
if("sujet" not in user.keys() ):
|
|
user['sujet'] = ""
|
|
|
|
|
|
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 suivis pédagogique "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Recuperer les données d'un Suivi Pedagogique
|
|
"""
|
|
def Get_Given_Suivi_Pedagogique(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['suivi_pedagogique'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
# Recuperer l'internal url de la formation
|
|
class_title = ""
|
|
class_internal_url = ""
|
|
if("class_id" in retval.keys() and retval['class_id']):
|
|
class_data = MYSY_GV.dbname['myclass'].find_one({'_id':ObjectId(str(retval['class_id'])),
|
|
'partner_owner_recid':str(my_partner['recid'])}, {'title':1})
|
|
|
|
if( class_data and 'title' in class_data.keys() ):
|
|
class_title = class_data['title']
|
|
|
|
if (class_data and 'internal_url' in class_data.keys()):
|
|
class_internal_url = class_data['internal_url']
|
|
|
|
user['class_title'] = str(class_title)
|
|
user['class_internal_url'] = str(class_internal_url)
|
|
|
|
# Recuperer session_code
|
|
session_code = ""
|
|
if("session_id" in retval.keys() and retval['session_id']):
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one({'_id': ObjectId(str(retval['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'code_session': 1})
|
|
|
|
if (session_data and 'code_session' in class_data.keys()):
|
|
session_code = session_data['code_session']
|
|
user['session_code'] = str(session_code)
|
|
|
|
# Recuperer ue_code
|
|
ue_code = ""
|
|
ue_titre = ""
|
|
if ("class_eu_id" in retval.keys() and retval['class_eu_id']):
|
|
unite_enseignement_data = MYSY_GV.dbname['unite_enseignement'].find_one({'_id': ObjectId(str(retval['class_eu_id'])),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])},
|
|
{'code': 1, 'titre':1})
|
|
|
|
if (unite_enseignement_data and 'code' in class_data.keys()):
|
|
ue_code = unite_enseignement_data['code']
|
|
|
|
if (unite_enseignement_data and 'ue_titre' in class_data.keys()):
|
|
ue_titre = unite_enseignement_data['titre']
|
|
|
|
user['ue_code'] = str(ue_code)
|
|
user['ue_titre'] = str(ue_titre)
|
|
|
|
if ("sujet" not in user.keys()):
|
|
user['sujet'] = ""
|
|
|
|
|
|
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 les données du suivi pédagogique "
|
|
|
|
|
|
"""
|
|
Supprimer un suivi pédagogique
|
|
|
|
"""
|
|
def Delete_Suivi_Pedagogique(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 class_ue_id est valide
|
|
"""
|
|
is_suivi_peda_exist_count = MYSY_GV.dbname['suivi_pedagogique'].count_documents({ '_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'
|
|
})
|
|
|
|
if (is_suivi_peda_exist_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du suivi pédagoqique est invalide ")
|
|
return False, " L'identifiant du suivi pédagoqique est invalide "
|
|
|
|
|
|
|
|
delete = MYSY_GV.dbname['suivi_pedagogique'].delete_one({ '_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':my_partner['recid'],
|
|
'valide': '1',
|
|
'locked': '0'
|
|
} )
|
|
|
|
|
|
|
|
return True, " Le suivi pédagogique 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 le suivi pédagogique "
|
|
|