04/12/2023 - 12h30
parent
7b96432866
commit
9562f45b89
|
@ -2,10 +2,15 @@
|
|||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="01/12/2023 - 23h">
|
||||
<change afterPath="$PROJECT_DIR$/Dashbord_queries/formation_tbd_qries.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Dashbord_queries/common_tdb_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/common_tdb_qries.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Dashbord_queries/session_tbd_qries.py" beforeDir="false" afterPath="$PROJECT_DIR$/Dashbord_queries/session_tbd_qries.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Inscription_mgt.py" beforeDir="false" afterPath="$PROJECT_DIR$/Inscription_mgt.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/partner_invoice.py" beforeDir="false" afterPath="$PROJECT_DIR$/partner_invoice.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/prj_common.py" beforeDir="false" afterPath="$PROJECT_DIR$/prj_common.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
|
@ -296,10 +296,47 @@ def Get_Connected_User_List_Dashbord(diction):
|
|||
|
||||
qry = {'valide':"1", 'locked':'0','partner_owner_recid':str(my_partner['recid']),'connected_id':str(my_partner['_id'])}
|
||||
|
||||
print(" ### qry = ", qry)
|
||||
|
||||
|
||||
for retval in MYSY_GV.dbname['user_dashbord'].find( qry):
|
||||
|
||||
"""
|
||||
Convertion des filtres en date reelles.
|
||||
Par exemple m0 = mois en cours = 1 du mois en cours à la date du jours.
|
||||
"""
|
||||
start_date = ""
|
||||
end_date = ""
|
||||
if( "default_filter" in retval.keys() ):
|
||||
local_default_filter = ast.literal_eval(retval['default_filter'])
|
||||
#print(" ### local_default_filter = ", local_default_filter)
|
||||
|
||||
if( "periode" in local_default_filter.keys() and str(local_default_filter['periode']) == "m0" ):
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if( local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
start_date = start_current_month_date
|
||||
end_date = end_current_month_date
|
||||
#print(" ### start_current_month_date = ", start_current_month_date, " ### end_current_month_date =", end_current_month_date)
|
||||
|
||||
if ("periode" in local_default_filter.keys() and str(local_default_filter['periode']) == "m1"):
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
start_date = start_current_month_date
|
||||
end_date = end_current_month_date
|
||||
#print(" ### start_current_month_date = ", start_current_month_date, " ### end_current_month_date =", end_current_month_date)
|
||||
|
||||
if ("session_start_date" in local_default_filter.keys() and "session_end_date" in local_default_filter.keys()):
|
||||
start_date = local_default_filter['session_start_date']
|
||||
end_date = local_default_filter['session_end_date']
|
||||
#print(" ### start_date = ", start_date, " ### end_date =",end_date)
|
||||
|
||||
|
||||
|
||||
retval['start_date'] = start_date
|
||||
retval['end_date'] = end_date
|
||||
#print(" ### final retval = ", retval)
|
||||
RetObject.append(mycommon.JSONEncoder().encode(retval))
|
||||
|
||||
return True, RetObject
|
||||
|
|
|
@ -0,0 +1,530 @@
|
|||
"""
|
||||
Ce fichier contient les requetes utilisées dans les tableaux de bord des Formation
|
||||
"""
|
||||
import ast
|
||||
|
||||
import dateutil
|
||||
import pymongo
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from flask import send_file
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime, timezone, date
|
||||
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
|
||||
from datetime import timedelta
|
||||
from operator import itemgetter
|
||||
|
||||
"""
|
||||
Recupération du nombre de session par formation par mois
|
||||
"""
|
||||
def Get_Qery_Formation_By_Session_By_Periode(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_start_date', 'session_end_date', 'filter_value' ]
|
||||
|
||||
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', 'session_start_date', 'session_end_date' ]
|
||||
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_session_start_date = ""
|
||||
if ("session_start_date" in diction.keys() and diction['session_start_date']):
|
||||
filt_session_start_date = str(diction['session_start_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_session_start_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de debut de session' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de debut de session' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
filt_session_end_date = ""
|
||||
if ("session_end_date" in diction.keys() and diction['session_end_date']):
|
||||
filt_session_end_date = str(diction['session_end_date'])[0:10]
|
||||
local_status = mycommon.CheckisDate(filt_session_end_date)
|
||||
if (local_status is False):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa.")
|
||||
return False, " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if( 'filter_value' in diction.keys() ):
|
||||
if( str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
filt_session_start_date_ISODATE = datetime.strptime(str(filt_session_start_date), '%d/%m/%Y')
|
||||
filt_session_end_date_ISODATE = datetime.strptime(str(filt_session_end_date), '%d/%m/%Y')
|
||||
|
||||
filt_session_start_date_ISODATE_work = filt_session_start_date_ISODATE
|
||||
filt_session_end_date_ISODATE_work = filt_session_end_date_ISODATE
|
||||
|
||||
interval_date = []
|
||||
|
||||
while filt_session_start_date_ISODATE_work <= filt_session_end_date_ISODATE_work:
|
||||
interval_date.append(filt_session_start_date_ISODATE_work)
|
||||
filt_session_start_date_ISODATE_work += relativedelta(months=1)
|
||||
|
||||
|
||||
qery_match = {'$and': [{"partner_owner_recid": str(my_partner['recid'])}, {"valide": '1'},
|
||||
{"formateur_id": {"$exists": 'true'}}, {
|
||||
'mysy_date_debut_session': {'$gte': filt_session_start_date_ISODATE,
|
||||
'$lte': filt_session_end_date_ISODATE}}, ]}
|
||||
|
||||
pipe_qry = ([
|
||||
{"$addFields": {
|
||||
"mysy_date_debut_session": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_debut',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{'$match': qery_match},
|
||||
{'$lookup': {
|
||||
'from': 'myclass',
|
||||
'let': {'formateur_id': '$formateur_id', 'partner_owner_recid': '$partner_owner_recid'},
|
||||
'localField': 'class_internal_url',
|
||||
'foreignField': 'internal_url',
|
||||
'pipeline': [
|
||||
{'$match':
|
||||
{'$expr':
|
||||
{'$and':
|
||||
[
|
||||
{'$eq': ["$valide", "1"]},
|
||||
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
'as': 'myclass'
|
||||
}
|
||||
},
|
||||
{'$group': {
|
||||
'_id': {
|
||||
|
||||
"class_internal_url": '$myclass.internal_url',
|
||||
"mois_annee_session": {'$substr': ["$date_debut", 3, 7]},
|
||||
},
|
||||
'count': {'$count': {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'$sort': {'_id': -1}
|
||||
},
|
||||
|
||||
])
|
||||
|
||||
print(" ### Get_Qery_Formation_By_Session_By_Periode ici pipe_qry = ", pipe_qry)
|
||||
|
||||
new_retval_titles = []
|
||||
new_retval_data = []
|
||||
for retval in MYSY_GV.dbname['session_formation'].aggregate(pipe_qry):
|
||||
#print(" ### retval = ", retval )
|
||||
user = retval
|
||||
existe_title = "0"
|
||||
tab_new_mois_data = str(retval['_id']['mois_annee_session']).split("/")
|
||||
new_mois_data = str(tab_new_mois_data[1])+"/"+str(tab_new_mois_data[0])
|
||||
new_mois_count = retval['count']
|
||||
|
||||
new_point = {"x":str(new_mois_data), "y":mycommon.tryInt(str(retval['count']))}
|
||||
#print(" ### new_point = ", new_point)
|
||||
|
||||
for val in new_retval_data:
|
||||
if( val["id"] == retval['_id']['class_internal_url'] ):
|
||||
val["data"].append(new_point)
|
||||
existe_title = "1"
|
||||
|
||||
if(existe_title == "0" ):
|
||||
# Ce titre n'existe pas
|
||||
new_title = {}
|
||||
new_title['id'] = retval['_id']['class_internal_url']
|
||||
new_title["data"] = []
|
||||
new_title["data"].append(new_point)
|
||||
new_retval_data.append(new_title)
|
||||
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
|
||||
#print(" #### new_retval_data = ", new_retval_data)
|
||||
|
||||
|
||||
interval_date_str = []
|
||||
for val in interval_date:
|
||||
tmp = str(val.strftime("%Y/%m"))
|
||||
interval_date_str.append(tmp)
|
||||
|
||||
for formation_data in new_retval_data:
|
||||
#print(" ANALYSE DE LA LIGNE :", formation_data)
|
||||
for my_date in interval_date_str:
|
||||
#print(" ### on cherche la date = ", my_date)
|
||||
ok = 0
|
||||
for val2 in formation_data['data']:
|
||||
if (val2['x'] == my_date):
|
||||
ok = 1
|
||||
#print(" trouvé : " + str(my_date))
|
||||
if (ok == 0):
|
||||
#print(" on PAS trouvé " + str(my_date))
|
||||
new_node = {'x': str(my_date), 'y': 0}
|
||||
formation_data['data'].append(new_node)
|
||||
#print(" Apres ajout ",formation_data['data'] )
|
||||
|
||||
formation_data['data'].sort(key=itemgetter('x'), reverse=False)
|
||||
#print(" #### TRIEEE = ", formation_data)
|
||||
|
||||
#print(" #### new_retval_data = ", new_retval_data)
|
||||
RetObject.append(mycommon.JSONEncoder().encode(new_retval_data))
|
||||
|
||||
|
||||
|
||||
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 "
|
||||
|
||||
|
||||
|
||||
""""
|
||||
Export Excel/CSV du resultat de Get_Qery_Formation_By_Session_By_Periode
|
||||
"""
|
||||
def Get_Qery_Formation_By_Session_By_Periode_Export_CSV(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'user_dashbord_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', 'user_dashbord_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
|
||||
|
||||
# Recuperation des données du user_dashbord
|
||||
my_user_dashbord = MYSY_GV.dbname['user_dashbord'].find_one(
|
||||
{'_id': ObjectId(str(diction['user_dashbord_id'])),
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])})
|
||||
|
||||
if (my_user_dashbord is None):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - L'identifiant du tableau de bord est invalide ")
|
||||
return False, " L'identifiant du tableau de bord est invalide",
|
||||
|
||||
local_default_filter = ast.literal_eval(str(my_user_dashbord['default_filter']))
|
||||
|
||||
my_new_diction = {}
|
||||
my_new_diction['token'] = diction['token']
|
||||
|
||||
filt_session_start_date = ""
|
||||
filt_session_end_date = ""
|
||||
|
||||
local_default_filter = ast.literal_eval(str(my_user_dashbord['default_filter']))
|
||||
if ("session_start_date" in local_default_filter.keys() and "session_end_date" in local_default_filter.keys()):
|
||||
filt_session_start_date = local_default_filter['session_start_date']
|
||||
filt_session_end_date = local_default_filter['session_end_date']
|
||||
|
||||
elif ("periode" in local_default_filter.keys()):
|
||||
my_new_diction['filter_value'] = str(local_default_filter['periode'])
|
||||
if (str(local_default_filter['periode']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
elif (str(local_default_filter['periode']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
|
||||
print(" ### DATE RECUP filt_session_start_date = ", filt_session_start_date, " --- filt_session_end_date = ",filt_session_end_date)
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
filt_session_start_date_ISODATE = datetime.strptime(str(filt_session_start_date), '%d/%m/%Y')
|
||||
filt_session_end_date_ISODATE = datetime.strptime(str(filt_session_end_date), '%d/%m/%Y')
|
||||
|
||||
filt_session_start_date_ISODATE_work = filt_session_start_date_ISODATE
|
||||
filt_session_end_date_ISODATE_work = filt_session_end_date_ISODATE
|
||||
|
||||
interval_date = []
|
||||
|
||||
while filt_session_start_date_ISODATE_work <= filt_session_end_date_ISODATE_work:
|
||||
interval_date.append(filt_session_start_date_ISODATE_work)
|
||||
filt_session_start_date_ISODATE_work += relativedelta(months=1)
|
||||
|
||||
|
||||
qery_match = {'$and': [{"partner_owner_recid": str(my_partner['recid'])}, {"valide": '1'},
|
||||
{"formateur_id": {"$exists": 'true'}}, {
|
||||
'mysy_date_debut_session': {'$gte': filt_session_start_date_ISODATE,
|
||||
'$lte': filt_session_end_date_ISODATE}}, ]}
|
||||
|
||||
pipe_qry = ([
|
||||
{"$addFields": {
|
||||
"mysy_date_debut_session": {
|
||||
'$dateFromString': {
|
||||
'dateString': '$date_debut',
|
||||
'format': "%d/%m/%Y"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
{'$match': qery_match},
|
||||
{'$lookup': {
|
||||
'from': 'myclass',
|
||||
'let': {'formateur_id': '$formateur_id', 'partner_owner_recid': '$partner_owner_recid'},
|
||||
'localField': 'class_internal_url',
|
||||
'foreignField': 'internal_url',
|
||||
'pipeline': [
|
||||
{'$match':
|
||||
{'$expr':
|
||||
{'$and':
|
||||
[
|
||||
{'$eq': ["$valide", "1"]},
|
||||
{'$eq': ["$partner_owner_recid", '$$partner_owner_recid']}
|
||||
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
],
|
||||
'as': 'myclass'
|
||||
}
|
||||
},
|
||||
{'$group': {
|
||||
'_id': {
|
||||
|
||||
"class_internal_url": '$myclass.internal_url',
|
||||
"mois_annee_session": {'$substr': ["$date_debut", 3, 7]},
|
||||
},
|
||||
'count': {'$count': {}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
'$sort': {'_id': -1}
|
||||
},
|
||||
|
||||
])
|
||||
|
||||
#print(" ### Get_Qery_Formation_By_Session_By_Periode ici pipe_qry = ", pipe_qry)
|
||||
|
||||
new_retval_titles = []
|
||||
new_retval_data = []
|
||||
for retval in MYSY_GV.dbname['session_formation'].aggregate(pipe_qry):
|
||||
#print(" ### retval = ", retval )
|
||||
user = retval
|
||||
existe_title = "0"
|
||||
tab_new_mois_data = str(retval['_id']['mois_annee_session']).split("/")
|
||||
new_mois_data = str(tab_new_mois_data[1])+"/"+str(tab_new_mois_data[0])
|
||||
new_mois_count = retval['count']
|
||||
|
||||
new_point = {"x":str(new_mois_data), "y":mycommon.tryInt(str(retval['count']))}
|
||||
#print(" ### new_point = ", new_point)
|
||||
|
||||
for val in new_retval_data:
|
||||
if( val["id"] == retval['_id']['class_internal_url'] ):
|
||||
val["data"].append(new_point)
|
||||
existe_title = "1"
|
||||
|
||||
if(existe_title == "0" ):
|
||||
# Ce titre n'existe pas
|
||||
new_title = {}
|
||||
new_title['id'] = retval['_id']['class_internal_url']
|
||||
new_title["data"] = []
|
||||
new_title["data"].append(new_point)
|
||||
new_retval_data.append(new_title)
|
||||
|
||||
val_tmp = val_tmp + 1
|
||||
|
||||
|
||||
#print(" #### new_retval_data = ", new_retval_data)
|
||||
|
||||
|
||||
interval_date_str = []
|
||||
for val in interval_date:
|
||||
tmp = str(val.strftime("%Y/%m"))
|
||||
interval_date_str.append(tmp)
|
||||
|
||||
|
||||
for formation_data in new_retval_data:
|
||||
#print(" ANALYSE DE LA LIGNE :", formation_data)
|
||||
for my_date in interval_date_str:
|
||||
#print(" ### on cherche la date = ", my_date)
|
||||
ok = 0
|
||||
for val2 in formation_data['data']:
|
||||
if (val2['x'] == my_date):
|
||||
ok = 1
|
||||
#print(" trouvé : " + str(my_date))
|
||||
if (ok == 0):
|
||||
#print(" on PAS trouvé " + str(my_date))
|
||||
new_node = {'x': str(my_date), 'y': 0}
|
||||
formation_data['data'].append(new_node)
|
||||
#print(" Apres ajout ",formation_data['data'] )
|
||||
|
||||
formation_data['data'].sort(key=itemgetter('x'), reverse=False)
|
||||
#print(" #### TRIEEE = ", formation_data)
|
||||
|
||||
#print(" #### RetObject = ", RetObject)
|
||||
|
||||
new_tab = []
|
||||
for val in new_retval_data:
|
||||
for tmp in val['data']:
|
||||
local_node = {}
|
||||
local_node['class'] = str(val['id'][0])
|
||||
local_node['date'] = tmp['x']
|
||||
local_node['nb_session'] = tmp['y']
|
||||
new_tab.append(local_node)
|
||||
|
||||
#print(" ### final new_tab = ", new_tab)
|
||||
|
||||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||||
|
||||
orig_file_name = "Export_csv_" + str(my_partner['recid']) + "_" + str(ts) + ".csv"
|
||||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||||
|
||||
tab_exported_fields = ['date_extraction', 'filtre_date_debut', 'filtre_date_fin', 'class', 'date', 'nb_session']
|
||||
session_start_date = str(filt_session_start_date_ISODATE)
|
||||
session_end_date = str(filt_session_end_date_ISODATE)
|
||||
|
||||
|
||||
with open(outputFilename, 'w', newline='') as outfile:
|
||||
fields = tab_exported_fields
|
||||
write = csv.DictWriter(outfile, fieldnames=fields)
|
||||
write.writeheader()
|
||||
|
||||
for answers_record in new_tab: # Here we are using 'cursor' as an iterator
|
||||
flattened_record = {}
|
||||
|
||||
for local_fiels in tab_exported_fields:
|
||||
answers_record_JSON = ast.literal_eval(str(answers_record))
|
||||
if( str(local_fiels) in answers_record_JSON.keys() ):
|
||||
flattened_record[str(local_fiels)] = answers_record_JSON[str(local_fiels)]
|
||||
|
||||
flattened_record['filtre_date_debut'] = str(session_start_date)[0:10]
|
||||
flattened_record['filtre_date_fin'] = str(session_end_date)[0:10]
|
||||
flattened_record['date_extraction'] = str(todays_date)[0:10]
|
||||
|
||||
#print(" ### flattened_record = ", flattened_record)
|
||||
|
||||
write.writerow(flattened_record)
|
||||
|
||||
if os.path.exists(outputFilename):
|
||||
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
return True, send_file(outputFilename, as_attachment=True)
|
||||
|
||||
return False, "Impossible de générer l'export csv (2) "
|
||||
|
||||
|
||||
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 "
|
|
@ -1,13 +1,16 @@
|
|||
"""
|
||||
Ce fichier contient les requetes utilisées dans les tableaux de bord des session
|
||||
Ce fichier contient les requetes utilisées dans les tableaux de bord des sessions
|
||||
"""
|
||||
import ast
|
||||
|
||||
import dateutil
|
||||
import pymongo
|
||||
from flask import send_file
|
||||
from pymongo import MongoClient
|
||||
import json
|
||||
from bson import ObjectId
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, date
|
||||
import prj_common as mycommon
|
||||
import secrets
|
||||
import inspect
|
||||
|
@ -20,7 +23,7 @@ from math import isnan
|
|||
import GlobalVariable as MYSY_GV
|
||||
from datetime import timedelta
|
||||
from datetime import timedelta
|
||||
|
||||
import Dashbord_queries.formation_tbd_qries as formation_tbd_qries
|
||||
|
||||
"""
|
||||
Recuperation des sessions avec le taux de remplissage
|
||||
|
@ -32,7 +35,7 @@ def Get_Qery_List_Session_Data(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_start_date', 'session_end_date' ]
|
||||
field_list = ['token', 'session_start_date', 'session_end_date', 'filter_value' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -83,6 +86,33 @@ def Get_Qery_List_Session_Data(diction):
|
|||
return False, " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if( 'filter_value' in diction.keys() ):
|
||||
#print(" filter_value = ", diction['filter_value'])
|
||||
if( str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
#print(" ### filt_session_start_date = ", filt_session_start_date, " ### filt_session_end_date = ", filt_session_end_date)
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
||||
|
@ -91,7 +121,7 @@ def Get_Qery_List_Session_Data(diction):
|
|||
'date_debut':1, 'date_fin':1}]
|
||||
|
||||
|
||||
print(" #### qery = ", qery)
|
||||
#print(" #### qery = ", qery)
|
||||
for retval in MYSY_GV.dbname['session_formation'].find({'partner_owner_recid':str(my_partner['recid'])}, {'code_session':1, 'session_etape':1, 'class_internal_url':1, 'distantiel':1,
|
||||
'presentiel':1, 'nb_participant':1, 'formateur_id':1, 'date_debut':1, 'date_fin':1}):
|
||||
user = retval
|
||||
|
@ -188,7 +218,7 @@ def Get_Qery_Session_By_Trainer_By_Periode(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_start_date', 'session_end_date' ]
|
||||
field_list = ['token', 'session_start_date', 'session_end_date', 'filter_value' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -239,6 +269,28 @@ def Get_Qery_Session_By_Trainer_By_Periode(diction):
|
|||
return False, " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if( 'filter_value' in diction.keys() ):
|
||||
if( str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
@ -247,11 +299,6 @@ def Get_Qery_Session_By_Trainer_By_Periode(diction):
|
|||
filt_session_end_date_ISODATE = datetime.strptime(str(filt_session_end_date), '%d/%m/%Y')
|
||||
|
||||
|
||||
|
||||
qery = [{'partner_owner_recid':str(my_partner['recid'])}, {'code_session':1, 'session_etape':1, 'class_internal_url':1, 'distantiel':1,
|
||||
'presentiel':1, 'nb_participant':1, 'formateur_id':1,
|
||||
'date_debut':1, 'date_fin':1}]
|
||||
|
||||
qery_match = {'$and': [ {"partner_owner_recid":str(my_partner['recid']) }, {"valide":'1'}, {"formateur_id": { "$exists": 'true' } }, { 'mysy_date_debut_session': { '$gte': filt_session_start_date_ISODATE, '$lte': filt_session_end_date_ISODATE } } , ]}
|
||||
|
||||
pipe_qry = ([
|
||||
|
@ -365,7 +412,7 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'session_start_date', 'session_end_date' ]
|
||||
field_list = ['token', 'session_start_date', 'session_end_date' , 'filter_value' ]
|
||||
|
||||
incom_keys = diction.keys()
|
||||
for val in incom_keys:
|
||||
|
@ -416,6 +463,30 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
return False, " Le filtre : 'date de fin de session' n'est pas au format jj/mm/aaaa."
|
||||
|
||||
|
||||
"""
|
||||
Si la valeur de 'filter_value' est m0 ou m1, on va aller recuperer les date du mois correspondant.
|
||||
On ecrase les valeur de filt_session_start_date et filt_session_end_date
|
||||
"""
|
||||
if( 'filter_value' in diction.keys() ):
|
||||
if( str(diction['filter_value']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
elif (str(diction['filter_value']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
filt_session_start_date = start_current_month_date
|
||||
filt_session_end_date = end_current_month_date
|
||||
|
||||
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 1
|
||||
|
@ -423,10 +494,12 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
filt_session_start_date_ISODATE = datetime.strptime(str(filt_session_start_date), '%d/%m/%Y')
|
||||
filt_session_end_date_ISODATE = datetime.strptime(str(filt_session_end_date), '%d/%m/%Y')
|
||||
|
||||
|
||||
#print(" ### filt_session_start_date_ISODATE = ", filt_session_start_date_ISODATE)
|
||||
#print(" ### filt_session_end_date_ISODATE = ", filt_session_end_date_ISODATE)
|
||||
|
||||
qery_match = {'$and': [{"partner_owner_recid":str(my_partner['recid']) }, {"valide":'1'}, { 'mysy_date_debut_session': { '$gte': filt_session_start_date_ISODATE, '$lte': filt_session_end_date_ISODATE } } , ]}
|
||||
|
||||
#print(" ### qery_match = ", qery_match)
|
||||
# Recuperation du nombre total de session sur la periode
|
||||
pipe_qry_nb_record = ([
|
||||
{"$addFields": {
|
||||
|
@ -444,8 +517,7 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
{'$project': {'_id': 0}}
|
||||
])
|
||||
|
||||
|
||||
|
||||
#print(" ### pipe_qry_nb_record = ", pipe_qry_nb_record)
|
||||
nb_total_session = 0
|
||||
Nb_Record_RetObject = []
|
||||
for retval in MYSY_GV.dbname['session_formation'].aggregate(pipe_qry_nb_record):
|
||||
|
@ -453,11 +525,11 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
if( "nb_record" in retval.keys() and retval['nb_record']):
|
||||
nb_total_session = mycommon.tryInt(retval['nb_record'])
|
||||
|
||||
print(" #### nb_total_session = ",str(nb_total_session))
|
||||
#print(" #### nb_total_session = ",str(nb_total_session))
|
||||
if(nb_total_session == 0 ):
|
||||
mycommon.myprint(str(
|
||||
inspect.stack()[0][3]) + " Aucune session de formation valide ")
|
||||
return False, " Aucune session de formation valide "
|
||||
return True, RetObject
|
||||
|
||||
pipe_qry = ([
|
||||
{"$addFields": {
|
||||
|
@ -563,3 +635,188 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(diction):
|
|||
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 "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction permet d'experter un dashbord en csv
|
||||
"""
|
||||
def Export_Dashbord_To_Csv(diction):
|
||||
try:
|
||||
diction = mycommon.strip_dictionary(diction)
|
||||
|
||||
"""
|
||||
Verification des input acceptés
|
||||
"""
|
||||
field_list = ['token', 'user_dashbord_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', 'user_dashbord_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
|
||||
|
||||
# Recuperation des données du user_dashbord
|
||||
my_user_dashbord = MYSY_GV.dbname['user_dashbord'].find_one({'_id':ObjectId(str(diction['user_dashbord_id'])),
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( my_user_dashbord is None):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " - L'identifiant du tableau de bord est invalide ")
|
||||
return False, " L'identifiant du tableau de bord est invalide",
|
||||
|
||||
|
||||
new_retval_data = {}
|
||||
my_new_diction = {}
|
||||
my_new_diction['token'] = diction['token']
|
||||
|
||||
session_start_date = ""
|
||||
session_end_date = ""
|
||||
|
||||
|
||||
local_default_filter = ast.literal_eval(str(my_user_dashbord['default_filter']))
|
||||
if( "session_start_date" in local_default_filter.keys() and "session_end_date" in local_default_filter.keys()):
|
||||
session_start_date = local_default_filter['session_start_date']
|
||||
session_end_date = local_default_filter['session_end_date']
|
||||
|
||||
elif ( "periode" in local_default_filter.keys() ):
|
||||
my_new_diction['filter_value'] = str(local_default_filter['periode'])
|
||||
if (str(local_default_filter['periode']) == "m0"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Current_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
session_start_date = start_current_month_date
|
||||
session_end_date = end_current_month_date
|
||||
|
||||
elif (str(local_default_filter['periode']) == "m1"):
|
||||
# On recupere les date du mois en cours
|
||||
local_status, start_current_month_date, end_current_month_date = mycommon.Get_Previous_Month_Start_End_Date()
|
||||
if (local_status is False):
|
||||
return local_status, start_current_month_date
|
||||
|
||||
session_start_date = start_current_month_date
|
||||
session_end_date = end_current_month_date
|
||||
|
||||
my_new_diction['session_start_date'] = session_start_date
|
||||
my_new_diction['session_end_date'] = session_end_date
|
||||
|
||||
|
||||
|
||||
|
||||
if( my_user_dashbord['dashbord_internal_code'] == "tbd_code_session_01"):
|
||||
local_status, local_retval = Get_Qery_List_Session_Data(my_new_diction)
|
||||
if( local_status is False):
|
||||
return local_status, local_retval
|
||||
new_retval_data = local_retval
|
||||
|
||||
elif ( my_user_dashbord['dashbord_internal_code'] == "tbd_code_session_02"):
|
||||
local_status, local_retval = Get_Qery_Session_By_Trainer_By_Periode(my_new_diction)
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
new_retval_data = local_retval
|
||||
|
||||
elif (my_user_dashbord['dashbord_internal_code'] == "tbd_code_session_03"):
|
||||
local_status, local_retval = Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode(my_new_diction)
|
||||
if (local_status is False):
|
||||
return local_status, local_retval
|
||||
new_retval_data = local_retval
|
||||
|
||||
|
||||
else:
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][3]) + " Requête inconnue ")
|
||||
return False, " Requête inconnue ",
|
||||
|
||||
#print(" ### la new_retval_data = ", new_retval_data)
|
||||
|
||||
|
||||
# Recuperation des colonne à exporter
|
||||
base_config_dashbord_data = MYSY_GV.dbname['base_config_dashbord'].find_one({'dashbord_internal_code':str(my_user_dashbord['dashbord_internal_code'])})
|
||||
|
||||
tab_exported_fields = []
|
||||
if( "exported_fields" in base_config_dashbord_data):
|
||||
tab_exported_fields = base_config_dashbord_data['exported_fields']
|
||||
|
||||
# Remettres les dates de filtres en debut de liste
|
||||
if( "filtre_date_fin" in tab_exported_fields):
|
||||
tab_exported_fields.remove("filtre_date_fin")
|
||||
tab_exported_fields.insert(0, "filtre_date_fin")
|
||||
|
||||
if ("filtre_date_debut" in tab_exported_fields):
|
||||
tab_exported_fields.remove("filtre_date_debut")
|
||||
tab_exported_fields.insert(0, "filtre_date_debut")
|
||||
|
||||
tab_exported_fields.insert(0, "date_extraction")
|
||||
|
||||
|
||||
#print(" ### Liste des colonnes à exporter sont : ", tab_exported_fields)
|
||||
|
||||
|
||||
todays_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
ts = datetime.now().timestamp()
|
||||
ts = str(ts).replace(".", "").replace(",", "")[-5:]
|
||||
|
||||
|
||||
orig_file_name = "Export_csv_"+str(my_partner['recid'])+"_" + str(ts) + ".csv"
|
||||
outputFilename = str(MYSY_GV.TEMPORARY_DIRECTORY) + "/" + str(orig_file_name)
|
||||
|
||||
with open(outputFilename, 'w', newline='') as outfile:
|
||||
fields = tab_exported_fields
|
||||
write = csv.DictWriter(outfile, fieldnames=fields)
|
||||
write.writeheader()
|
||||
|
||||
for answers_record in new_retval_data: # Here we are using 'cursor' as an iterator
|
||||
flattened_record = {}
|
||||
|
||||
for local_fiels in tab_exported_fields:
|
||||
answers_record_JSON = ast.literal_eval(str(answers_record))
|
||||
if( str(local_fiels) in answers_record_JSON.keys() ):
|
||||
flattened_record[str(local_fiels)] = answers_record_JSON[str(local_fiels)]
|
||||
|
||||
flattened_record['filtre_date_debut'] = str(session_start_date)
|
||||
flattened_record['filtre_date_fin'] = str(session_end_date)
|
||||
flattened_record['date_extraction'] = str(todays_date)
|
||||
|
||||
#print(" ### flattened_record = ", flattened_record)
|
||||
|
||||
write.writerow(flattened_record)
|
||||
|
||||
if os.path.exists(outputFilename):
|
||||
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||
return True, send_file(outputFilename, as_attachment=True)
|
||||
|
||||
return False, "Impossible de générer l'export csv (2) "
|
||||
|
||||
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'exporter les données "
|
||||
|
||||
|
||||
|
|
|
@ -5952,3 +5952,78 @@ def UpdateStagiairetoClass_Tuteurs(diction):
|
|||
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 mettre à jour le tuteur "
|
||||
|
||||
|
||||
"""
|
||||
Cette fonction recupere les differentes types de convention de stagiaire
|
||||
|
||||
On accepte plusieurs vesions du meme doc
|
||||
"""
|
||||
def Get_List_Conventions_Stagiaire(diction):
|
||||
try:
|
||||
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 liste ")
|
||||
return False, " La valeur '" + val + "' n'est pas presente dans liste"
|
||||
|
||||
my_token = ""
|
||||
if ("token" in diction.keys()):
|
||||
if diction['token']:
|
||||
my_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 stagiaire est bien inscrit. Le statut de l'inscription doit etre "1"
|
||||
|
||||
is_inscription_valide = MYSY_GV.dbname['inscription'].count_documents({'_id':ObjectId(str(diction['inscription_id'])),
|
||||
'status':'1',
|
||||
'partner_owner_recid':str(my_partner['recid'])})
|
||||
|
||||
if( is_inscription_valide != 1 ):
|
||||
mycommon.myprint(
|
||||
str(inspect.stack()[0][
|
||||
3]) + " L'identifiant de l'inscription est invalide ")
|
||||
return False, " L'identifiant de l'inscription est invalide "
|
||||
|
||||
RetObject = []
|
||||
val_tmp = 0
|
||||
|
||||
"""
|
||||
# Recuperation des documents (collection : courrier_template) de ce partenaire avec 'ref_interne' = 'CONVENTION_STAGIAIRE'
|
||||
1 - On regarde le partenaire à des conventions qui sont personnalisées, si non
|
||||
2 - On va sortir les conventions par defaut de MySy.
|
||||
|
||||
/!\ : On ne melange pas les 2. c'est l'un ou l'autre
|
||||
"""
|
||||
for retval in MYSY_GV.dbname['courrier_template'].find({'ref_interne':'CONVENTION_STAGIAIRE',
|
||||
'valide':'1',
|
||||
'locked':'0',
|
||||
'partner_owner_recid':str(my_partner['recid'])}):
|
||||
user = retval
|
||||
val_tmp = val_tmp + 1
|
||||
RetObject.append(mycommon.JSONEncoder().encode(user))
|
||||
|
||||
# Si aucune convention personnalisée, on va chercher les conventions mysy
|
||||
if( val_tmp == 0 ):
|
||||
for retval in MYSY_GV.dbname['courrier_template'].find({'ref_interne': 'CONVENTION_STAGIAIRE',
|
||||
'valide': '1',
|
||||
'locked': '0',
|
||||
'partner_owner_recid': 'default'}):
|
||||
user = retval
|
||||
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 conventions"
|
||||
|
|
8589
Log/log_file.log
8589
Log/log_file.log
File diff suppressed because it is too large
Load Diff
86
main.py
86
main.py
|
@ -64,6 +64,7 @@ import Session_Formation_Sequence as Session_Formation_Sequence
|
|||
import base_config_modele_journee as base_config_modele_journee
|
||||
import Dashbord_queries.session_tbd_qries as session_tbd_qries
|
||||
import Dashbord_queries.common_tdb_qries as common_tdb_qries
|
||||
import Dashbord_queries.formation_tbd_qries as formation_tbd_qries
|
||||
|
||||
app = Flask(__name__)
|
||||
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
|
||||
|
@ -3988,6 +3989,23 @@ def UpdateStagiairetoClass_Tuteurs():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API qui permet de recuperer la liste des convention stagiaires
|
||||
"""
|
||||
@app.route('/myclass/api/Get_List_Conventions_Stagiaire/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_List_Conventions_Stagiaire():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_List_Conventions_Stagiaire payload = ",payload)
|
||||
status, retval = inscription.Get_List_Conventions_Stagiaire(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
API qui ajoute une ressource humaine
|
||||
"""
|
||||
|
@ -5810,6 +5828,38 @@ def Get_Qery_Session_Repartition_Session_By_Trainer_By_Periode():
|
|||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API d'export excel/csv des resultats d'un dashbord
|
||||
"""
|
||||
"""
|
||||
@app.route('/myclass/api/Export_Dashbord_To_Csv/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Export_Dashbord_To_Csv():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Export_Dashbord_To_Csv payload = ",payload)
|
||||
status, retval = session_tbd_qries.Export_Dashbord_To_Csv(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
"""
|
||||
|
||||
@app.route('/myclass/api/Export_Dashbord_To_Csv/<token>/<user_dashbord_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Export_Dashbord_To_Csv(token, user_dashbord_id):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
payload = {}
|
||||
payload['token'] = str(token)
|
||||
payload['user_dashbord_id'] = str(user_dashbord_id)
|
||||
|
||||
|
||||
print(" ### Export_Dashbord_To_Csv payload = ",payload)
|
||||
|
||||
status, retval = session_tbd_qries.Export_Dashbord_To_Csv(payload)
|
||||
if(status ):
|
||||
return retval
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
"""
|
||||
API Recuperation de liste des tableaux de bord disponible d'un partenaire (magasin tableaux de bord)
|
||||
|
@ -5864,6 +5914,42 @@ def Delete_To_User_Dashbord():
|
|||
status, retval = common_tdb_qries.Delete_To_User_Dashbord(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
"""
|
||||
API/ TBD / QERY / Formation
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Qery_Formation_By_Session_By_Periode/', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Qery_Formation_By_Session_By_Periode():
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
print(" ### Get_Qery_Formation_By_Session_By_Periode payload = ",payload)
|
||||
status, retval = formation_tbd_qries.Get_Qery_Formation_By_Session_By_Periode(payload)
|
||||
return jsonify(status=status, message=retval)
|
||||
|
||||
|
||||
"""
|
||||
API/ TBD / QERY / Formation ==> Export CSV/EXCEL
|
||||
"""
|
||||
@app.route('/myclass/api/Get_Qery_Formation_By_Session_By_Periode_Export_CSV/<token>/<user_dashbord_id>', methods=['POST','GET'])
|
||||
@crossdomain(origin='*')
|
||||
def Get_Qery_Formation_By_Session_By_Periode_Export_CSV(token, user_dashbord_id):
|
||||
# On recupere le corps (payload) de la requete
|
||||
payload = mycommon.strip_dictionary (request.form.to_dict())
|
||||
payload = {}
|
||||
payload['token'] = str(token)
|
||||
payload['user_dashbord_id'] = str(user_dashbord_id)
|
||||
|
||||
|
||||
print(" ### Get_Qery_Formation_By_Session_By_Periode_Export_CSV payload = ",payload)
|
||||
|
||||
status, retval = formation_tbd_qries.Get_Qery_Formation_By_Session_By_Periode_Export_CSV(payload)
|
||||
if(status ):
|
||||
return retval
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -1333,7 +1333,7 @@ def GerneratePDF_Partner_Invoice(diction):
|
|||
# Verification de la validité de la facture
|
||||
qry = {'_id': ObjectId(str(diction['invoice_id'])), 'valide': '1', 'locked': '0',
|
||||
'partner_owner_recid': str(my_partner['recid'])}
|
||||
print(" ### qry = ", qry)
|
||||
#print(" ### qry = ", qry)
|
||||
|
||||
is_invoice_Existe_Count = MYSY_GV.dbname['partner_invoice_header'].count_documents(
|
||||
{'_id': ObjectId(str(diction['invoice_id'])),
|
||||
|
@ -1421,7 +1421,7 @@ def GerneratePDF_Partner_Invoice(diction):
|
|||
}
|
||||
}
|
||||
]
|
||||
print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
||||
#print("#### Get_Given_Partner_Order_Lines_From_order_ref_interne : query pip= ", query)
|
||||
val_tmp = 0
|
||||
Order_header_lines_data = []
|
||||
for retval in MYSY_GV.dbname['partner_invoice_line'].aggregate(query):
|
||||
|
|
|
@ -3746,3 +3746,75 @@ def Get_Personnalized_Document_From_courrier_template(diction):
|
|||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récuperer le document personnalisé "
|
||||
|
||||
|
||||
"""
|
||||
Get current month date : Cette fontion retoune
|
||||
start_date = 01/m/y
|
||||
end_date = date_jour (jj/mm/aaaa)
|
||||
"""
|
||||
def Get_Current_Month_Start_End_Date():
|
||||
try:
|
||||
|
||||
todays_date = date.today()
|
||||
start_date = "01/"+str(todays_date.month)+"/"+str(todays_date.year)
|
||||
end_date = str(date.today().strftime("%d/%m/%Y"))
|
||||
|
||||
# Verifier que les date sont bien valide
|
||||
local_status = CheckisDate(start_date)
|
||||
if (local_status is False):
|
||||
myprint(str(
|
||||
inspect.stack()[0][3]) + " la date "+str(start_date)+" n'est pas au format jj/mm/aaaa.")
|
||||
return False, " la date "+str(start_date)+" n'est pas au format jj/mm/aaaa.", False
|
||||
|
||||
local_status = CheckisDate(end_date)
|
||||
if (local_status is False):
|
||||
myprint(str(
|
||||
inspect.stack()[0][3]) + " la date " + str(end_date) + " n'est pas au format jj/mm/aaaa.")
|
||||
return False, " la date " + str(end_date) + " n'est pas au format jj/mm/aaaa.", False
|
||||
|
||||
|
||||
return True, start_date, end_date
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récuperer les dates début et fin du mois en cours ", False
|
||||
|
||||
|
||||
"""
|
||||
Get previous month date : Cette fontion retourne le debut et la fin du mois precedent
|
||||
|
||||
"""
|
||||
def Get_Previous_Month_Start_End_Date():
|
||||
try:
|
||||
|
||||
|
||||
this_first = date.today().replace(day=1)
|
||||
prev_last = this_first - timedelta(days=1)
|
||||
prev_first = prev_last.replace(day=1)
|
||||
|
||||
start_date = str(prev_first.strftime("%d/%m/%Y"))
|
||||
end_date = str(prev_last.strftime("%d/%m/%Y"))
|
||||
|
||||
|
||||
# Verifier que les date sont bien valide
|
||||
local_status = CheckisDate(start_date)
|
||||
if (local_status is False):
|
||||
myprint(str(
|
||||
inspect.stack()[0][3]) + " la date "+str(start_date)+" n'est pas au format jj/mm/aaaa.")
|
||||
return False, " la date "+str(start_date)+" n'est pas au format jj/mm/aaaa.", False
|
||||
|
||||
local_status = CheckisDate(end_date)
|
||||
if (local_status is False):
|
||||
myprint(str(
|
||||
inspect.stack()[0][3]) + " la date " + str(end_date) + " n'est pas au format jj/mm/aaaa.")
|
||||
return False, " la date " + str(end_date) + " n'est pas au format jj/mm/aaaa.", False
|
||||
|
||||
|
||||
return True, start_date, end_date
|
||||
|
||||
except Exception as e:
|
||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||
myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
||||
return False, " Impossible de récuperer les dates début et fin du mois en cours ", False
|
Loading…
Reference in New Issue