919 lines
34 KiB
Python
919 lines
34 KiB
Python
"""
|
|
Ce fichier permet de gerer les groupes d'inscrit.
|
|
Par exemple dans les formations initiales, les inscrits à une formation
|
|
sont regroupés en
|
|
- groupe de TD
|
|
- groupe de TP
|
|
- groupe de Projet
|
|
- etc.
|
|
|
|
Ce fichier permet de gérer ces regoupement
|
|
"""
|
|
import bson
|
|
import pymongo
|
|
from pymongo import MongoClient
|
|
import json
|
|
from bson import ObjectId
|
|
import re
|
|
from datetime import datetime
|
|
import prj_common as mycommon
|
|
import secrets
|
|
import inspect
|
|
import sys, os
|
|
import csv
|
|
import pandas as pd
|
|
from pymongo import ReturnDocument
|
|
import GlobalVariable as MYSY_GV
|
|
from math import isnan
|
|
import GlobalVariable as MYSY_GV
|
|
import ela_index_bdd_classes as eibdd
|
|
import email_mgt as email
|
|
import jinja2
|
|
from flask import send_file
|
|
from xhtml2pdf import pisa
|
|
from email.message import EmailMessage
|
|
from email.mime.text import MIMEText
|
|
from email import encoders
|
|
import smtplib
|
|
from email.mime.multipart import MIMEMultipart
|
|
from email.mime.text import MIMEText
|
|
from email.mime.base import MIMEBase
|
|
from email import encoders
|
|
|
|
"""
|
|
Ajout d'un groupe.
|
|
Un groupe est defini par les
|
|
- Code
|
|
- Nom
|
|
- Description
|
|
- Type de groupe (liste : TD, TP, etc)
|
|
- class_id
|
|
- session_id
|
|
|
|
La collection est : groupe_inscription
|
|
"""
|
|
|
|
def Add_Groupe_Inscrit(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'code', 'nom', 'description', 'type_groupe_code', 'class_id', 'session_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', 'code', 'type_groupe_code', 'class_id', 'session_id']
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
# Verifier que ce code n'existe pas déjà
|
|
is_existe_class_metier = MYSY_GV.dbname['groupe_inscription'].count_documents({'code':str(diction['code']),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
|
|
if( is_existe_class_metier != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Un groupe avec le code '" + str(diction['code']) + "' existe déjà ")
|
|
return False, " Un groupe avec le code '" + str(diction['code']) + "' existe déjà "
|
|
|
|
|
|
"""
|
|
Verifier que le class_id exist et est valide
|
|
"""
|
|
is_class_id_count = MYSY_GV.dbname['myclass'].count_documents({'_id':ObjectId(str(diction['class_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if (is_class_id_count != 1) :
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la formation est invalide valide ")
|
|
return False, " L'identifiant de la formation est invalide valide "
|
|
|
|
"""
|
|
Verifier que la session_id exist et est valide
|
|
"""
|
|
is_session_id_count = MYSY_GV.dbname['session_formation'].count_documents({'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if (is_session_id_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session/classe est invalide valide ")
|
|
return False, " L'identifiant de la session/classe est invalide valide "
|
|
|
|
"""
|
|
Verifier que la type_groupe exist et est valide
|
|
"""
|
|
is_type_groupe_code_count = MYSY_GV.dbname['groupe_inscription_type'].count_documents(
|
|
{'code': str(diction['type_groupe_code']),
|
|
'valide': '1',
|
|
'partner_owner_recid':'default'})
|
|
|
|
if (is_type_groupe_code_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type de groupe est invalide valide ")
|
|
return False, " Le type de groupe est invalide valide "
|
|
|
|
new_data = diction
|
|
del diction['token']
|
|
|
|
# Initialisation des champs non envoyés à vide
|
|
for val in field_list:
|
|
if val not in diction.keys():
|
|
new_data[str(val)] = ""
|
|
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
|
|
inserted_id = MYSY_GV.dbname['groupe_inscription'].insert_one(new_data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer le groupe (2) ")
|
|
return False, " Impossible de créer le groupe (2) "
|
|
|
|
|
|
return True, " La metier 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 groupe "
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'un groupe
|
|
"""
|
|
|
|
def Update_Groupe_Inscrit(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'code', 'nom', 'description', 'type_groupe_code', 'class_id', 'session_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 liste ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
new_data = diction
|
|
|
|
# Verifier que le groupe existe et est valide
|
|
is_existe_groupe = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_groupe != 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
|
|
|
|
# Verifier que ce code n'existe pas déjà
|
|
if( "code" in diction.keys() ):
|
|
is_existe_class_metier = MYSY_GV.dbname['groupe_inscription'].count_documents({'code':str(diction['code']),
|
|
'valide':'1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
|
|
if( is_existe_class_metier != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Un groupe avec le code '" + str(diction['code']) + "' existe déjà ")
|
|
return False, " Un groupe avec le code '" + str(diction['code']) + "' existe déjà "
|
|
|
|
|
|
"""
|
|
Verifier que le class_id exist et est valide
|
|
"""
|
|
if ("class_id" in diction.keys()):
|
|
is_class_id_count = MYSY_GV.dbname['myclass'].count_documents({'_id':ObjectId(str(diction['class_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if (is_class_id_count != 1) :
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la formation est invalide valide ")
|
|
return False, " L'identifiant de la formation est invalide valide "
|
|
|
|
"""
|
|
Verifier que la session_id exist et est valide
|
|
"""
|
|
if ("session_id" in diction.keys()):
|
|
is_session_id_count = MYSY_GV.dbname['session_formation'].count_documents({'_id': ObjectId(str(diction['session_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
if (is_session_id_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la session/classe est invalide valide ")
|
|
return False, " L'identifiant de la session/classe est invalide valide "
|
|
|
|
|
|
"""
|
|
Verifier que la type_groupe exist et est valide
|
|
"""
|
|
if ("type_groupe_code" in diction.keys()):
|
|
is_type_groupe_code_count = MYSY_GV.dbname['groupe_inscription_type'].count_documents(
|
|
{'code': str(diction['type_groupe_code']),
|
|
'valide': '1',
|
|
'partner_owner_recid':'default'})
|
|
|
|
if (is_type_groupe_code_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Le type de groupe est invalide valide ")
|
|
return False, " Le type de groupe est invalide valide "
|
|
|
|
|
|
|
|
|
|
local_id = str(diction['_id'])
|
|
|
|
del diction['token']
|
|
del diction['_id']
|
|
|
|
|
|
new_data['date_update'] = str(datetime.now())
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['_id'] = ObjectId(local_id)
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
result = MYSY_GV.dbname['groupe_inscription'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour le groupe (2) ")
|
|
return False, " Impossible de mettre à jour le groupe (2) "
|
|
|
|
return True, " Le groupe 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 groupe "
|
|
|
|
|
|
"""
|
|
Suppression d'un groupe
|
|
regles :
|
|
Si la condition (_id) n'est pas utilisé dans les collection
|
|
- groupe_inscription_membre (la liste des personnes apprenant a ce groupe. on utilise l'inscription_id)
|
|
"""
|
|
|
|
def Delete_Groupe_Inscrit(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 liste ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
|
|
# Verifier que la codition de paiement existe
|
|
is_existe_groupe = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_groupe != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
|
|
"""
|
|
Verifier que le groupe n'est pas utilisé dans la collection 'groupe_inscription_membre'
|
|
"""
|
|
is_groupe_has_members = MYSY_GV.dbname['groupe_inscription_membre'].count_documents({'partner_owner_recid':my_partner['recid'],
|
|
'valide':'1',
|
|
'groupe_inscription_id':str(diction['_id'])})
|
|
|
|
|
|
if( is_groupe_has_members > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " Ce groupe a "+str(is_groupe_has_members)+" membres ")
|
|
return False, " Ce groupe a "+str(is_groupe_has_members)+" membres "
|
|
|
|
|
|
|
|
|
|
delete = MYSY_GV.dbname['groupe_inscription'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
}, )
|
|
|
|
|
|
|
|
return True, " Le groupe 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 groupe "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste des groupe d'un partenaire avec des filtre sur :
|
|
- la session_id
|
|
- la class_id
|
|
- le type_groupe_code
|
|
"""
|
|
def Get_List_Groupe_Inscrit_With_Filter(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'code', 'nom', 'type_groupe_code', 'class_external_code',
|
|
'code_session', ]
|
|
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list and val.startswith('my_') is False:
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " Le champ '" + val + "' n'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', ]
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
filt_nom = {}
|
|
if ("nom" in diction.keys()):
|
|
filt_nom = {'nom': {'$regex': str(diction['nom']), "$options": "i"}}
|
|
|
|
|
|
filt_code = {}
|
|
if ("code" in diction.keys()):
|
|
filt_ref_interne = {
|
|
'code': {'$regex': str(diction['code']), "$options": "i"}}
|
|
|
|
|
|
filt_session_id = {}
|
|
list_session_id = []
|
|
if ("code_session" in diction.keys()):
|
|
filt_code_session = {'code_session': {'$regex': str(diction['code_session']), "$options": "i"}}
|
|
|
|
qry_list_session_id = {"$and": [{'code_session': {'$regex': str(diction['code_session']), "$options": "i"}},
|
|
{'partner_owner_recid': str(my_partner['recid'])}]}
|
|
|
|
# print(" ### qry_list_session_id aa = ", qry_list_session_id)
|
|
list_session_id_count = MYSY_GV.dbname['session_formation'].count_documents(qry_list_session_id)
|
|
|
|
if (list_session_id_count <= 0):
|
|
# Aucune session
|
|
return True, []
|
|
|
|
for val in MYSY_GV.dbname['session_formation'].find(qry_list_session_id):
|
|
list_session_id.append(str(val['_id']))
|
|
|
|
# print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
|
filt_session_id = {'session_id': {'$in': list_session_id, }}
|
|
|
|
|
|
filt_class_id = {}
|
|
list_class_id = []
|
|
if ("class_external_code" in diction.keys()):
|
|
filt_class_title = {'external_code': {'$regex': str(diction['class_external_code']), "$options": "i"}}
|
|
|
|
qry_list_class_id = {
|
|
"$and": [{'external_code': {'$regex': str(diction['class_external_code']), "$options": "i"}},
|
|
{'partner_owner_recid': str(my_partner['recid'])}]}
|
|
|
|
print(" ### qry_list_class_id aa = ", qry_list_class_id)
|
|
list_class_id_count = MYSY_GV.dbname['myclass'].count_documents(qry_list_class_id)
|
|
|
|
if (list_class_id_count <= 0):
|
|
# Aucune session
|
|
return True, []
|
|
|
|
for val in MYSY_GV.dbname['myclass'].find(qry_list_class_id):
|
|
list_class_id.append(str(val['_id']))
|
|
|
|
# print(" ### liste des Id des sessions eligible list_session_id = ", list_session_id)
|
|
filt_class_id = {'class_id': {'$in': list_class_id, }}
|
|
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
|
|
find_qry = {'$and': [{'partner_owner_recid': str(my_partner['recid']), 'valide': '1', 'locked': '0'}, filt_class_id,
|
|
filt_session_id, filt_code, filt_nom]}
|
|
|
|
for retval in MYSY_GV.dbname['groupe_inscription'].find(find_qry).sort([("_id", pymongo.DESCENDING), ]):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
|
|
if ("class_id" not in retval.keys()):
|
|
user['class_title'] = ""
|
|
user['class_internal_url'] = ""
|
|
else:
|
|
my_class_data = MYSY_GV.dbname['myclass'].find_one({"_id":ObjectId(str(retval['class_id'])),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
if( my_class_data and "title" in my_class_data.keys() ):
|
|
user['class_title'] = my_class_data['title']
|
|
|
|
if (my_class_data and "internal_url" in my_class_data.keys()):
|
|
user['class_internal_url'] = my_class_data['internal_url']
|
|
|
|
if ("session_id" not in retval.keys()):
|
|
user['session_code_session'] = ""
|
|
else:
|
|
my_session_formation_data = MYSY_GV.dbname['session_formation'].find_one({"_id": ObjectId(str(retval['session_id'])),
|
|
'valide': '1',})
|
|
|
|
if (my_session_formation_data and "code_session" in my_session_formation_data.keys()):
|
|
user['session_code_session'] = my_class_data['code_session']
|
|
|
|
|
|
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 metiers de formation "
|
|
|
|
|
|
"""
|
|
Recuperer les données d'un groupe donné
|
|
"""
|
|
def Get_Given_Groupe_Inscrit_Data(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 liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
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['groupe_inscription'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject
|
|
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de récupérer les données du groupe "
|
|
|
|
|
|
"""
|
|
Recuperer la liste des membres d'un groupe
|
|
"""
|
|
|
|
def Get_Given_Groupe_Inscrit_With_Membres(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 liste ")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
"""
|
|
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['groupe_inscription'].find(data_cle):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
user['membres'] = MYSY_GV.dbname['groupe_inscription_membre'].find({'groupe_inscription_id':str(retval['_id']),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
|
|
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 groupe "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet d'inscrire des 'inscrit_id' a un groupe
|
|
"""
|
|
|
|
def Add_Update_Groupe_Inscrit(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'tab_inscriptions_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', '_id',]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
new_data = diction
|
|
|
|
# Verifier que le groupe existe et est valide
|
|
is_existe_groupe = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_groupe != 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
|
|
tab_inscriptions_ids = ""
|
|
if ("tab_inscriptions_ids" in diction.keys()):
|
|
if diction['tab_inscriptions_ids']:
|
|
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
|
|
|
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
|
# Controle de validité des inscriptions
|
|
for my_inscription in tab_inscriptions_ids_splited:
|
|
# Verifier que l'inscription est valide
|
|
my_inscription_is_valide = MYSY_GV.dbname['inscription'].count_documents(
|
|
{'_id': ObjectId(str(my_inscription)), 'status': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (my_inscription_is_valide != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'inscription_id '" + my_inscription + "' est invalide ")
|
|
return False, " L'inscription_id '" + my_inscription + "' est invalide "
|
|
|
|
cpt = 0
|
|
for my_inscription in tab_inscriptions_ids_splited:
|
|
new_data = {}
|
|
new_data['groupe_inscription_id'] = str(diction['_id'])
|
|
new_data['inscription_id'] = str(my_inscription['_id'])
|
|
|
|
now = str(datetime.now())
|
|
new_data['date_update'] = now
|
|
new_data['valide'] = "1"
|
|
new_data['locked'] = "0"
|
|
new_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
new_data['update_by'] = str(my_partner['_id'])
|
|
|
|
data_cle = {}
|
|
data_cle['partner_owner_recid'] = str(my_partner['recid'])
|
|
data_cle['groupe_inscription_id'] = str(diction['_id'])
|
|
data_cle['inscription_id'] = str(my_inscription['_id'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
result = MYSY_GV.dbname['groupe_inscription_membre'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": new_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if (result is None or "_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible d'inscrire les personnes au groupe (2) ")
|
|
return False, " Impossible d'inscrire les personnes au groupe (2) "
|
|
|
|
|
|
cpt = cpt + 1
|
|
|
|
|
|
|
|
return True, str(cpt)+ " Membre(s) inscrit(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 d'inscrire les personnes au groupe "
|
|
|
|
|
|
"""
|
|
Cette fonction permet de supprimer des inscrits à un groupe
|
|
"""
|
|
|
|
|
|
def Delete_Groupe_Inscrit_Membres(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'tab_inscriptions_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', '_id', ]
|
|
|
|
for val in field_list_obligatoire:
|
|
if val not in diction:
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
|
return False, " Les informations fournies sont incorrectes"
|
|
|
|
"""
|
|
Verification de l'identité et autorisation de l'entité qui
|
|
appelle cette API
|
|
"""
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
new_data = diction
|
|
|
|
# Verifier que le groupe existe et est valide
|
|
is_existe_groupe = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
if (is_existe_groupe != 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
tab_inscriptions_ids = ""
|
|
if ("tab_inscriptions_ids" in diction.keys()):
|
|
if diction['tab_inscriptions_ids']:
|
|
tab_inscriptions_ids = diction['tab_inscriptions_ids']
|
|
|
|
tab_inscriptions_ids_splited = str(tab_inscriptions_ids).split(",")
|
|
|
|
qery_delete = {'inscription_id': {'$in': tab_inscriptions_ids_splited},
|
|
'groupe_inscription_id':str(diction['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'locked': '0'}
|
|
|
|
delete = MYSY_GV.dbname['groupe_inscription_membre'].delete_many(qery_delete )
|
|
|
|
return True, str(delete.deleted_count) + " Membre(s) désinscrit(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 désinscrire les personnes au groupe "
|