429 lines
14 KiB
Python
429 lines
14 KiB
Python
"""
|
|
Ce document permet de gerer les bulletin de note créer
|
|
- Recuperation liste bulletin note
|
|
- publication / Depublication ENT
|
|
|
|
Un bulletin de note est definit par
|
|
- inscription_id,
|
|
- class_id,
|
|
- session_id,
|
|
- tab_semestre,
|
|
- diplome_id
|
|
"""
|
|
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
|
|
|
|
|
|
"""
|
|
Recuperer la liste de bulletin de note d'un inscrit
|
|
"""
|
|
def Get_Bulletin_Note_Inscrit(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'inscription_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', 'inscription_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
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0',
|
|
'object_owner_collection':'inscription',
|
|
'object_owner_id':str(diction['inscription_id']),
|
|
'type_document':'bulletin'}
|
|
|
|
for New_retVal in MYSY_GV.dbname['download_files'].find(qry).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_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 compétences "
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste de bulletin de note d'un partenaire avec des filter sur :
|
|
- session_id
|
|
- class_id
|
|
- diplome_id
|
|
- inscrit_id
|
|
"""
|
|
def Get_Partner_Bulletin_Note_With_Filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'inscription_id', 'session_id', 'class_id', 'diplome_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
|
|
|
|
filt_session_id = {}
|
|
if ("session_id" in diction.keys()):
|
|
filt_session_id = {'session_id':str(diction['session_id'])}
|
|
|
|
filt_class_id = {}
|
|
if ("class_id" in diction.keys()):
|
|
filt_class_id = {'class_id': str(diction['class_id'])}
|
|
|
|
filt_diplome_id = {}
|
|
if ("diplome_id" in diction.keys()):
|
|
filt_diplome_id = {'diplome_id': str(diction['diplome_id'])}
|
|
|
|
|
|
filt_inscription_id = {}
|
|
if ("inscription_id" in diction.keys()):
|
|
filt_inscription_id = {'inscription_id': str(diction['inscription_id'])}
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
qry = {"partner_owner_recid":str(my_partner['recid']), 'valide':'1', 'locked':'0',
|
|
'object_owner_collection':'inscription',
|
|
'object_owner_id':str(diction['inscription_id']),
|
|
'type_document':'bulletin'}
|
|
|
|
query_with_filter = {'$and': [qry, filt_session_id, filt_class_id, filt_diplome_id, filt_inscription_id]}
|
|
|
|
|
|
for New_retVal in MYSY_GV.dbname['download_files'].find(query_with_filter).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = New_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 bulletins de notes "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Publier une liste de bulletin de note
|
|
"""
|
|
def Publish_Tab_Bulletin_Note(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'tab_download_files_ids']
|
|
|
|
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', 'tab_download_files_ids']
|
|
|
|
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
|
|
|
|
|
|
tab_download_files_ids_work = str(diction['tab_download_files_ids']).split(",")
|
|
tab_download_files_ids = []
|
|
tab_download_files_ids_ObjectId = []
|
|
for tmp in tab_download_files_ids_work:
|
|
if( tmp ):
|
|
tab_download_files_ids.append(tmp)
|
|
tab_download_files_ids_ObjectId.append(tmp)
|
|
|
|
|
|
update_data = {}
|
|
update_data['update_date'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['publish'] = "1"
|
|
update_data['publish_date'] = str(datetime.now())
|
|
|
|
result = MYSY_GV.dbname['download_files'].update_many(
|
|
{'_id':{'$in':tab_download_files_ids_ObjectId},
|
|
'partner_owner_recid':str(my_partner['recid'])},
|
|
|
|
update_data
|
|
)
|
|
|
|
return True, " Les bulletins ont été publiés "
|
|
|
|
|
|
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 publier les bulletins de notes "
|
|
|
|
|
|
"""
|
|
Dépublier une liste de bulletin de note
|
|
"""
|
|
def Unpublish_Tab_Bulletin_Note(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'tab_download_files_ids']
|
|
|
|
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', 'tab_download_files_ids']
|
|
|
|
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
|
|
|
|
tab_download_files_ids_work = str(diction['tab_download_files_ids']).split(",")
|
|
tab_download_files_ids = []
|
|
tab_download_files_ids_ObjectId = []
|
|
for tmp in tab_download_files_ids_work:
|
|
if (tmp):
|
|
tab_download_files_ids.append(tmp)
|
|
tab_download_files_ids_ObjectId.append(tmp)
|
|
|
|
update_data = {}
|
|
update_data['update_date'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['publish'] = "0"
|
|
update_data['unpublish_date'] = str(datetime.now())
|
|
|
|
result = MYSY_GV.dbname['download_files'].update_many(
|
|
{'_id': {'$in': tab_download_files_ids_ObjectId},
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
|
|
update_data
|
|
)
|
|
|
|
return True, " Les bulletins ont été dépubliés "
|
|
|
|
|
|
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 dépublier les bulletins de notes "
|
|
|
|
|
|
"""
|
|
Supprimer une liste de bulletin de note
|
|
"""
|
|
def Delete_Tab_Bulletin_Note(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'tab_download_files_ids']
|
|
|
|
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', 'tab_download_files_ids']
|
|
|
|
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
|
|
|
|
tab_download_files_ids_work = str(diction['tab_download_files_ids']).split(",")
|
|
tab_download_files_ids = []
|
|
tab_download_files_ids_ObjectId = []
|
|
for tmp in tab_download_files_ids_work:
|
|
if (tmp):
|
|
tab_download_files_ids.append(tmp)
|
|
tab_download_files_ids_ObjectId.append(tmp)
|
|
|
|
update_data = {}
|
|
update_data['update_date'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['publish'] = "0"
|
|
update_data['unpublish_date'] = str(datetime.now())
|
|
|
|
result = MYSY_GV.dbname['download_files'].delete_many(
|
|
{'_id': {'$in': tab_download_files_ids_ObjectId},
|
|
'partner_owner_recid': str(my_partner['recid'])}
|
|
)
|
|
|
|
return True, " Les bulletins ont été supprimés "
|
|
|
|
|
|
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 les bulletins de notes "
|