1050 lines
44 KiB
Python
1050 lines
44 KiB
Python
"""
|
|
Ce document permet de gerer les blocs de compétence
|
|
|
|
- code
|
|
- description
|
|
- commentaire
|
|
- Liste des Poles d'activité
|
|
- Liste UE :
|
|
==> A chaque UE on associe la compétence validé
|
|
|
|
|
|
"""
|
|
from operator import itemgetter
|
|
|
|
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
|
|
|
|
"""
|
|
Fonction pour ajouter un bloc de compétence
|
|
"""
|
|
def Add_bloc_competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'description', 'commentaire', 'code',
|
|
'prerequis'
|
|
]
|
|
|
|
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' ]
|
|
|
|
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 de l'activité n'est pas déjà utilisé
|
|
"""
|
|
is_bloc_competence_code_used = MYSY_GV.dbname['bloc_competence'].count_documents({'code':str(diction['code']),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_bloc_competence_code_used != 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le code "+str(diction['code'])+" est déjà utilisé ")
|
|
return False, " Le code "+str(diction['code'])+" est déjà utilisé "
|
|
|
|
|
|
mydata = {}
|
|
|
|
mydata = diction
|
|
del mydata['token']
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
mydata[str(val)] = ""
|
|
|
|
mydata['creation_date'] = str(datetime.now())
|
|
mydata['creation_by'] = str(my_partner['_id'])
|
|
mydata['partner_owner_recid'] = str(my_partner['recid'])
|
|
mydata['valide'] = "1"
|
|
mydata['locked'] = "0"
|
|
mydata['tab_pole_activite'] = []
|
|
mydata['tab_ue'] = []
|
|
|
|
|
|
inserted_id = MYSY_GV.dbname['bloc_competence'].insert_one(mydata).inserted_id
|
|
|
|
if (not inserted_id):
|
|
mycommon.myprint(" Impossible de créer le bloc de compétence (2) ")
|
|
return False, " Impossible de créer le bloc de compétence (2) "
|
|
|
|
return True, " le bloc de compétence 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 le bloc de compétence "
|
|
|
|
|
|
"""
|
|
Fonction de mise à jour un bloc de compétence
|
|
"""
|
|
def Update_bloc_competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'description', 'bloc_competence_id', 'commentaire', 'code',
|
|
'prerequis'
|
|
]
|
|
|
|
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', 'bloc_competence_id', 'code']
|
|
|
|
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 code de compétence n'est pas utilisé par une autre compétence autre que celle ci
|
|
"""
|
|
|
|
is_competence_code_used = MYSY_GV.dbname['bloc_competence'].count_documents({'code': str(diction['code']),
|
|
'valide': '1',
|
|
'_id':{'$ne':ObjectId(str(diction['bloc_competence_id']))},
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])})
|
|
|
|
if (is_competence_code_used != 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le code " + str(diction['code']) + " est déjà utilisé ")
|
|
return False, " Le code " + str(diction['code']) + " est déjà utilisé "
|
|
|
|
|
|
# Verifier que la compétence existe et est valide
|
|
is_valide_bloc_competence_id = MYSY_GV.dbname['bloc_competence'].count_documents({'_id':ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
|
|
if( is_valide_bloc_competence_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'activité est invalide ")
|
|
return False, " L'identifiant de l'activité est invalide "
|
|
|
|
|
|
mydata = {}
|
|
mydata = diction
|
|
del mydata['token']
|
|
|
|
|
|
mydata['update_date'] = str(datetime.now())
|
|
mydata['update_by'] = str(my_partner['_id'])
|
|
|
|
result = MYSY_GV.dbname['bloc_competence'].find_one_and_update(
|
|
{'_id':ObjectId(str(diction['bloc_competence_id'])),
|
|
'partner_owner_recid':str(my_partner['recid'])},
|
|
{"$set": mydata},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le bloc de compétence (2) ")
|
|
return False, " Impossible de mettre à jour le bloc de compétence (2) "
|
|
|
|
|
|
|
|
return True, " le bloc de compétence 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 le bloc de compétence "
|
|
|
|
|
|
"""
|
|
Recuperer la liste des un bloc de compétence d'un partenaire, sans filtres
|
|
"""
|
|
def Get_bloc_competence_no_filter(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'est pas autorisé")
|
|
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
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0'}
|
|
|
|
for New_retVal in MYSY_GV.dbname['bloc_competence'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_retVal
|
|
|
|
|
|
if( "code" not in user.keys() ):
|
|
user["code"] = "--"
|
|
|
|
|
|
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 blocs de compétence "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer les données d'une bloc de compétence donnée
|
|
"""
|
|
def Get_Given_bloc_competence(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',]
|
|
|
|
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
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0', '_id':ObjectId(str(diction['_id']))}
|
|
|
|
for New_retVal in MYSY_GV.dbname['bloc_competence'].find(qry):
|
|
user = New_retVal
|
|
|
|
if( "code" not in user.keys() ):
|
|
user["code"] = "--"
|
|
|
|
tab_pole_activite_with_code = []
|
|
if( "tab_pole_activite" in New_retVal.keys() ):
|
|
for tache_pedago in New_retVal['tab_pole_activite']:
|
|
tache_pedago_data = MYSY_GV.dbname['pole_activite_pedagogique'].find_one({'_id':ObjectId(str(tache_pedago['_id'])), 'valide':'1'}, {'_id':1, 'code':1, 'description':1, })
|
|
|
|
if("rang" in tache_pedago.keys()):
|
|
tache_pedago_data['rang'] = str(tache_pedago['rang'])
|
|
else:
|
|
tache_pedago_data['rang'] = "99"
|
|
|
|
if ("obligatoire" in tache_pedago.keys()):
|
|
tache_pedago_data['obligatoire'] = str(tache_pedago['obligatoire'])
|
|
else:
|
|
tache_pedago_data['obligatoire'] = "0"
|
|
|
|
tab_pole_activite_with_code.append(tache_pedago_data)
|
|
|
|
ss = sorted(tab_pole_activite_with_code, key=itemgetter('rang'))
|
|
|
|
user['tab_pole_activite_with_code'] = tab_pole_activite_with_code
|
|
|
|
tab_ue_competence_with_code = []
|
|
cpt_local_tab_ue_competence = 0
|
|
if ("tab_ue" in New_retVal.keys()):
|
|
for ue_competence in New_retVal['tab_ue']:
|
|
if ("competence_id" in ue_competence.keys() and
|
|
"ue_id" in ue_competence.keys() and
|
|
"mysy_single_field" in ue_competence.keys()):
|
|
|
|
local_competence_data = MYSY_GV.dbname['competence_pedagogique'].find_one(
|
|
{'_id': ObjectId(str(ue_competence['competence_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
local_ue_data = MYSY_GV.dbname['unite_enseignement'].find_one(
|
|
{'_id': ObjectId(str(ue_competence['ue_id'])),
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
local_node = {}
|
|
local_node['id'] = str(cpt_local_tab_ue_competence)
|
|
cpt_local_tab_ue_competence = cpt_local_tab_ue_competence + 1
|
|
|
|
local_node['mysy_single_field'] = str(ue_competence['mysy_single_field'])
|
|
local_node['ue_id'] = str(local_ue_data['_id'])
|
|
local_node['ue_code'] = str(local_ue_data['code'])
|
|
local_node['ue_titre'] = str(local_ue_data['titre'])
|
|
|
|
local_node['competence_id'] = str(local_competence_data['_id'])
|
|
local_node['competence_code'] = str(local_competence_data['code'])
|
|
local_node['competence_description'] = str(local_competence_data['description'])
|
|
|
|
local_node['creation_date'] = str(ue_competence['creation_date'])
|
|
|
|
tab_ue_competence_with_code.append(local_node)
|
|
|
|
|
|
user['tab_ue_competence_with_code'] = tab_ue_competence_with_code
|
|
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
print("user = ", user)
|
|
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 blocs de compétence "
|
|
|
|
|
|
|
|
"""
|
|
Suppression un bloc de compétence
|
|
"""
|
|
def Delete_Given_bloc_competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'bloc_competence_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', 'bloc_competence_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
|
|
|
|
|
|
qry = {'_id':ObjectId(str(diction['bloc_competence_id'])), 'partner_owner_recid':str(my_partner['recid'])}
|
|
|
|
ret_del_competence = MYSY_GV.dbname['bloc_competence'].delete_many(qry)
|
|
|
|
return True, "le bloc de compétence 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 le bloc de compétence "
|
|
|
|
|
|
"""
|
|
Ajouter un pole d'activité pédagogique d'un bloc de compétence
|
|
"""
|
|
def Add_Update_tab_Pole_Activite_To_Bloc_Competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'bloc_competence_id', 'pole_activite_id', 'rang', ]
|
|
|
|
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', 'bloc_competence_id', 'pole_activite_id', 'rang', ]
|
|
|
|
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
|
|
|
|
|
|
|
|
if ("rang" in diction.keys()):
|
|
local_status, local_note_max = mycommon.IsInt(str(diction['rang']).strip())
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
" Le rang doit être un nombre entier ")
|
|
return False, " Le rang doit être un nombre entier"
|
|
|
|
|
|
|
|
"""
|
|
Verifier la validité de bloc_competence_id
|
|
"""
|
|
is_valide_activite = MYSY_GV.dbname['bloc_competence'].count_documents({'_id':ObjectId(diction['bloc_competence_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_activite != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du bloc de compétence est invalide ")
|
|
return False, " L'identifiant du bloc de compétence est invalide "
|
|
|
|
"""
|
|
Verifier la validité de pole_activite_id
|
|
"""
|
|
is_valide_pole = MYSY_GV.dbname['pole_activite_pedagogique'].count_documents({'_id':ObjectId(str(diction['pole_activite_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_pole != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du pôle d'activité "+str(diction['pole_activite_id'])+" est invalide ")
|
|
return False, " L'identifiant du pôle d'activité "+str(diction['pole_activite_id'])+" est invalide "
|
|
|
|
|
|
tab_pole_activite = []
|
|
tab_pole_activite.append(str(diction['pole_activite_id']))
|
|
|
|
|
|
for pole_id in tab_pole_activite:
|
|
|
|
"""
|
|
Si le pole existe dans le bloc de compétence alors on fait un update,
|
|
si non on fait une insertion
|
|
"""
|
|
is_pole_id_existe_in_bloc_competence = MYSY_GV.dbname['bloc_competence'].count_documents({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_pole_activite._id': ObjectId(str(diction['pole_activite_id']))
|
|
})
|
|
|
|
if( is_pole_id_existe_in_bloc_competence == 1):
|
|
print(" OUII existe, donc update")
|
|
update = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_pole_activite._id': ObjectId(str(diction['pole_activite_id']))
|
|
},
|
|
{'$set':
|
|
{
|
|
'tab_pole_activite.$[xxx].rang': str( diction['rang']),
|
|
|
|
'tab_pole_activite.$[xxx].update_date': str( datetime.now()),
|
|
'tab_pole_activite.$[xxx].update_by': str(my_partner['_id']),
|
|
}
|
|
},
|
|
upsert=False,
|
|
array_filters=[
|
|
{"xxx._id": ObjectId(str(pole_id))},
|
|
]
|
|
)
|
|
|
|
elif( is_pole_id_existe_in_bloc_competence == 0):
|
|
print(" NOOO existe, donc insert")
|
|
new_data = {}
|
|
new_data['_id'] = ObjectId(str(pole_id))
|
|
new_data['rang'] = str(diction['rang'])
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['creation_by'] = str(my_partner['_id'])
|
|
new_data['creation_date'] = str(datetime.now())
|
|
new_data['locked'] = "0"
|
|
|
|
|
|
|
|
insert = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
},
|
|
|
|
{
|
|
'$push': {
|
|
"tab_pole_activite": {
|
|
'$each': [new_data]
|
|
}
|
|
}
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return True, " La mise à jour a été correctement faite "
|
|
|
|
|
|
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 faire la mise à jour "
|
|
|
|
|
|
|
|
"""
|
|
Supprimer un pole d'activité pédagogique d'un bloc de compétence
|
|
"""
|
|
def Delete_Pole_Activite_From_Bloc_Competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'bloc_competence_id', 'pole_activite_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', 'bloc_competence_id', 'pole_activite_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 la validité du bloc de compétence
|
|
"""
|
|
is_valide_bloc_compet = MYSY_GV.dbname['bloc_competence'].count_documents({'_id':ObjectId(diction['bloc_competence_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_bloc_compet != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du bloc de compétence est invalide ")
|
|
return False, " L'identifiant du bloc de compétence est invalide "
|
|
|
|
"""
|
|
Verifier la validité de pole_activite_id
|
|
"""
|
|
is_valide_pole = MYSY_GV.dbname['pole_activite_pedagogique'].count_documents({'_id':ObjectId(str(diction['pole_activite_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_pole != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du pôle d'activités "+str(diction['tache_pedagogique_id'])+" est invalide ")
|
|
return False, " L'identifiant du pôle d'activités "+str(diction['tache_pedagogique_id'])+" est invalide "
|
|
|
|
|
|
tab_pole_activite = []
|
|
tab_pole_activite.append(str(diction['pole_activite_id']))
|
|
|
|
|
|
for pole_id in tab_pole_activite:
|
|
|
|
"""
|
|
Si la tache existe dans tab_pole_activite, alors on fait un update,
|
|
si non on fait une insertion
|
|
"""
|
|
is_pole_activite_existe_in_compet = MYSY_GV.dbname['bloc_competence'].count_documents({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_pole_activite._id': ObjectId(str(pole_id))
|
|
})
|
|
|
|
if( is_pole_activite_existe_in_compet == 1):
|
|
print(" OUII existe, donc update")
|
|
update = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_pole_activite._id': ObjectId(str(pole_id))
|
|
},
|
|
{'$pull': {"tab_pole_activite": {"_id": ObjectId(str(pole_id)) }}},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return True, " Le pôle d'activité 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 pôle d'activité "
|
|
|
|
|
|
"""
|
|
Ajouter une liste d'UE à un bloc de competence
|
|
"""
|
|
def Add_Update_tab_UE_And_Competence_To_Bloc_Competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'bloc_competence_id', 'ue_id', 'competence_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', 'bloc_competence_id', 'ue_id', 'competence_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 la validité de bloc_competence_id
|
|
"""
|
|
is_valide_activite = MYSY_GV.dbname['bloc_competence'].count_documents({'_id':ObjectId(diction['bloc_competence_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_activite != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du bloc de compétence est invalide ")
|
|
return False, " L'identifiant du bloc de compétence est invalide "
|
|
|
|
"""
|
|
Verifier la validité d'ue
|
|
"""
|
|
is_valide_ue = MYSY_GV.dbname['unite_enseignement'].count_documents({'_id':ObjectId(str(diction['ue_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_ue != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de l'unité d'enseignement "+str(diction['ue_id'])+" est invalide ")
|
|
return False, " L'identifiant de l'unité d'enseignement "+str(diction['ue_id'])+" est invalide "
|
|
|
|
"""
|
|
Verifier la validité de la compétence
|
|
"""
|
|
is_valide_competence = MYSY_GV.dbname['competence_pedagogique'].count_documents({'_id': ObjectId(str(diction['competence_id'])),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'partner_owner_recid': str(
|
|
my_partner['recid'])})
|
|
|
|
if (is_valide_competence != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la compétence pédagogique " + str(diction['competence_id']) + " est invalide ")
|
|
return False, " L'identifiant de la compétence pédagogique " + str(diction['competence_id']) + " est invalide "
|
|
|
|
|
|
tab_ue = []
|
|
tab_ue.append(str(diction['ue_id']))
|
|
|
|
|
|
for local_eu_id in tab_ue:
|
|
|
|
local_mysy_single_field = str(diction['competence_id']) + "_" + str(local_eu_id)
|
|
"""
|
|
Si local_mysy_single_field existe dans le bloc de compétence alors on fait un update,
|
|
si non on fait une insertion
|
|
"""
|
|
is_mysy_single_field_existe_in_bloc_competence = MYSY_GV.dbname['bloc_competence'].count_documents({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_ue.mysy_single_field': str(local_mysy_single_field)
|
|
})
|
|
|
|
if( is_mysy_single_field_existe_in_bloc_competence == 1):
|
|
print(" OUII existe, donc update")
|
|
update = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_ue.mysy_single_field': str(local_mysy_single_field)
|
|
},
|
|
{'$set':
|
|
{
|
|
'tab_ue.$[xxx].update_date': str( datetime.now()),
|
|
'tab_ue.$[xxx].update_by': str(my_partner['_id']),
|
|
}
|
|
},
|
|
upsert=False,
|
|
array_filters=[
|
|
{"xxx.mysy_single_field": str(local_mysy_single_field)},
|
|
]
|
|
)
|
|
|
|
elif( is_mysy_single_field_existe_in_bloc_competence == 0):
|
|
print(" NOOO existe, donc insert")
|
|
new_data = {}
|
|
|
|
new_data['ue_id'] = str(diction['ue_id'])
|
|
new_data['competence_id'] = str(diction['competence_id'])
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['creation_by'] = str(my_partner['_id'])
|
|
new_data['creation_date'] = str(datetime.now())
|
|
new_data['locked'] = "0"
|
|
new_data['mysy_single_field'] = str(local_mysy_single_field)
|
|
|
|
|
|
|
|
insert = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
|
|
},
|
|
|
|
{
|
|
'$push': {
|
|
"tab_ue": {
|
|
'$each': [new_data]
|
|
}
|
|
}
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return True, " La mise à jour a été correctement faite "
|
|
|
|
|
|
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 faire la mise à jour "
|
|
|
|
|
|
|
|
"""
|
|
Supprimer une liste d'UE à un bloc de competence
|
|
"""
|
|
def Delete_UE_From_Bloc_Competence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'bloc_competence_id', 'mysy_single_field']
|
|
|
|
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', 'bloc_competence_id', 'mysy_single_field']
|
|
|
|
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 la validité du bloc de competence
|
|
"""
|
|
is_valide_bloc_compet = MYSY_GV.dbname['bloc_competence'].count_documents({'_id':ObjectId(diction['bloc_competence_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if( is_valide_bloc_compet != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant du bloc de compétence est invalide ")
|
|
return False, " L'identifiant du bloc de compétence est invalide "
|
|
|
|
|
|
|
|
tab_pole_activite = []
|
|
tab_pole_activite.append(str(diction['mysy_single_field']))
|
|
|
|
|
|
for local_mysy_single_field in tab_pole_activite:
|
|
|
|
"""
|
|
Si la tache existe dans tab_pole_activite, alors on fait un update,
|
|
si non on fait une insertion
|
|
"""
|
|
is_mysy_single_field_existe_in_compet = MYSY_GV.dbname['bloc_competence'].count_documents({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_ue.mysy_single_field': str(diction['mysy_single_field'])
|
|
})
|
|
|
|
if( is_mysy_single_field_existe_in_compet == 1):
|
|
print(" OUII existe, donc update")
|
|
update = MYSY_GV.dbname['bloc_competence'].update_one({'_id': ObjectId(str(diction['bloc_competence_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'tab_ue.mysy_single_field': str(diction['mysy_single_field'])
|
|
},
|
|
{'$pull': {"tab_ue": {"mysy_single_field": str(local_mysy_single_field) }}},
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
return True, " L'Unité d'enseignement 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'unité d'enseignement "
|