"""
Fichier de gestion des opco
"""
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
from datetime import timedelta
import email_inscription_mgt as email_session


def GetListOpco():
    try:

        ## Recuperation de toutes les stagiaire rattaché à cette session
        coll_opco = MYSY_GV.dbname['liste_opco']
        myquery = {}
        myquery['valide'] = "1"

        RetObject = []
        val_tmp = 1

        # print(" #### myquery = "+str(myquery))

        for retval in coll_opco.find(myquery):
            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) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
        return False, "Impossible de recuperer la liste des opco "


