3762 lines
166 KiB
Python
3762 lines
166 KiB
Python
"""
|
|
Ce fichier permet de gerer les sequences associées à une session de formation. En effet toutes journées ou 1/2 journées de formation
|
|
ne sont pas consecutives.
|
|
Par exemple, une session peut de deroulée sur 2 mois (planning) mais en realité il y une formation tous les 3 jours
|
|
|
|
Ce developpement permet de gerer ce cas.
|
|
"""
|
|
import ast
|
|
|
|
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
|
|
from datetime import timedelta
|
|
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
|
|
|
|
import base_config_modele_journee as base_config_modele_journee
|
|
|
|
|
|
"""
|
|
Regles :
|
|
Pour la meme session, verifier qu'il n'y pas de chevauchement de date
|
|
|
|
"""
|
|
|
|
def Add_Session_Sequence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
|
|
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_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', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', ]
|
|
|
|
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
|
|
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents({'_id':ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if( is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
|
|
# Recuperation des données de la session
|
|
is_existe_valide_session_id_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
|
|
|
|
# Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session.
|
|
date_debut_seq = ""
|
|
if ("sequence_start" in diction.keys()):
|
|
if diction['sequence_start']:
|
|
date_debut_seq = str(diction['sequence_start'])
|
|
local_status = mycommon.CheckisDate_Hours(date_debut_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de debut de séquence " + str(date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
date_fin_seq = ""
|
|
if ("sequence_end" in diction.keys()):
|
|
if diction['sequence_end']:
|
|
date_fin_seq = str(diction['sequence_end'])
|
|
local_status = mycommon.CheckisDate_Hours(date_fin_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
|
|
|
|
if (datetime.strptime(str(date_debut_seq), '%d/%m/%Y %H:%M') >= datetime.strptime(str(date_fin_seq),'%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence "+ str( date_debut_seq)+" ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence "+ str( date_debut_seq)+" "
|
|
|
|
|
|
"""
|
|
04/05/2024 : Controle des chevauchements
|
|
Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver
|
|
|
|
"""""
|
|
check_chevauchement = 1
|
|
if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"):
|
|
check_chevauchement = 0
|
|
|
|
|
|
local_grp_apprenant_id = ""
|
|
if( "grp_apprenant_id" in diction.keys()):
|
|
local_grp_apprenant_id = diction['grp_apprenant_id']
|
|
|
|
local_ue_id = ""
|
|
if ("ue_id" in diction.keys()):
|
|
local_ue_id = diction['ue_id']
|
|
|
|
if( check_chevauchement == 1 and str(diction['type']) == "planning" ):
|
|
for retVal in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'grp_apprenant_id': str(local_grp_apprenant_id),
|
|
'ue_id': str(local_ue_id),
|
|
'valide':'1',
|
|
'locked':'0'}):
|
|
|
|
#print(" #### str(retVal['event_start']) = ", str(retVal['sequence_start']))
|
|
#print(" #### str(retVal['event_end']) = ", str(retVal['sequence_end']))
|
|
|
|
New_retVal_start_date = datetime.strptime(str(retVal['sequence_start']), '%d/%m/%Y %H:%M').strftime("%d/%m/%Y %H:%M")
|
|
New_retVal_end_date = datetime.strptime(str(retVal['sequence_end']), '%d/%m/%Y %H:%M').strftime("%d/%m/%Y %H:%M")
|
|
|
|
#print(" ### New_retVal_start_date = ", New_retVal_start_date)
|
|
#print(" ### New_retVal_end_date = ", New_retVal_end_date)
|
|
|
|
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(str(date_debut_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(str(date_debut_seq), '%d/%m/%Y %H:%M')):
|
|
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de debut de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence"
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(str(date_fin_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(str(date_fin_seq), '%d/%m/%Y %H:%M')):
|
|
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence"
|
|
|
|
sequence_type = "planning"
|
|
if ("type" in diction.keys()):
|
|
sequence_type = str(diction['type'])
|
|
|
|
|
|
sequence_title = ""
|
|
if( "sequence_title" in diction.keys() ):
|
|
sequence_title = str(diction['sequence_title'])
|
|
|
|
agenda = ""
|
|
if ("agenda" in diction.keys()):
|
|
agenda = str(diction['agenda'])
|
|
|
|
objectif = ""
|
|
if ("objectif" in diction.keys()):
|
|
objectif = str(diction['objectif'])
|
|
|
|
commentaire = ""
|
|
if ("commentaire" in diction.keys()):
|
|
commentaire = str(diction['commentaire'])
|
|
|
|
grp_apprenant_id = ""
|
|
if ("grp_apprenant_id" in diction.keys() and diction['grp_apprenant_id']):
|
|
grp_apprenant_id = str(diction['grp_apprenant_id'])
|
|
is_valide_grp_apprenant_id = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['grp_apprenant_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_grp_apprenant_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
ue_id = ""
|
|
if ("ue_id" in diction.keys() and diction['ue_id']):
|
|
ue_id = str(diction['ue_id'])
|
|
is_valide_ue_id = MYSY_GV.dbname['unite_enseignement'].count_documents({'_id':ObjectId(str( diction['ue_id'])),
|
|
'valide':'1', 'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])})
|
|
if(is_valide_ue_id != 1 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de l'unité d'enseignement est invalide "
|
|
|
|
new_session_formation_sequence_id = ""
|
|
ue_planif_line_id = ""
|
|
if ("ue_id" in diction.keys() and diction['ue_id'] and "ue_planif_line_id" in diction.keys() and diction[
|
|
'ue_planif_line_id']):
|
|
ue_planif_line_id = str(diction['ue_planif_line_id'])
|
|
|
|
is_valide_unite_enseignement_planif_id = MYSY_GV.dbname['unite_enseignement_planif'].count_documents(
|
|
{'_id': ObjectId(str(diction['ue_planif_line_id'])),
|
|
'ue_id': str(diction['ue_id']),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
})
|
|
if (is_valide_unite_enseignement_planif_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la ligne de planification de unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de la ligne de planification de unité d'enseignement est invalide "
|
|
|
|
"""
|
|
is_valide_unite_enseignement_planif_id_data = MYSY_GV.dbname['unite_enseignement_planif'].find_one(
|
|
{'_id': ObjectId(str(diction['ue_planif_line_id'])),
|
|
'ue_id': str(diction['ue_id']),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
})
|
|
|
|
if(is_valide_unite_enseignement_planif_id_data and "session_formation_sequence_id" in is_valide_unite_enseignement_planif_id_data.keys() and
|
|
is_valide_unite_enseignement_planif_id_data['session_formation_sequence_id']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La ligne de planification de unité d'enseignement est actuellement utilisé. Impossible d'associer à cette ligne à une nouvelle séquence ")
|
|
return False, " La ligne de planification de unité d'enseignement est actuellement utilisé. Impossible d'associer à cette ligne à une nouvelle séquence "
|
|
"""
|
|
|
|
|
|
|
|
my_data = {}
|
|
my_data['session_id'] = str(diction['session_id'])
|
|
my_data['type'] = sequence_type
|
|
my_data['sequence_title'] = sequence_title
|
|
my_data['sequence_start'] = date_debut_seq
|
|
my_data['sequence_end'] = date_fin_seq
|
|
|
|
my_data['agenda'] = agenda
|
|
my_data['objectif'] = objectif
|
|
my_data['commentaire'] = commentaire
|
|
|
|
my_data['grp_apprenant_id'] = grp_apprenant_id
|
|
my_data['ue_id'] = ue_id
|
|
my_data['unite_enseignement_planif_id'] = ue_planif_line_id
|
|
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
my_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
my_data['update_by'] = str(my_partner['_id'])
|
|
|
|
|
|
local_retval = MYSY_GV.dbname['session_formation_sequence'].insert_one(my_data)
|
|
|
|
new_session_formation_sequence_id = str(local_retval.inserted_id)
|
|
"""
|
|
Si la mise à jour fonction et qu'on a bien un update_data['ue_planif_line_id'] = str(diction['ue_planif_line_id'])
|
|
alors on met à jour la ligne de la collection : unite_enseignement_planif.
|
|
|
|
1 - On programme le nouvelle ligne de planification
|
|
|
|
|
|
"""
|
|
if (ue_planif_line_id ):
|
|
|
|
# Programmation de la nouvelle
|
|
update_data = {}
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['session_formation_sequence_id'] = str(new_session_formation_sequence_id)
|
|
|
|
update = MYSY_GV.dbname['unite_enseignement_planif'].update_one(
|
|
{'_id': ObjectId(str(ue_planif_line_id)),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{'$set': update_data}
|
|
)
|
|
|
|
return True, " La séquence a été correctement ajoutée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible d'ajouter la séquence "
|
|
|
|
|
|
"""
|
|
Ajout d'une requence avec retour des données de la sequence ajoutée
|
|
|
|
"""
|
|
|
|
|
|
def Add_Session_Sequence_Return_New_Seq_Data(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
|
|
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_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", False
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', ]
|
|
|
|
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", False
|
|
|
|
"""
|
|
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, False
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide ", False
|
|
|
|
# Recuperation des données de la session
|
|
is_existe_valide_session_id_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
# Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session.
|
|
date_debut_seq = ""
|
|
if ("sequence_start" in diction.keys()):
|
|
if diction['sequence_start']:
|
|
date_debut_seq = str(diction['sequence_start'])
|
|
local_status = mycommon.CheckisDate_Hours(date_debut_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de debut de séquence " + str(
|
|
date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'", False
|
|
|
|
date_fin_seq = ""
|
|
if ("sequence_end" in diction.keys()):
|
|
if diction['sequence_end']:
|
|
date_fin_seq = str(diction['sequence_end'])
|
|
local_status = mycommon.CheckisDate_Hours(date_fin_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'", False
|
|
|
|
if (datetime.strptime(str(date_debut_seq), '%d/%m/%Y %H:%M') >= datetime.strptime(str(date_fin_seq),
|
|
'%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence " + str(
|
|
date_debut_seq) + " ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence " + str(date_debut_seq) + " ", False
|
|
|
|
"""
|
|
04/05/2024 : Controle des chevauchements
|
|
Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver
|
|
|
|
"""""
|
|
check_chevauchement = 1
|
|
if ("check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"):
|
|
check_chevauchement = 0
|
|
|
|
local_grp_apprenant_id = ""
|
|
if ("grp_apprenant_id" in diction.keys()):
|
|
local_grp_apprenant_id = diction['grp_apprenant_id']
|
|
|
|
local_ue_id = ""
|
|
if ("ue_id" in diction.keys()):
|
|
local_ue_id = diction['ue_id']
|
|
|
|
if (check_chevauchement == 1 and str(diction['type']) == "planning"):
|
|
for retVal in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'grp_apprenant_id': str(
|
|
local_grp_apprenant_id),
|
|
'ue_id': str(local_ue_id),
|
|
'valide': '1',
|
|
'locked': '0'}):
|
|
|
|
# print(" #### str(retVal['event_start']) = ", str(retVal['sequence_start']))
|
|
# print(" #### str(retVal['event_end']) = ", str(retVal['sequence_end']))
|
|
|
|
New_retVal_start_date = datetime.strptime(str(retVal['sequence_start']), '%d/%m/%Y %H:%M').strftime(
|
|
"%d/%m/%Y %H:%M")
|
|
New_retVal_end_date = datetime.strptime(str(retVal['sequence_end']), '%d/%m/%Y %H:%M').strftime(
|
|
"%d/%m/%Y %H:%M")
|
|
|
|
# print(" ### New_retVal_start_date = ", New_retVal_start_date)
|
|
# print(" ### New_retVal_end_date = ", New_retVal_end_date)
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(
|
|
str(date_debut_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(
|
|
str(date_debut_seq), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de debut de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence", False
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(
|
|
str(date_fin_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(
|
|
str(date_fin_seq), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_debut_seq) + " chevauche une autre séquence", False
|
|
|
|
sequence_type = "planning"
|
|
if ("type" in diction.keys()):
|
|
sequence_type = str(diction['type'])
|
|
|
|
sequence_title = ""
|
|
if ("sequence_title" in diction.keys()):
|
|
sequence_title = str(diction['sequence_title'])
|
|
|
|
agenda = ""
|
|
if ("agenda" in diction.keys()):
|
|
agenda = str(diction['agenda'])
|
|
|
|
objectif = ""
|
|
if ("objectif" in diction.keys()):
|
|
objectif = str(diction['objectif'])
|
|
|
|
commentaire = ""
|
|
if ("commentaire" in diction.keys()):
|
|
commentaire = str(diction['commentaire'])
|
|
|
|
grp_apprenant_id = ""
|
|
if ("grp_apprenant_id" in diction.keys() and diction['grp_apprenant_id']):
|
|
grp_apprenant_id = str(diction['grp_apprenant_id'])
|
|
is_valide_grp_apprenant_id = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['grp_apprenant_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_grp_apprenant_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide ", False
|
|
|
|
ue_id = ""
|
|
if ("ue_id" in diction.keys() and diction['ue_id']):
|
|
ue_id = str(diction['ue_id'])
|
|
is_valide_ue_id = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
|
{'_id': ObjectId(str(diction['ue_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_ue_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de l'unité d'enseignement est invalide ", False
|
|
|
|
new_session_formation_sequence_id = ""
|
|
ue_planif_line_id = ""
|
|
if ("ue_id" in diction.keys() and diction['ue_id'] and "ue_planif_line_id" in diction.keys() and diction[
|
|
'ue_planif_line_id']):
|
|
ue_planif_line_id = str(diction['ue_planif_line_id'])
|
|
|
|
is_valide_unite_enseignement_planif_id = MYSY_GV.dbname['unite_enseignement_planif'].count_documents(
|
|
{'_id': ObjectId(str(diction['ue_planif_line_id'])),
|
|
'ue_id': str(diction['ue_id']),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
})
|
|
if (is_valide_unite_enseignement_planif_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " L'identifiant de la ligne de planification de unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de la ligne de planification de unité d'enseignement est invalide ", False
|
|
|
|
"""
|
|
is_valide_unite_enseignement_planif_id_data = MYSY_GV.dbname['unite_enseignement_planif'].find_one(
|
|
{'_id': ObjectId(str(diction['ue_planif_line_id'])),
|
|
'ue_id': str(diction['ue_id']),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
})
|
|
|
|
if(is_valide_unite_enseignement_planif_id_data and "session_formation_sequence_id" in is_valide_unite_enseignement_planif_id_data.keys() and
|
|
is_valide_unite_enseignement_planif_id_data['session_formation_sequence_id']):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La ligne de planification de unité d'enseignement est actuellement utilisé. Impossible d'associer à cette ligne à une nouvelle séquence ")
|
|
return False, " La ligne de planification de unité d'enseignement est actuellement utilisé. Impossible d'associer à cette ligne à une nouvelle séquence "
|
|
"""
|
|
|
|
my_data = {}
|
|
my_data['session_id'] = str(diction['session_id'])
|
|
my_data['type'] = sequence_type
|
|
my_data['sequence_title'] = sequence_title
|
|
my_data['sequence_start'] = date_debut_seq
|
|
my_data['sequence_end'] = date_fin_seq
|
|
|
|
my_data['agenda'] = agenda
|
|
my_data['objectif'] = objectif
|
|
my_data['commentaire'] = commentaire
|
|
|
|
my_data['grp_apprenant_id'] = grp_apprenant_id
|
|
my_data['ue_id'] = ue_id
|
|
my_data['unite_enseignement_planif_id'] = ue_planif_line_id
|
|
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
my_data['partner_owner_recid'] = str(my_partner['recid'])
|
|
my_data['update_by'] = str(my_partner['_id'])
|
|
|
|
local_retval = MYSY_GV.dbname['session_formation_sequence'].insert_one(my_data)
|
|
|
|
"""
|
|
recuperation des données inserées
|
|
"""
|
|
inserted_seq_data = None
|
|
RetObject = []
|
|
val_tmp = 0
|
|
if( local_retval and local_retval.inserted_id ):
|
|
for inserted_seq_data in MYSY_GV.dbname['session_formation_sequence'].find({'_id':ObjectId(str(local_retval.inserted_id)),'partner_owner_recid':str(my_partner['recid'])}):
|
|
user = inserted_seq_data
|
|
user['id'] = str(inserted_seq_data)
|
|
val_tmp = val_tmp + 1
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
else:
|
|
return False, "Impossible d'ajouter la séquence (2) ",False
|
|
|
|
|
|
|
|
new_session_formation_sequence_id = str(local_retval.inserted_id)
|
|
"""
|
|
Si la mise à jour fonction et qu'on a bien un update_data['ue_planif_line_id'] = str(diction['ue_planif_line_id'])
|
|
alors on met à jour la ligne de la collection : unite_enseignement_planif.
|
|
|
|
1 - On programme le nouvelle ligne de planification
|
|
|
|
|
|
"""
|
|
if (ue_planif_line_id):
|
|
# Programmation de la nouvelle
|
|
update_data = {}
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['session_formation_sequence_id'] = str(new_session_formation_sequence_id)
|
|
|
|
update = MYSY_GV.dbname['unite_enseignement_planif'].update_one(
|
|
{'_id': ObjectId(str(ue_planif_line_id)),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{'$set': update_data}
|
|
)
|
|
|
|
return True, "La séquence a été correctement ajoutée", 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 d'ajouter la séquence ", False
|
|
|
|
|
|
"""
|
|
Fonction de Creation automatique de sequence.
|
|
Pour certains utilisteurs, au lieu de créer manuellement chaque sequence,
|
|
ils laisse le système créer toutes les sequence.
|
|
|
|
Alogo :
|
|
1 - Si la session est valide, on supprime toutes les sequences existantes pour cette session (y compris les plannings)
|
|
2 - on prend en entrée le modele de journé à appliquer (heures de la journée, jours de la semaine)
|
|
3 - Pour chaque ressource rattachée à session, on va aller faire les reservation d'agenda : ATTENTION
|
|
-> NOTE : On ne va pas ajouté les ressources tout de suite. Apres la creation, on donnera la possiblité de choisir plusieurs (voir toutes)
|
|
les sequence, puis proposer l'ajout en masse d'une ressource.
|
|
|
|
"""
|
|
|
|
def Create_Automatic_Sequence_ORIG(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'jounree_modele_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', 'session_id', 'jounree_modele_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
|
|
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents({'_id':ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if( is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
"""
|
|
Si le "jounree_modele_id" est vide, cela veut dire qu'il faut aller chercher le modele par default
|
|
"""
|
|
jounree_modele_id = ""
|
|
if( str(diction['jounree_modele_id']) == "" ):
|
|
jounree_modele_data = MYSY_GV.dbname['base_config_modele_journee'].find_one({'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked':'0'})
|
|
|
|
if( jounree_modele_data is None ):
|
|
# On ne trouve pas de modele par defaut pour ce client. On va aller le chercher le modele par defaut de MySy
|
|
jounree_modele_data_mysy = MYSY_GV.dbname['base_config_modele_journee'].find_one(
|
|
{'partner_owner_recid': "default", 'valide': '1', 'locked': '0'})
|
|
|
|
if( jounree_modele_data_mysy is None ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée n'est configuré dans le système ")
|
|
return False, " Aucun modèle de journée n'est configuré dans le système "
|
|
|
|
|
|
jounree_modele_id = str(jounree_modele_data_mysy['_id'])
|
|
|
|
|
|
else:
|
|
jounree_modele_id = str(jounree_modele_data['_id'])
|
|
|
|
|
|
else:
|
|
jounree_modele_id = str(diction['jounree_modele_id'])
|
|
|
|
|
|
|
|
if (str(jounree_modele_id).strip() == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée n'est configuré dans le système (2) ")
|
|
return False, " Aucun modèle de journée n'est configuré dans le système (2) "
|
|
|
|
|
|
|
|
# Verification de l'existence du modele de journée
|
|
is_existe_valide_journee_model_id = MYSY_GV.dbname["base_config_modele_journee"].count_documents(
|
|
{'_id': ObjectId(str(jounree_modele_id)) ,
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked':'0'})
|
|
|
|
if (is_existe_valide_journee_model_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du modèle de journee n'est pas valide ")
|
|
return False, " L'identifiant du modèle de journee n'est pas valide "
|
|
|
|
|
|
# Recuperation des data de la journée modele
|
|
is_existe_valide_journee_model_data= MYSY_GV.dbname["base_config_modele_journee"].find_one(
|
|
{'_id': ObjectId(str(jounree_modele_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
"""
|
|
for local_val in is_existe_valide_journee_model_data['tab_sequence']:
|
|
model_heure_debut = local_val['heure_debut']
|
|
model_heure_fin = local_val['heure_fin']
|
|
|
|
local_status = mycommon.CheckisDate_Hours(model_heure_debut)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
model_heure_debut) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de debut de séquence " + str(
|
|
model_heure_debut) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
|
|
local_status = mycommon.CheckisDate_Hours(model_heure_fin)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
model_heure_fin) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de fin de séquence " + str(
|
|
model_heure_fin) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
"""""
|
|
|
|
|
|
is_existe_valide_session_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
date_debut_session = ""
|
|
if ("date_debut" in is_existe_valide_session_data.keys()):
|
|
if is_existe_valide_session_data['date_debut']:
|
|
date_debut_session = str(is_existe_valide_session_data['date_debut'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_debut_session)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de session " + str(
|
|
date_debut_session) + " n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de debut de session " + str(
|
|
date_debut_session) + " n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
date_fin_session = ""
|
|
if ("date_fin" in is_existe_valide_session_data.keys()):
|
|
if is_existe_valide_session_data['date_fin']:
|
|
date_fin_session = str(is_existe_valide_session_data['date_fin'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_fin_session)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de session " + str(
|
|
date_fin_session) + " n'est pas au format 'jj/mm/aaaa'")
|
|
return False, " La date de fin de session " + str(
|
|
date_fin_session) + " n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
date_debut_session = datetime.strptime(str(date_debut_session), '%d/%m/%Y')
|
|
date_fin_session = datetime.strptime(str(date_fin_session), '%d/%m/%Y')
|
|
|
|
|
|
liste_jours_travaille = []
|
|
liste_jours_travaille_code_day = []
|
|
if ("jours" in is_existe_valide_journee_model_data.keys()):
|
|
for jour in is_existe_valide_journee_model_data['jours']:
|
|
if (str(jour['travail']) == "1"):
|
|
liste_jours_travaille.append(str(jour['jour']))
|
|
liste_jours_travaille_code_day.append(str(jour['day_name']))
|
|
|
|
"""
|
|
/!\ Suppression des sequences qui existe et reservation dans les agenda par rapport à cette session
|
|
"""
|
|
for local_retval in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),}):
|
|
|
|
|
|
deleted_data_agenda = MYSY_GV.dbname['agenda'].delete_many({'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
deleted_data_affectation = MYSY_GV.dbname['session_formation_sequence_affectation'].delete_many({'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),})
|
|
|
|
|
|
deleted_data_sequence = MYSY_GV.dbname['session_formation_sequence'].delete_many({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),})
|
|
|
|
cpt = 10
|
|
|
|
nb_sequence = 0
|
|
|
|
for single_date in mycommon.daterange(date_debut_session, date_fin_session):
|
|
#print(single_date.strftime("%Y-%m-%d"))
|
|
#print(single_date.strftime("%A"))
|
|
|
|
#print(" Les date off sont : ", is_existe_valide_journee_model_data['date_off'])
|
|
date_jour = str(single_date.strftime("%Y-%m-%d"))
|
|
jour_name = single_date.strftime("%A")
|
|
|
|
# Recuperation des sequences associées à jour_name
|
|
jours_name_list_sequence = is_existe_valide_journee_model_data[jour_name]["tab_sequence"]
|
|
|
|
#print(" ### les sequences du ", jour_name, " sont ", jours_name_list_sequence)
|
|
# Pour chaque sequence de la journée
|
|
if (date_jour not in is_existe_valide_journee_model_data['date_off']):
|
|
for local_val in jours_name_list_sequence :
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = "Seq_Auto_" + str(cpt)
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(
|
|
local_val['heure_debut']).strip()
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(
|
|
local_val['heure_fin']).strip()
|
|
|
|
print(" ### sequence_data = ", sequence_data)
|
|
|
|
local_status, local_val = Add_Session_Sequence(sequence_data)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_val))
|
|
else:
|
|
nb_sequence = nb_sequence +1
|
|
|
|
cpt = cpt + 1
|
|
|
|
|
|
|
|
return True, str(nb_sequence)+" séquence(s) automatiquement créée(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 créer automatiquement les séquences "
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction des sequences automatiques en travaillant en fonction des options :
|
|
- option = 0 ==> on prend le calendrier
|
|
- option = 1 ==> on prend la demi-journée
|
|
- option = 2 ==> on prend la journée
|
|
"""
|
|
|
|
|
|
def Create_Automatic_Sequence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'jounree_modele_id', 'option', 'ecrase_existing' ]
|
|
|
|
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', 'session_id', 'jounree_modele_id', 'option' ]
|
|
|
|
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']
|
|
|
|
|
|
if( diction['option'] not in MYSY_GV.EMARGEMENT_OPTION ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " La valeur '" + diction['option'] + "' n'est pas autorisé. Les valeurs autorisées sont : "+str(MYSY_GV.EMARGEMENT_OPTION))
|
|
return False, " La valeur '" + diction['option'] + "' n'est pas autorisé. Les valeurs autorisées sont : "+str(MYSY_GV.EMARGEMENT_OPTION)
|
|
|
|
|
|
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
"""
|
|
Si le "jounree_modele_id" est vide, cela veut dire qu'il faut aller chercher le modele par default
|
|
"""
|
|
jounree_modele_id = ""
|
|
if (str(diction['jounree_modele_id']) == ""):
|
|
jounree_modele_data = MYSY_GV.dbname['base_config_modele_journee'].find_one(
|
|
{'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (jounree_modele_data is None):
|
|
# On ne trouve pas de modele par defaut pour ce client. On va aller le chercher le modele par defaut de MySy
|
|
jounree_modele_data_mysy = MYSY_GV.dbname['base_config_modele_journee'].find_one(
|
|
{'partner_owner_recid': "default", 'valide': '1', 'locked': '0'})
|
|
|
|
if (jounree_modele_data_mysy is None):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée n'est configuré dans le système ")
|
|
return False, " Aucun modèle de journée n'est configuré dans le système "
|
|
|
|
jounree_modele_id = str(jounree_modele_data_mysy['_id'])
|
|
|
|
|
|
else:
|
|
jounree_modele_id = str(jounree_modele_data['_id'])
|
|
|
|
|
|
else:
|
|
jounree_modele_id = str(diction['jounree_modele_id'])
|
|
|
|
if (str(jounree_modele_id).strip() == ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - Aucun modèle de journée n'est configuré dans le système (2) ")
|
|
return False, " Aucun modèle de journée n'est configuré dans le système (2) "
|
|
|
|
# Verification de l'existence du modele de journée
|
|
is_existe_valide_journee_model_id = MYSY_GV.dbname["base_config_modele_journee"].count_documents(
|
|
{'_id': ObjectId(str(jounree_modele_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
if (is_existe_valide_journee_model_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant du modèle de journee n'est pas valide ")
|
|
return False, " L'identifiant du modèle de journee n'est pas valide "
|
|
|
|
# Recuperation des data de la journée modele
|
|
is_existe_valide_journee_model_data = MYSY_GV.dbname["base_config_modele_journee"].find_one(
|
|
{'_id': ObjectId(str(jounree_modele_id)),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
is_existe_valide_session_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
date_debut_session = ""
|
|
if ("date_debut" in is_existe_valide_session_data.keys()):
|
|
if is_existe_valide_session_data['date_debut']:
|
|
date_debut_session = str(is_existe_valide_session_data['date_debut'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_debut_session)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de session " + str(
|
|
date_debut_session) + " n'est pas au format 'jj/mm/aaaa' ")
|
|
return False, " La date de debut de session " + str(
|
|
date_debut_session) + " n'est pas au format 'jj/mm/aaaa' "
|
|
|
|
date_fin_session = ""
|
|
if ("date_fin" in is_existe_valide_session_data.keys()):
|
|
if is_existe_valide_session_data['date_fin']:
|
|
date_fin_session = str(is_existe_valide_session_data['date_fin'])[0:10]
|
|
local_status = mycommon.CheckisDate(date_fin_session)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de session " + str(
|
|
date_fin_session) + " n'est pas au format 'jj/mm/aaaa'")
|
|
return False, " La date de fin de session " + str(
|
|
date_fin_session) + " n'est pas au format 'jj/mm/aaaa'"
|
|
|
|
|
|
date_debut_session = datetime.strptime(str(date_debut_session), '%d/%m/%Y')
|
|
date_fin_session = datetime.strptime(str(date_fin_session), '%d/%m/%Y')
|
|
|
|
liste_jours_travaille = []
|
|
liste_jours_travaille_code_day = []
|
|
if ("jours" in is_existe_valide_journee_model_data.keys()):
|
|
for jour in is_existe_valide_journee_model_data['jours']:
|
|
if (str(jour['travail']) == "1"):
|
|
liste_jours_travaille.append(str(jour['jour']))
|
|
liste_jours_travaille_code_day.append(str(jour['day_name']))
|
|
|
|
"""
|
|
/!\ Suppression des sequences qui existe et reservation dans les agenda par rapport à cette session
|
|
"""
|
|
if( "ecrase_existing" in diction.keys() and diction['ecrase_existing'] == "1"):
|
|
for local_retval in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), }):
|
|
deleted_data_agenda = MYSY_GV.dbname['agenda'].delete_many({'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), })
|
|
|
|
deleted_data_affectation = MYSY_GV.dbname['session_formation_sequence_affectation'].delete_many(
|
|
{'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
deleted_data_sequence = MYSY_GV.dbname['session_formation_sequence'].delete_many(
|
|
{'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
cpt = 10
|
|
|
|
nb_sequence = 0
|
|
|
|
|
|
for single_date in mycommon.daterange(date_debut_session, date_fin_session):
|
|
#print(single_date.strftime("%Y-%m-%d"))
|
|
#print(single_date.strftime("%A"))
|
|
|
|
# print(" Les date off sont : ", is_existe_valide_journee_model_data['date_off'])
|
|
date_jour = str(single_date.strftime("%Y-%m-%d"))
|
|
jour_name = single_date.strftime("%A")
|
|
|
|
# Recuperation des sequences associées à jour_name
|
|
jours_name_list_sequence = is_existe_valide_journee_model_data[jour_name]["tab_sequence"]
|
|
|
|
# print(" ### les sequences du ", jour_name, " sont ", jours_name_list_sequence)
|
|
## Sequences / Emargement à la demi journée (matin & apres midi )
|
|
if( diction['option'] == "1"):
|
|
# Sequences / Emargement à la demi journée (matin & apres midi )
|
|
|
|
#Verifer que le jour n'est pas off. (ex : les dimanches sont paramettré comme off)
|
|
is_off_day_of_week = "0"
|
|
if (str(jour_name) in is_existe_valide_journee_model_data.keys()):
|
|
is_off_day_of_week = is_existe_valide_journee_model_data[str(jour_name)]['is_off_day']
|
|
|
|
|
|
# Verifier que ce n'est pas une date off (ex : 01/01/aaaa)
|
|
if (date_jour not in is_existe_valide_journee_model_data['date_off'] and is_off_day_of_week != "1"):
|
|
# La sequence de la matinée
|
|
|
|
# Recuperation des heures de debut et fin des matinée et appres midi
|
|
matine_heure_debut = ""
|
|
matine_heure_fin = ""
|
|
apres_midi_heure_debut = ""
|
|
apres_midi_heure_fin = ""
|
|
|
|
if( "decoupage_journee" in is_existe_valide_journee_model_data.keys()):
|
|
if( "matinee_debut" in is_existe_valide_journee_model_data['decoupage_journee'].keys() ):
|
|
matine_heure_debut = is_existe_valide_journee_model_data['decoupage_journee']['matinee_debut']
|
|
|
|
if ("matinee_fin" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
matine_heure_fin = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'matinee_fin']
|
|
|
|
if ("apres_midi_debut" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
apres_midi_heure_debut = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'apres_midi_debut']
|
|
|
|
if ("apres_midi_fin" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
apres_midi_heure_fin = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'apres_midi_fin']
|
|
|
|
if( matine_heure_debut == "" or matine_heure_fin == "" or apres_midi_heure_debut == "" or apres_midi_heure_fin == ""):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][3]) + " La configuration de decoupage de la journée en matinée et apres midi est invalide ")
|
|
return False, " La configuration de decoupage de la journée en matinée et apres midi est invalide "
|
|
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = "Seq_Auto_" + str(cpt)
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(matine_heure_debut)
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(matine_heure_fin)
|
|
|
|
local_status, local_val = Add_Session_Sequence(sequence_data)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_val))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
# La sequence de la l'apres midi
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = "Seq_Auto_" + str(cpt)
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(apres_midi_heure_debut)
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(apres_midi_heure_fin)
|
|
|
|
local_status, local_val = Add_Session_Sequence(sequence_data)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_val))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
|
|
|
|
cpt = cpt + 1
|
|
|
|
# Pour chaque sequence de la journée
|
|
elif (diction['option'] == "2"):
|
|
# Sequences / Emargement à la journée
|
|
|
|
|
|
# Verifer que le jour n'est pas off. (ex : les dimanches sont paramettré comme off)
|
|
is_off_day_of_week = "0"
|
|
if (str(jour_name) in is_existe_valide_journee_model_data.keys()):
|
|
is_off_day_of_week = is_existe_valide_journee_model_data[str(jour_name)]['is_off_day']
|
|
|
|
|
|
if (date_jour not in is_existe_valide_journee_model_data['date_off'] and is_off_day_of_week != "1"):
|
|
|
|
# Recuperation des heures de debut et fin des matinée et appres midi
|
|
matine_heure_debut = ""
|
|
matine_heure_fin = ""
|
|
apres_midi_heure_debut = ""
|
|
apres_midi_heure_fin = ""
|
|
|
|
if ("decoupage_journee" in is_existe_valide_journee_model_data.keys()):
|
|
if ("matinee_debut" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
matine_heure_debut = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'matinee_debut']
|
|
|
|
if ("matinee_fin" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
matine_heure_fin = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'matinee_fin']
|
|
|
|
if ("apres_midi_debut" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
apres_midi_heure_debut = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'apres_midi_debut']
|
|
|
|
if ("apres_midi_fin" in is_existe_valide_journee_model_data['decoupage_journee'].keys()):
|
|
apres_midi_heure_fin = is_existe_valide_journee_model_data['decoupage_journee'][
|
|
'apres_midi_fin']
|
|
if (
|
|
matine_heure_debut == "" or matine_heure_fin == "" or apres_midi_heure_debut == "" or apres_midi_heure_fin == ""):
|
|
mycommon.myprint(str(
|
|
inspect.stack()[0][
|
|
3]) + " La configuration de decoupage de la journée en matinée et apres midi est invalide ")
|
|
return False, " La configuration de decoupage de la journée en matinée et apres midi est invalide "
|
|
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = "Seq_Auto_" + str(cpt)
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(matine_heure_debut)
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " "+str(apres_midi_heure_fin)
|
|
|
|
|
|
local_status, local_val = Add_Session_Sequence(sequence_data)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_val))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
cpt = cpt + 1
|
|
|
|
else:
|
|
|
|
# Si pas la journée, ni la demi journée alors on crée les sequences selon le calendrier
|
|
# print(" ### les sequences du ", jour_name, " sont ", jours_name_list_sequence)
|
|
# Pour chaque sequence de la journée
|
|
if (date_jour not in is_existe_valide_journee_model_data['date_off']):
|
|
for local_val in jours_name_list_sequence:
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = "Seq_Auto_" + str(cpt)
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(
|
|
local_val['heure_debut']).strip()
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(
|
|
local_val['heure_fin']).strip()
|
|
|
|
local_status, local_val = Add_Session_Sequence(sequence_data)
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_val))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
cpt = cpt + 1
|
|
|
|
return True, str(nb_sequence) + " séquence(s) automatiquement créée(s) ", str(nb_sequence)
|
|
|
|
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 automatiquement les séquences "
|
|
|
|
|
|
|
|
"""
|
|
Mise à jour d'une sequence
|
|
"""
|
|
|
|
def Update_Session_Sequence(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '_id', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', 'agenda', 'objectif',
|
|
'commentaire', 'check_chevauchement', 'grp_apprenant_id', 'ue_id', 'type', 'ue_planif_line_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', 'session_id', 'sequence_title', 'sequence_start', 'sequence_end', ]
|
|
|
|
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
|
|
|
|
|
|
|
|
# Verification de l'existence d'une sequence à mettre à jour
|
|
is_existe_valide_session_sequence_id = MYSY_GV.dbname["session_formation_sequence"].count_documents({'_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1',
|
|
'locked':'0'})
|
|
|
|
if (is_existe_valide_session_sequence_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la séquence n'est pas valide ")
|
|
return False, " L'identifiant de la séquence n'est pas valide "
|
|
|
|
old_unite_enseignement_planif_id = ""
|
|
is_existe_valide_session_sequence_id_data = MYSY_GV.dbname["session_formation_sequence"].find_one(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if( is_existe_valide_session_sequence_id_data and "unite_enseignement_planif_id" in is_existe_valide_session_sequence_id_data.keys() ):
|
|
old_unite_enseignement_planif_id = is_existe_valide_session_sequence_id_data['unite_enseignement_planif_id']
|
|
|
|
|
|
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents({'_id':ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']),
|
|
'valide':'1'})
|
|
|
|
if( is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
# Verifier qu'il n'y a pas de chevauchement de date avec une autre sequence de la meme session.
|
|
date_debut_seq = ""
|
|
if ("sequence_start" in diction.keys()):
|
|
if diction['sequence_start']:
|
|
date_debut_seq = str(diction['sequence_start'])
|
|
local_status = mycommon.CheckisDate_Hours(date_debut_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence " + str(
|
|
date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de debut de séquence " + str(
|
|
date_debut_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
date_fin_seq = ""
|
|
if ("sequence_end" in diction.keys()):
|
|
if diction['sequence_end']:
|
|
date_fin_seq = str(diction['sequence_end'])
|
|
local_status = mycommon.CheckisDate_Hours(date_fin_seq)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm' ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " n'est pas au format 'jj/mm/aaaa hh:mm'"
|
|
|
|
if (datetime.strptime(str(date_debut_seq), '%d/%m/%Y %H:%M') >= datetime.strptime(str(date_fin_seq),
|
|
'%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence " + str(
|
|
date_debut_seq) + " ")
|
|
return False, " La date de fin de séquence " + str(
|
|
date_fin_seq) + " doit être postérieure à la date de début de séquence " + str(date_debut_seq) + " "
|
|
|
|
|
|
"""
|
|
04/05/2024 : Controle des chevauchements
|
|
Par defaut on fait des controle de chevauchement, sauf si on decide de la desactiver
|
|
|
|
"""""
|
|
check_chevauchement = 1
|
|
if( "check_chevauchement" in diction.keys() and diction['check_chevauchement'] == "0"):
|
|
check_chevauchement = 0
|
|
|
|
if( check_chevauchement == 1 and str(diction['type']) == "planning"):
|
|
for retVal in MYSY_GV.dbname['session_formation_sequence'].find({'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0',
|
|
'grp_apprenant_id': str(
|
|
diction['grp_apprenant_id']),
|
|
'ue_id': str(
|
|
diction['ue_id']),
|
|
'_id': {'$ne': ObjectId(
|
|
str(diction['_id']))}
|
|
}):
|
|
|
|
|
|
|
|
New_retVal_start_date = datetime.strptime(str(retVal['sequence_start']), '%d/%m/%Y %H:%M').strftime(
|
|
"%d/%m/%Y %H:%M")
|
|
New_retVal_end_date = datetime.strptime(str(retVal['sequence_end']), '%d/%m/%Y %H:%M').strftime(
|
|
"%d/%m/%Y %H:%M")
|
|
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(
|
|
str(date_debut_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(
|
|
str(date_debut_seq), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut de séquence" + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de debut de séquence" + str(
|
|
date_debut_seq) + " chevauche une autre séquence"
|
|
|
|
if (datetime.strptime(str(New_retVal_start_date), '%d/%m/%Y %H:%M') <= datetime.strptime(
|
|
str(date_fin_seq), '%d/%m/%Y %H:%M') and
|
|
datetime.strptime(str(New_retVal_end_date), '%d/%m/%Y %H:%M') >= datetime.strptime(
|
|
str(date_fin_seq), '%d/%m/%Y %H:%M')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin de séquence" + str(
|
|
date_debut_seq) + " chevauche une autre séquence ")
|
|
return False, " La date de fin de séquence" + str(
|
|
date_debut_seq) + " chevauche une autre séquence"
|
|
|
|
update_data = {}
|
|
|
|
if ("type" in diction.keys()):
|
|
update_data['type'] = str(diction['type'])
|
|
|
|
if ("sequence_title" in diction.keys()):
|
|
update_data['sequence_title'] = str(diction['sequence_title'])
|
|
|
|
if ("agenda" in diction.keys()):
|
|
update_data['agenda'] = str(diction['agenda'])
|
|
|
|
if ("objectif" in diction.keys()):
|
|
update_data['objectif'] = str(diction['objectif'])
|
|
|
|
|
|
|
|
if ("commentaire" in diction.keys()):
|
|
update_data['commentaire'] = str(diction['commentaire'])
|
|
|
|
if ("grp_apprenant_id" in diction.keys() and diction['grp_apprenant_id']):
|
|
update_data['grp_apprenant_id'] = str(diction['grp_apprenant_id'])
|
|
grp_apprenant_id = str(diction['grp_apprenant_id'])
|
|
is_valide_grp_apprenant_id = MYSY_GV.dbname['groupe_inscription'].count_documents(
|
|
{'_id': ObjectId(str(diction['grp_apprenant_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_grp_apprenant_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant du groupe est invalide ")
|
|
return False, " L'identifiant du groupe est invalide "
|
|
|
|
|
|
if ("ue_id" in diction.keys() and diction['ue_id']):
|
|
update_data['ue_id'] = str(diction['ue_id'])
|
|
is_valide_ue_id = MYSY_GV.dbname['unite_enseignement'].count_documents(
|
|
{'_id': ObjectId(str(diction['ue_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_ue_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de l'unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de l'unité d'enseignement est invalide "
|
|
|
|
new_unite_enseignement_planif_id = ""
|
|
if ("ue_id" in diction.keys() and diction['ue_id'] and "ue_planif_line_id" in diction.keys() and diction['ue_planif_line_id']):
|
|
update_data['unite_enseignement_planif_id'] = str(diction['ue_planif_line_id'])
|
|
new_unite_enseignement_planif_id = str(diction['ue_planif_line_id'])
|
|
|
|
is_valide_unite_enseignement_planif_id = MYSY_GV.dbname['unite_enseignement_planif'].count_documents(
|
|
{'_id': ObjectId(str(diction['ue_planif_line_id'])),
|
|
'ue_id':str( diction['ue_id']),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
if (is_valide_unite_enseignement_planif_id != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " L'identifiant de la ligne de planification de unité d'enseignement est invalide ")
|
|
return False, " L'identifiant de la ligne de planification de unité d'enseignement est invalide "
|
|
|
|
|
|
|
|
update_data['session_id'] = str(diction['session_id'])
|
|
update_data['sequence_start'] = date_debut_seq
|
|
update_data['sequence_end'] = date_fin_seq
|
|
update_data['valide'] = "1"
|
|
update_data['locked'] = "0"
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
|
|
|
|
print({'_id': ObjectId(str(diction['_id'])),
|
|
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])})
|
|
|
|
|
|
|
|
update = MYSY_GV.dbname['session_formation_sequence'].update_one({'_id': ObjectId(str(diction['_id'])),
|
|
'valide': '1', 'locked': '0',
|
|
'partner_owner_recid': str(my_partner['recid'])},
|
|
{'$set': update_data}
|
|
)
|
|
if (update.modified_count != 1):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Impossible de mettre à jour la séquence (2); update.modified_count = ", update.modified_count)
|
|
return False, "Impossible de mettre à jour la séquence (2) "
|
|
|
|
|
|
"""
|
|
Si la mise à jour fonction et qu'on a bien un update_data['ue_planif_line_id'] = str(diction['ue_planif_line_id'])
|
|
alors on met à jour la ligne de la collection : unite_enseignement_planif.
|
|
|
|
1 - On deprogramme l'ancienne ligne de planification si jamais il eu un mise à jour
|
|
2 - On programme le nouvelle ligne de planification
|
|
|
|
|
|
"""
|
|
if( new_unite_enseignement_planif_id != old_unite_enseignement_planif_id ):
|
|
# Deprogrammation de l'ancien
|
|
update_data = {}
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['session_formation_sequence_id'] = ""
|
|
|
|
if( old_unite_enseignement_planif_id ):
|
|
update = MYSY_GV.dbname['unite_enseignement_planif'].update_one({'_id': ObjectId(str(old_unite_enseignement_planif_id)),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{'$set': update_data}
|
|
)
|
|
|
|
# Programmation de la nouvelle
|
|
update_data = {}
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner['_id'])
|
|
update_data['session_formation_sequence_id'] = str(diction['_id'])
|
|
|
|
update = MYSY_GV.dbname['unite_enseignement_planif'].update_one({'_id': ObjectId(str(new_unite_enseignement_planif_id)),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'},
|
|
{'$set': update_data}
|
|
)
|
|
|
|
|
|
|
|
|
|
return True, " La séquence a été correctement mise à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour la séquence "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste des sequence d'une formation
|
|
"""
|
|
def Get_Session_Sequence_List(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', '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'existe pas")
|
|
return False, " Les informations fournies sont incorrectes",
|
|
|
|
"""
|
|
Verification des champs obligatoires
|
|
"""
|
|
field_list_obligatoire = ['token', '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
|
|
|
|
RetObject = []
|
|
val_tmp = 0
|
|
nb_sequence = 0
|
|
for New_retVal in MYSY_GV.dbname['session_formation_sequence'].find({'session_id':str(diction['session_id']),
|
|
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}):
|
|
|
|
user = New_retVal
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
if( "grp_apprenant_id" not in user.keys() ):
|
|
user['grp_apprenant_id'] = ""
|
|
|
|
grp_apprenant_color = ""
|
|
grp_apprenant_code = ""
|
|
"""
|
|
Recuperer la couleur du groupe
|
|
"""
|
|
if( "grp_apprenant_id" in user.keys() and user['grp_apprenant_id']):
|
|
groupe_data = MYSY_GV.dbname['groupe_inscription'].find_one({'_id':ObjectId(str(user['grp_apprenant_id'])),
|
|
'valide':'1',
|
|
'locked':'0',
|
|
'partner_owner_recid':str(my_partner['recid'])},
|
|
{'code':1, 'color':1})
|
|
|
|
if( groupe_data and "color" in groupe_data.keys() and groupe_data['color']):
|
|
grp_apprenant_color = groupe_data['color']
|
|
|
|
if (groupe_data and "code" in groupe_data.keys() and groupe_data['code']):
|
|
grp_apprenant_code = groupe_data['code']
|
|
|
|
user['grp_apprenant_color'] = grp_apprenant_color
|
|
user['grp_apprenant_code'] = grp_apprenant_code
|
|
|
|
|
|
|
|
if ("ue_id" not in user.keys()):
|
|
user['ue_id'] = ""
|
|
|
|
if ("unite_enseignement_planif_id" not in user.keys()):
|
|
user['unite_enseignement_planif_id'] = ""
|
|
|
|
RetObject.append(mycommon.JSONEncoder().encode(user))
|
|
|
|
return True, RetObject, nb_sequence
|
|
|
|
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 séquences de la session "
|
|
|
|
|
|
"""
|
|
Recuperer les données d'une sequence donnée
|
|
"""
|
|
def Get_Given_Session_Sequence(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
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
for New_retVal in MYSY_GV.dbname['session_formation_sequence'].find({'_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}):
|
|
|
|
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 les données de la séquence"
|
|
|
|
|
|
|
|
"""
|
|
Supprimer une sequence donnée
|
|
"""
|
|
def Delete_Given_Session_Sequence(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
|
|
|
|
# Verifier si la sequence est valide
|
|
is_existe_valide_session_sequence_id = MYSY_GV.dbname["session_formation_sequence"].count_documents(
|
|
{'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
if (is_existe_valide_session_sequence_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la séquence n'est pas valide ")
|
|
return False, " L'identifiant de la séquence n'est pas valide "
|
|
|
|
delete = MYSY_GV.dbname['session_formation_sequence'].delete_one({'_id': ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1',
|
|
'locked': '0'})
|
|
|
|
|
|
"""
|
|
Apres la suppression de la sequence, on supprime les eventuels reservations dans les agenda pour tout event rattaché à cette sequence
|
|
"""
|
|
deleted_data_qry = {'sequence_session_id':str(diction['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']),}
|
|
|
|
#print(" ### deleted_data_qry = ", deleted_data_qry)
|
|
|
|
deleted_data = MYSY_GV.dbname['agenda'].delete_many(deleted_data_qry)
|
|
|
|
|
|
return True, "La sequence a été supprimée "
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer la séquence"
|
|
|
|
|
|
"""
|
|
Supprimer une sequence donnée en mass
|
|
"""
|
|
def Delete_Given_Session_Sequence_Mass(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'tab_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', 'tab_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
|
|
|
|
tab_id = ""
|
|
if ("tab_id" in diction.keys()):
|
|
if diction['tab_id']:
|
|
tab_id = str(diction['tab_id']).split(",")
|
|
|
|
nb_sequence = 0
|
|
for my_id in tab_id:
|
|
my_seq_data = {}
|
|
my_seq_data['token'] = diction['token']
|
|
my_seq_data['_id'] = str(my_id)
|
|
|
|
local_status, local_retval = Delete_Given_Session_Sequence(my_seq_data)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - WARNING . " + str(local_retval))
|
|
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
return True, str(nb_sequence)+" séquence(s) supprimée(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 séquences en masse"
|
|
|
|
|
|
|
|
"""
|
|
Affectation d'une ressource (humaine ou materielle) a une sequence
|
|
"""
|
|
def Add_Sequence_Affectation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "sequence_session_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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', 'sequence_session_id', "poste", ]
|
|
|
|
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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
sequence_session_id = ""
|
|
if ("sequence_session_id" in diction.keys()):
|
|
if diction['sequence_session_id']:
|
|
sequence_session_id = diction['sequence_session_id']
|
|
|
|
# Verifier que la sequence existe bien
|
|
sequence_session_existe_count = MYSY_GV.dbname['session_formation_sequence'].count_documents({'_id':ObjectId(str(sequence_session_id)), 'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( sequence_session_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La sequence est invalide ")
|
|
return False, " La sequence est invalide "
|
|
|
|
if (sequence_session_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Sequence incohérente. il a plusieurs sequences avec le meme id ")
|
|
return False, " Sequence incohérente. il a plusieurs sequences avec le meme id "
|
|
|
|
sequence_session_existe_data = MYSY_GV.dbname['session_formation_sequence'].find_one(
|
|
{'_id': ObjectId(str(sequence_session_id)), 'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
qry_la = {'_id': ObjectId(str(sequence_session_existe_data['session_id'])), 'partner_owner_recid': str(partner_recid),
|
|
'valide': '1'}
|
|
|
|
|
|
|
|
session_data = MYSY_GV.dbname['session_formation'].find_one(
|
|
{'_id': ObjectId(str(sequence_session_existe_data['session_id'])), 'partner_owner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if( diction['related_target_collection_id'] and diction['related_target_collection'] ):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
if( diction['related_target_collection_id'] != "" or diction['related_target_collection'] != ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
|
|
|
|
# Verifier qu'on pas une affectation avec le meme poste qui demarre à la meme date.
|
|
if_affectation_exist_count_qry = {'related_target_collection':str(diction['related_target_collection']), 'related_target_collection_id':str(diction['related_target_collection_id']),
|
|
'partner_owner_recid':str(partner_recid),'valide':'1', 'poste':str(diction['poste']),
|
|
'sequence_session_id':str(sequence_session_id)
|
|
}
|
|
|
|
if_affectation_exist_count = MYSY_GV.dbname['ressource_humaine_affectation'].count_documents(if_affectation_exist_count_qry)
|
|
if(if_affectation_exist_count > 0 ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Cette ressource occupe déjà ce poste pour cette séquence")
|
|
return False, " Cette ressource occupe déjà ce poste pour cette séquence "
|
|
|
|
|
|
my_data = {}
|
|
|
|
my_data['partner_owner_recid'] = str(partner_recid)
|
|
my_data['poste'] = str(poste)
|
|
my_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
my_data['related_target_collection'] = str(related_target_collection)
|
|
if( "comment" in diction.keys() ):
|
|
my_data['comment'] = str(diction['comment'])
|
|
else:
|
|
my_data['comment'] = ""
|
|
my_data['sequence_session_id'] = str(diction['sequence_session_id'])
|
|
|
|
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
my_data['date_update'] = str(datetime.now())
|
|
my_data['update_by'] = str(my_partner_data['_id'])
|
|
|
|
inserted_data = MYSY_GV.dbname['session_formation_sequence_affectation'].insert_one(my_data)
|
|
if( inserted_data is None):
|
|
return False," Impossible d'affecter la ressource à la sequence (2)"
|
|
|
|
print(" ### inserted_data = ", inserted_data)
|
|
|
|
|
|
"""
|
|
A présent que la sequence est créée, creation de l'event dans l'agenda de la ressource
|
|
"""
|
|
|
|
my_class_data = MYSY_GV.dbname['myclass'].find_one({'internal_url':str(session_data['class_internal_url']),
|
|
'partner_owner_recid':str(session_data['partner_owner_recid']),
|
|
'valide':'1'})
|
|
|
|
class_title = ""
|
|
if( my_class_data and "title" in my_class_data.keys()):
|
|
class_title = my_class_data['title']
|
|
|
|
data_agenda = {}
|
|
data_agenda['related_collection'] = str(related_target_collection)
|
|
data_agenda['related_collection_recid'] = str(related_target_collection_id)
|
|
data_agenda['partner_owner_recid'] = str(partner_recid)
|
|
data_agenda['event_title'] = str(class_title)
|
|
|
|
data_agenda['session_formation_sequence_affectation_id'] = str(inserted_data.inserted_id)
|
|
|
|
data_agenda['comment'] = str(session_data['code_session'])
|
|
|
|
data_agenda['event_start'] = datetime.strptime(str(sequence_session_existe_data['sequence_start']), '%d/%m/%Y %H:%M').isoformat()
|
|
data_agenda['event_end'] = datetime.strptime(str(sequence_session_existe_data['sequence_end']), '%d/%m/%Y %H:%M').isoformat()
|
|
data_agenda['valide'] = "1"
|
|
data_agenda['locked'] = "0"
|
|
data_agenda['event_type'] = "planning"
|
|
data_agenda['sequence_session_id'] = str(sequence_session_existe_data['_id'])
|
|
data_agenda['update_by'] = str(my_partner_data['_id'])
|
|
|
|
#print(" #### data_agenda to add = ", data_agenda)
|
|
|
|
MYSY_GV.dbname['agenda'].insert_one(data_agenda)
|
|
|
|
|
|
return True, " La ressource a bien été affectée à la sequence"
|
|
|
|
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'affecter la ressource à la sequence "
|
|
|
|
|
|
"""
|
|
Affectation d'une ressource (humaine ou materielle) a une note_evaluation
|
|
"""
|
|
def Add_Note_Evaluation_Affectation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "note_evaluation_id", "poste",
|
|
"comment", 'related_target_collection', 'related_target_collection_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', 'note_evaluation_id', "poste", ]
|
|
|
|
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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
note_evaluation_id = ""
|
|
if ("note_evaluation_id" in diction.keys()):
|
|
if diction['note_evaluation_id']:
|
|
note_evaluation_id = diction['note_evaluation_id']
|
|
|
|
# Verifier que l'evaluation existe bien
|
|
note_evaluation_existe_count = MYSY_GV.dbname['note_evaluation'].count_documents({'_id':ObjectId(str(note_evaluation_id)),
|
|
'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( note_evaluation_existe_count != 1 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identifiant de la note d'évaluation est invalide ")
|
|
return False, "L'identifiant de l'note d'évaluation est invalide "
|
|
|
|
|
|
note_evaluation_existe_data = MYSY_GV.dbname['note_evaluation'].find_one(
|
|
{'_id': ObjectId(str(note_evaluation_id)),
|
|
'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
|
|
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if( diction['related_target_collection_id'] and diction['related_target_collection'] ):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
if( diction['related_target_collection_id'] != "" or diction['related_target_collection'] != ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
|
|
|
|
my_data = {}
|
|
|
|
my_data['partner_owner_recid'] = str(partner_recid)
|
|
my_data['poste'] = str(poste)
|
|
my_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
my_data['related_target_collection'] = str(related_target_collection)
|
|
if( "comment" in diction.keys() ):
|
|
my_data['comment'] = str(diction['comment'])
|
|
else:
|
|
my_data['comment'] = ""
|
|
|
|
my_data['note_evaluation_id'] = str(diction['note_evaluation_id'])
|
|
|
|
|
|
my_data['valide'] = "1"
|
|
my_data['locked'] = "0"
|
|
my_data['date_update'] = str(datetime.now())
|
|
my_data['update_by'] = str(my_partner_data['_id'])
|
|
|
|
inserted_data = MYSY_GV.dbname['note_evaluation_affectation_ressource'].insert_one(my_data)
|
|
if( inserted_data is None):
|
|
return False," Impossible d'affecter la ressource à l'évaluation (2)"
|
|
|
|
print(" ### inserted_data = ", inserted_data)
|
|
|
|
|
|
"""
|
|
A présent que la ressource est créée, creation de l'event dans l'agenda de la ressource
|
|
"""
|
|
|
|
my_class_data = MYSY_GV.dbname['myclass'].find_one({'_id':str(note_evaluation_existe_data['class_id']),
|
|
'partner_owner_recid':str(my_partner_data['recid']),
|
|
'valide':'1'})
|
|
|
|
class_title = ""
|
|
if( my_class_data and "title" in my_class_data.keys()):
|
|
class_title = my_class_data['title']
|
|
|
|
data_agenda = {}
|
|
data_agenda['related_collection'] = str(related_target_collection)
|
|
data_agenda['related_collection_recid'] = str(related_target_collection_id)
|
|
data_agenda['partner_owner_recid'] = str(partner_recid)
|
|
data_agenda['event_title'] = str(class_title)
|
|
|
|
data_agenda['session_formation_sequence_affectation_id'] = str(inserted_data.inserted_id)
|
|
|
|
data_agenda['comment'] = "Eval : "+str(note_evaluation_existe_data['titre'])
|
|
|
|
data_agenda['event_start'] = datetime.strptime(str(note_evaluation_existe_data['eval_date_heure_debut']), '%d/%m/%Y %H:%M').isoformat()
|
|
data_agenda['event_end'] = datetime.strptime(str(note_evaluation_existe_data['eval_date_heure_fin']), '%d/%m/%Y %H:%M').isoformat()
|
|
data_agenda['valide'] = "1"
|
|
data_agenda['locked'] = "0"
|
|
data_agenda['event_type'] = "planning"
|
|
data_agenda['sequence_session_id'] = str(note_evaluation_existe_data['_id'])
|
|
data_agenda['update_by'] = str(my_partner_data['_id'])
|
|
|
|
#print(" #### data_agenda to add = ", data_agenda)
|
|
|
|
MYSY_GV.dbname['agenda'].insert_one(data_agenda)
|
|
|
|
|
|
return True, " La ressource a été correctement affectée à l'évaluation "
|
|
|
|
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'affecter la ressource à l'évaluation "
|
|
|
|
|
|
"""
|
|
Mettre à jour une affectation de ressource a une note_evaluation
|
|
"""
|
|
def Update_Note_Evaluation_Affectation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "_id", "note_evaluation_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
# Verifier l'existence et la validité de la sequence à modifier
|
|
|
|
|
|
# Verifier que l'affetation existe bien
|
|
affectation_note_evaluation_existe_count = MYSY_GV.dbname['note_evaluation_affectation_ressource'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( affectation_note_evaluation_existe_count != 1 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'identification de l'affectation est invalide ")
|
|
return False, " L'identification de l'affectation est invalide "
|
|
|
|
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if( diction['related_target_collection_id'] and diction['related_target_collection'] ):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
if( diction['related_target_collection_id'] != "" or diction['related_target_collection'] != ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
|
|
|
|
update_data = {}
|
|
|
|
update_data['partner_owner_recid'] = str(partner_recid)
|
|
update_data['poste'] = str(poste)
|
|
update_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
update_data['related_target_collection'] = str(related_target_collection)
|
|
update_data['comment'] = str(diction['comment'])
|
|
update_data['sequence_session_id'] = str(affectation_note_evaluation_existe_count['_id'])
|
|
|
|
|
|
update_data['valide'] = "1"
|
|
update_data['locked'] = "0"
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner_data['_id'])
|
|
|
|
inserted_data = MYSY_GV.dbname['note_evaluation_affectation_ressource'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked": "0",
|
|
'partner_owner_recid': str(partner_recid)},
|
|
{"$set": update_data},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if (inserted_data is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour cette affectation (3)")
|
|
return False, " Impossible de mettre à jour cette affectation (3) "
|
|
|
|
|
|
|
|
return True, " L'affectation a bien été mise à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour l'affectation de la ressource "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Affectation d'une ressource (humaine ou materielle) en masse à plusieurs sequence
|
|
"""
|
|
def Add_Sequence_Affectation_Ressource_Poste_Mass(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "tab_sequence_session_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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', 'tab_sequence_session_id', "poste", ]
|
|
|
|
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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
tab_sequence_session_id = ""
|
|
if ("tab_sequence_session_id" in diction.keys()):
|
|
if diction['tab_sequence_session_id']:
|
|
tab_sequence_session_id = str(diction['tab_sequence_session_id']).split(",")
|
|
|
|
# Verifier que la sequence existe bien
|
|
for sequence_session_id in tab_sequence_session_id :
|
|
sequence_session_existe_count = MYSY_GV.dbname['session_formation_sequence'].count_documents({'_id':ObjectId(str(sequence_session_id)), 'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( sequence_session_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - La sequence est invalide ")
|
|
return False, " La sequence est invalide "
|
|
|
|
if (sequence_session_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Sequence incohérente. il a plusieurs sequences avec le meme id ")
|
|
return False, " Sequence incohérente. il a plusieurs sequences avec le meme id "
|
|
|
|
# Vu que toutes les sequences sont valides, on fait la mise à jour
|
|
for sequence_session_id in tab_sequence_session_id:
|
|
my_ressource_seq_data = {}
|
|
|
|
my_ressource_seq_data['token'] = diction['token']
|
|
my_ressource_seq_data['sequence_session_id'] = sequence_session_id
|
|
if( "poste" in diction.keys() ):
|
|
my_ressource_seq_data['poste'] = diction['poste']
|
|
else:
|
|
my_ressource_seq_data['poste'] = ""
|
|
|
|
if ("comment" in diction.keys()):
|
|
my_ressource_seq_data['comment'] = diction['comment']
|
|
else:
|
|
my_ressource_seq_data['comment'] = ""
|
|
|
|
if ("related_target_collection" in diction.keys()):
|
|
my_ressource_seq_data['related_target_collection'] = diction['related_target_collection']
|
|
else:
|
|
my_ressource_seq_data['related_target_collection'] = ""
|
|
|
|
if ("related_target_collection_id" in diction.keys()):
|
|
my_ressource_seq_data['related_target_collection_id'] = diction['related_target_collection_id']
|
|
else:
|
|
my_ressource_seq_data['related_target_collection_id'] = ""
|
|
|
|
|
|
|
|
local_status, local_retval = Add_Sequence_Affectation_Ressource_Poste(my_ressource_seq_data)
|
|
if(local_status is False ):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - WARNING . "+str(local_retval))
|
|
|
|
|
|
|
|
|
|
return True, " Les ressources ont bien été ajoutées en masse"
|
|
|
|
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'affecter la ressource à la sequence "
|
|
|
|
|
|
|
|
"""
|
|
Mettre à jour une affectation de ressource
|
|
"""
|
|
def Update_Sequence_Affectation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "_id", "sequence_session_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
# Verifier l'existence et la validité de la sequence à modifier
|
|
sequence_session_id = ""
|
|
if ("sequence_session_id" in diction.keys()):
|
|
if diction['sequence_session_id']:
|
|
sequence_session_id = diction['sequence_session_id']
|
|
|
|
# Verifier que l'affetation existe bien
|
|
affectation_sequence_session_existe_count = MYSY_GV.dbname['session_formation_sequence_affectation'].count_documents({'_id':ObjectId(str(diction['_id'])), 'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( affectation_sequence_session_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'affectation est invalide ")
|
|
return False, " L'affectation est invalide "
|
|
|
|
if (affectation_sequence_session_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'affectation est incohérente. il a plusieurs affectations avec le meme id ")
|
|
return False, " L'affectation est incohérente. il a plusieurs affectations avec le meme id "
|
|
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
comment = diction['comment']
|
|
if(len(str(comment)) > 500):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'comment' a plus de 500 caractères ")
|
|
return False, "Le champ 'comment' a plus de 500 caractères "
|
|
|
|
poste = ""
|
|
if ("poste" in diction.keys()):
|
|
poste = diction['poste']
|
|
if (len(str(poste)) > 255):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Le champ 'poste' a plus de 255 caractères ")
|
|
return False, "Le champ 'poste' a plus de 255 caractères "
|
|
|
|
|
|
related_target_collection_id = ""
|
|
related_target_collection = ""
|
|
if ("related_target_collection_id" in diction.keys() and "related_target_collection" in diction.keys()):
|
|
if( diction['related_target_collection_id'] and diction['related_target_collection'] ):
|
|
related_target_collection_id = diction['related_target_collection_id']
|
|
related_target_collection = diction['related_target_collection']
|
|
else:
|
|
if( diction['related_target_collection_id'] != "" or diction['related_target_collection'] != ""):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " Les données related_target_collection_id et related_target_collection sont incohérentes")
|
|
return False, "Les données related_target_collection_id et related_target_collection sont incohérentes "
|
|
|
|
|
|
|
|
update_data = {}
|
|
|
|
update_data['partner_owner_recid'] = str(partner_recid)
|
|
update_data['poste'] = str(poste)
|
|
update_data['related_target_collection_id'] = str(related_target_collection_id)
|
|
update_data['related_target_collection'] = str(related_target_collection)
|
|
update_data['comment'] = str(diction['comment'])
|
|
update_data['sequence_session_id'] = str(diction['sequence_session_id'])
|
|
|
|
|
|
update_data['valide'] = "1"
|
|
update_data['locked'] = "0"
|
|
update_data['date_update'] = str(datetime.now())
|
|
update_data['update_by'] = str(my_partner_data['_id'])
|
|
|
|
inserted_data = MYSY_GV.dbname['session_formation_sequence_affectation'].find_one_and_update(
|
|
{'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked": "0",
|
|
'partner_owner_recid': str(partner_recid)},
|
|
{"$set": update_data},
|
|
return_document=ReturnDocument.AFTER,
|
|
upsert=False,
|
|
)
|
|
|
|
if (inserted_data is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de mettre à jour cette affectation (3)")
|
|
return False, " Impossible de mettre à jour cette affectation (3) "
|
|
|
|
|
|
|
|
return True, " L'affectation a bien été mise à jour"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de mettre à jour l'affectation de la ressource à la sequence "
|
|
|
|
|
|
"""
|
|
Supprimer une affectation de ressource à une sequence
|
|
"""
|
|
def Delete_Sequence_Affectation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "_id", "sequence_session_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
# Verifier l'existence et la validité de la sequence à modifier
|
|
sequence_session_id = ""
|
|
if ("sequence_session_id" in diction.keys()):
|
|
if diction['sequence_session_id']:
|
|
sequence_session_id = diction['sequence_session_id']
|
|
|
|
# Verifier que l'affetation existe bien
|
|
affectation_sequence_session_existe_count = MYSY_GV.dbname['session_formation_sequence_affectation'].count_documents({'_id':ObjectId(str(diction['_id'])), 'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( affectation_sequence_session_existe_count <= 0 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'affectation est invalide ")
|
|
return False, " L'affectation est invalide "
|
|
|
|
if (affectation_sequence_session_existe_count > 1):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - L'affectation est incohérente. il a plusieurs affectations avec le meme id ")
|
|
return False, " L'affectation est incohérente. il a plusieurs affectations avec le meme id "
|
|
|
|
affectation_sequence_session_data = MYSY_GV.dbname[
|
|
'session_formation_sequence_affectation'].find_one(
|
|
{'_id': ObjectId(str(diction['_id'])), 'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
|
|
|
|
inserted_data = MYSY_GV.dbname['session_formation_sequence_affectation'].delete_one(
|
|
{'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked": "0",
|
|
'partner_owner_recid': str(partner_recid)}, )
|
|
|
|
if (inserted_data is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer à jour cette affectation (3)")
|
|
return False, " Impossible de supprimer cette affectation (3) "
|
|
|
|
"""
|
|
A present que la ressource a été supprimée, il faut egalement supprimer la reservation de la ressource
|
|
"""
|
|
qry_for_delete = {'sequence_session_id':str(affectation_sequence_session_data['sequence_session_id']), 'partner_owner_recid': str(affectation_sequence_session_data['partner_owner_recid']),
|
|
'related_collection_recid':str(affectation_sequence_session_data['related_target_collection_id']),
|
|
'related_collection':str(affectation_sequence_session_data['related_target_collection']),
|
|
'session_formation_sequence_affectation_id': str(affectation_sequence_session_data['_id'])}
|
|
|
|
print(" #### qry_for_delete = ", qry_for_delete)
|
|
|
|
MYSY_GV.dbname['agenda'].delete_many(qry_for_delete)
|
|
|
|
|
|
return True, " L'affectation a bien été supprimée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer l'affectation de la ressource à la sequence "
|
|
|
|
|
|
"""
|
|
Supprimer les affectations et reservation de ressources pour les
|
|
notes evaluation
|
|
"""
|
|
|
|
def Delete_Note_Evaluation_Ressource_Poste(diction):
|
|
try:
|
|
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "_id", "note_evaluation_id", "poste", "comment", 'related_target_collection', 'related_target_collection_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, " Toutes le information obligatoires n'ont pas été fournies"
|
|
|
|
token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de récupérer le partner_recid")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
# Verifier l'existence et la validité d'evalution à modifier
|
|
note_evaluation_id = ""
|
|
if ("note_evaluation_id" in diction.keys()):
|
|
if diction['note_evaluation_id']:
|
|
note_evaluation_id = diction['note_evaluation_id']
|
|
|
|
# Verifier que l'affetation existe bien
|
|
affectation_evaluation_existe_count = MYSY_GV.dbname['note_evaluation_affectation_ressource'].count_documents({'_id':ObjectId(str(diction['_id'])),
|
|
'partner_owner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':'0'})
|
|
|
|
if( affectation_evaluation_existe_count != 1 ) :
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " L'affectation est invalide ")
|
|
return False, " L'affectation est invalide "
|
|
|
|
|
|
affectation_evaluation_existe_data = MYSY_GV.dbname[
|
|
'note_evaluation_affectation_ressource'].find_one(
|
|
{'_id': ObjectId(str(diction['_id'])), 'partner_owner_recid': str(partner_recid),
|
|
'valide': '1', 'locked': '0'})
|
|
|
|
|
|
|
|
deleted_data = MYSY_GV.dbname['note_evaluation_affectation_ressource'].delete_one(
|
|
{'_id': ObjectId(str(diction['_id'])), 'valide': "1", "locked": "0",
|
|
'partner_owner_recid': str(partner_recid)}, )
|
|
|
|
if (deleted_data is None):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible de supprimer à jour cette affectation (3)")
|
|
return False, " Impossible de supprimer cette affectation (3) "
|
|
|
|
"""
|
|
A present que la ressource a été supprimée, il faut egalement supprimer la reservation de la ressource
|
|
"""
|
|
qry_for_delete = { 'partner_owner_recid': str(affectation_evaluation_existe_data['partner_owner_recid']),
|
|
'related_collection_recid':str(affectation_evaluation_existe_data['related_target_collection_id']),
|
|
'related_collection':str(affectation_evaluation_existe_data['related_target_collection']),
|
|
'session_formation_sequence_affectation_id': str(affectation_evaluation_existe_data['_id'])}
|
|
|
|
print(" #### qry_for_delete = ", qry_for_delete)
|
|
|
|
MYSY_GV.dbname['agenda'].delete_many(qry_for_delete)
|
|
|
|
|
|
return True, " L'affectation a bien été supprimée"
|
|
|
|
except Exception as e:
|
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
|
|
return False, " Impossible de supprimer l'affectation de la ressource "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste des affectations de ressource à une sequence
|
|
"""
|
|
def Get_List_Sequence_Ressource_Affectation(diction):
|
|
try:
|
|
field_list_obligatoire = [ 'token', 'sequence_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, " La valeur '" + val + "' n'est pas presente dans liste"
|
|
|
|
my_token = ""
|
|
if ("token" in diction.keys()):
|
|
if diction['token']:
|
|
my_token = diction['token']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
|
|
qry_affectation = {'partner_owner_recid':str(my_partner_data['recid']),
|
|
'sequence_session_id':str(diction['sequence_session_id']),
|
|
'valide':'1', 'locked':'0'}
|
|
|
|
|
|
#print(" ### qry_affectation = ",qry_affectation)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['session_formation_sequence_affectation'].find(qry_affectation):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
related_target_collection_id_nom = ""
|
|
related_target_collection_object = ""
|
|
|
|
# Si l'affectation a un 'related_target_collection_id', alors cela veut dire qu'il faut aller chercheer
|
|
# la cible de cette affection.
|
|
if( "related_target_collection_id" in retval.keys() and "related_target_collection" in retval.keys()):
|
|
if( retval["related_target_collection_id"] and retval["related_target_collection"]):
|
|
|
|
# Si l'affectation concerne une ressource_humaine
|
|
if( retval["related_target_collection"] == "ressource_humaine"):
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one({"_id":ObjectId(str( retval["related_target_collection_id"])),
|
|
'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':"0"})
|
|
|
|
if(affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["nom"] +" "+affectation_target_data["prenom"]
|
|
related_target_collection_object = "Ressource Humaine"
|
|
|
|
elif ( retval["related_target_collection"] == "ressource_materielle") :
|
|
# Si l'affectation concerne une ressource_materielle
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["nom"]
|
|
related_target_collection_object = "Ressource Materielle"
|
|
|
|
|
|
|
|
|
|
user['related_target_collection_id_nom'] = related_target_collection_id_nom
|
|
user['related_target_collection_object'] = related_target_collection_object
|
|
|
|
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 ressources affectées à cette séquence "
|
|
|
|
|
|
|
|
"""
|
|
Recuperer la liste des affectations de ressource à une sequence
|
|
"""
|
|
def Get_List_note_evaluation_Ressource_Affectation(diction):
|
|
try:
|
|
field_list_obligatoire = [ 'token', 'note_evaluation_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']
|
|
|
|
|
|
|
|
# Recuperation du recid du partenaire
|
|
partner_recid = mycommon.get_parnter_recid_from_token(str(my_token))
|
|
if partner_recid is False:
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la fiche detaillée")
|
|
return False, " Les informations d'identification sont invalides"
|
|
|
|
local_status, my_partner_data = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
|
|
if (local_status is not True):
|
|
return local_status, my_partner_data
|
|
|
|
|
|
|
|
qry_affectation = {'partner_owner_recid':str(my_partner_data['recid']),
|
|
'note_evaluation_id':str(diction['note_evaluation_id']),
|
|
'valide':'1', 'locked':'0'}
|
|
|
|
|
|
#print(" ### qry_affectation = ",qry_affectation)
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
for retval in MYSY_GV.dbname['note_evaluation_affectation_ressource'].find(qry_affectation):
|
|
user = retval
|
|
user['id'] = str(val_tmp)
|
|
val_tmp = val_tmp + 1
|
|
|
|
related_target_collection_id_nom = ""
|
|
related_target_collection_object = ""
|
|
|
|
# Si l'affectation a un 'related_target_collection_id', alors cela veut dire qu'il faut aller chercheer
|
|
# la cible de cette affection.
|
|
if( "related_target_collection_id" in retval.keys() and "related_target_collection" in retval.keys()):
|
|
if( retval["related_target_collection_id"] and retval["related_target_collection"]):
|
|
|
|
# Si l'affectation concerne une ressource_humaine
|
|
if( retval["related_target_collection"] == "ressource_humaine"):
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one({"_id":ObjectId(str( retval["related_target_collection_id"])),
|
|
'partner_recid':str(partner_recid),
|
|
'valide':'1', 'locked':"0"})
|
|
|
|
if(affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["nom"] +" "+affectation_target_data["prenom"]
|
|
related_target_collection_object = "Ressource Humaine"
|
|
|
|
elif ( retval["related_target_collection"] == "ressource_materielle") :
|
|
# Si l'affectation concerne une ressource_materielle
|
|
affectation_target_data = MYSY_GV.dbname[retval["related_target_collection"]].find_one(
|
|
{"_id": ObjectId(str(retval["related_target_collection_id"])),
|
|
'partner_recid': str(partner_recid),
|
|
'valide': '1'})
|
|
|
|
if (affectation_target_data is not None):
|
|
related_target_collection_id_nom = affectation_target_data["nom"]
|
|
related_target_collection_object = "Ressource Materielle"
|
|
|
|
|
|
|
|
|
|
user['related_target_collection_id_nom'] = related_target_collection_id_nom
|
|
user['related_target_collection_object'] = related_target_collection_object
|
|
|
|
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 ressources affectées à cette évaluation "
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet de dupliquer une semaine type
|
|
de date_debut à date_fin.
|
|
|
|
le champ : 'semaine_tab_event' contient la semaine type et est de forme :
|
|
[
|
|
{
|
|
"id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds",
|
|
"day_week": "Thursday"
|
|
},
|
|
{
|
|
"id": "1714820397818",
|
|
"title": "Nouvelle",
|
|
"start": "2024-04-30 14:30:00",
|
|
"end": "2024-04-30 16:00:00",
|
|
"agenda": "ddfd",
|
|
"objectif": "fff",
|
|
"comment": "qqsdsq",
|
|
"day_week": "Tuesday"
|
|
},
|
|
{
|
|
"id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
"day_week": "Friday"
|
|
},
|
|
{
|
|
"id": "1714831968489",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-04 08:30:00",
|
|
"end": "2024-05-04 12:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
"day_week": "Saturday"
|
|
}
|
|
]
|
|
|
|
|
|
il faut dans une premier tmps reordonnée la liste des events comme suit :
|
|
[
|
|
{
|
|
"day_week": "Thursday",
|
|
"tab_event" : [ { "id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds"
|
|
},
|
|
{ "id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"day_week": "Saturday",
|
|
"tab_event" : [ { "id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds"
|
|
},
|
|
{ "id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
"""
|
|
|
|
def Convert_And_ReFormat_Week_Type(semaine_tab_event):
|
|
try:
|
|
|
|
Formated_Week = []
|
|
|
|
for tmp in semaine_tab_event:
|
|
print(" inside : ", tmp )
|
|
local_day = tmp['day_week']
|
|
local_node = {}
|
|
local_node['id'] = tmp['id']
|
|
local_node['title'] = tmp['title']
|
|
local_node['start'] = tmp['start']
|
|
local_node['end'] = tmp['end']
|
|
local_node['agenda'] = tmp['agenda']
|
|
local_node['objectif'] = tmp['objectif']
|
|
local_node['comment'] = tmp['comment']
|
|
|
|
day_in_Formated_Week = 0
|
|
|
|
for exist_data in Formated_Week :
|
|
if( "day_week" in exist_data.keys() and exist_data["day_week"] == local_day ):
|
|
exist_data["tab_event"].append(local_node)
|
|
day_in_Formated_Week = 1
|
|
|
|
if( day_in_Formated_Week == 0 ):
|
|
new_node = {}
|
|
new_node['day_week'] = local_day
|
|
new_node['tab_event'] = []
|
|
new_node['tab_event'].append(local_node)
|
|
|
|
Formated_Week.append(new_node)
|
|
|
|
|
|
return True, Formated_Week
|
|
|
|
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 reformater la semaine type "
|
|
|
|
|
|
"""
|
|
Cette fonction permet de créer les planification à la semaine.
|
|
|
|
mais avant tout traitement, un reformatage est necessaure
|
|
avec la fontion : Convert_And_ReFormat_Week_Type
|
|
"""
|
|
def Create_Automatic_Sequence_From_Week_Model(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'planif_date_debut', 'planif_date_fin', "semaine_tab_event", "ecrase_existing"]
|
|
|
|
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', 'session_id', 'planif_date_debut', 'planif_date_fin', 'semaine_tab_event']
|
|
|
|
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
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
is_existe_valide_session_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
date_session_debut = str(is_existe_valide_session_data['date_debut'])[0:10]
|
|
date_session_fin = str(is_existe_valide_session_data['date_fin'])[0:10]
|
|
|
|
|
|
# Controle de cohérence sur les dates
|
|
local_status = mycommon.CheckisDate(str(diction['planif_date_debut'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de debut n'est pas au format jj/mm/aaaa "
|
|
|
|
local_status = mycommon.CheckisDate(str(diction['planif_date_fin'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, "La date de fin n'est pas au format jj/mm/aaaa "
|
|
|
|
|
|
if (datetime.strptime(str(diction['planif_date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['planif_date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(
|
|
diction['planif_date_debut'])[0:10] +
|
|
" est postérieure à la date de fin " + str(diction['planif_date_fin'])[0:10])
|
|
|
|
return False, " La date debut de formation " + str(diction['planif_date_debut'])[0:10] + \
|
|
" est postérieure à la date de fin de formation " + str(diction['planif_date_fin'])[0:10] + " "
|
|
|
|
semaine_tab_event = diction['semaine_tab_event']
|
|
semaine_tab_event_JSON = ast.literal_eval(semaine_tab_event)
|
|
|
|
|
|
local_status, local_retval = Convert_And_ReFormat_Week_Type(semaine_tab_event_JSON)
|
|
if( local_status is False):
|
|
return local_status, local_retval
|
|
|
|
|
|
formated_semaine_tab_event = local_retval
|
|
|
|
date_debut_periode_planif = datetime.strptime(str(diction['planif_date_debut'])[0:10], '%d/%m/%Y')
|
|
date_fin_periode_planif = datetime.strptime(str(diction['planif_date_fin'])[0:10], '%d/%m/%Y')
|
|
|
|
"""
|
|
/!\ Suppression des sequences qui existe et reservation dans les agenda par rapport à cette session
|
|
si l'option est activée
|
|
"""
|
|
if( "ecrase_existing" in diction.keys() and diction['ecrase_existing'] == "1"):
|
|
for local_retval in MYSY_GV.dbname['session_formation_sequence'].find(
|
|
{'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), }):
|
|
deleted_data_agenda = MYSY_GV.dbname['agenda'].delete_many(
|
|
{'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), })
|
|
|
|
deleted_data_affectation = MYSY_GV.dbname['session_formation_sequence_affectation'].delete_many(
|
|
{'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
deleted_data_sequence = MYSY_GV.dbname['session_formation_sequence'].delete_many(
|
|
{'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
cpt = 0
|
|
|
|
nb_sequence = 0
|
|
|
|
|
|
|
|
for single_date in mycommon.daterange(date_debut_periode_planif, date_fin_periode_planif):
|
|
#print(single_date.strftime("%Y-%m-%d"))
|
|
#print(single_date.strftime("%A"))
|
|
|
|
"""
|
|
Recuperation des events associé à ce jour
|
|
"""
|
|
local_day = single_date.strftime("%A")
|
|
tab_events = []
|
|
for local_tmp in formated_semaine_tab_event:
|
|
if( "day_week" in local_tmp.keys() and local_tmp['day_week'] == local_day ):
|
|
tab_events = local_tmp['tab_event']
|
|
|
|
#print(" Pour le jour : ", local_day)
|
|
|
|
#print(" TAB EVENT = ", tab_events)
|
|
for local_event in tab_events :
|
|
|
|
local_start_date = datetime.strptime(str(local_event['start']), "%Y-%m-%d %H:%M:%S")
|
|
local_start_hour = local_start_date.strftime("%H:%M")
|
|
|
|
local_end_date = datetime.strptime(str(local_event['end']), "%Y-%m-%d %H:%M:%S")
|
|
local_end_hour = local_end_date.strftime("%H:%M")
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = local_event['title']
|
|
|
|
sequence_data['agenda'] = local_event['agenda']
|
|
sequence_data['objectif'] = local_event['objectif']
|
|
sequence_data['commentaire'] = local_event['comment']
|
|
|
|
sequence_data['check_chevauchement'] = "0"
|
|
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " " + str( local_start_hour).strip()
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(local_end_hour).strip()
|
|
|
|
|
|
#print(" #### sequence_data = ", sequence_data)
|
|
|
|
local_status, local_event = Add_Session_Sequence(sequence_data)
|
|
|
|
#print(" ### OK ")
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_event))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
cpt = cpt + 1
|
|
|
|
|
|
return True, str(nb_sequence) + " séquence(s) automatiquement créée(s) ", str(nb_sequence)
|
|
|
|
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 dupliquer la semaine "
|
|
|
|
|
|
"""
|
|
Cette fonction permet de dupliquer une semaine type
|
|
de date_debut à date_fin.
|
|
|
|
le champ : 'semaine_tab_event' contient la semaine type et est de forme :
|
|
[
|
|
{
|
|
"id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds",
|
|
"day_week": "Thursday"
|
|
},
|
|
{
|
|
"id": "1714820397818",
|
|
"title": "Nouvelle",
|
|
"start": "2024-04-30 14:30:00",
|
|
"end": "2024-04-30 16:00:00",
|
|
"agenda": "ddfd",
|
|
"objectif": "fff",
|
|
"comment": "qqsdsq",
|
|
"day_week": "Tuesday"
|
|
},
|
|
{
|
|
"id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
"day_week": "Friday"
|
|
},
|
|
{
|
|
"id": "1714831968489",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-04 08:30:00",
|
|
"end": "2024-05-04 12:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
"day_week": "Saturday"
|
|
}
|
|
]
|
|
|
|
|
|
il faut dans une premier tmps reordonnée la liste des events comme suit :
|
|
[
|
|
{
|
|
"day_month": "1",
|
|
"tab_event" : [ { "id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds"
|
|
},
|
|
{ "id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"day_week": "2",
|
|
"tab_event" : [ { "id": "1714820379044",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-02 11:00:00",
|
|
"end": "2024-05-02 12:30:00",
|
|
"agenda": "ddd",
|
|
"objectif": "ff",
|
|
"comment": "sdfds"
|
|
},
|
|
{ "id": "1714831959464",
|
|
"title": "Nouvelle",
|
|
"start": "2024-05-03 09:00:00",
|
|
"end": "2024-05-03 11:00:00",
|
|
"agenda": "",
|
|
"objectif": "",
|
|
"comment": "",
|
|
}
|
|
]
|
|
}
|
|
]
|
|
|
|
"""
|
|
|
|
def Convert_And_ReFormat_Month_Type(month_tab_event):
|
|
try:
|
|
|
|
Formated_Month = []
|
|
|
|
for tmp in month_tab_event:
|
|
print(" inside month : ", tmp )
|
|
|
|
local_node = {}
|
|
local_node['id'] = tmp['id']
|
|
local_node['title'] = tmp['title']
|
|
local_node['start'] = tmp['start']
|
|
local_node['end'] = tmp['end']
|
|
local_node['agenda'] = tmp['agenda']
|
|
local_node['objectif'] = tmp['objectif']
|
|
local_node['comment'] = tmp['comment']
|
|
|
|
local_start_date = datetime.strptime(str(tmp['start']), "%Y-%m-%d %H:%M:%S")
|
|
local_start_day = local_start_date.strftime("%d")
|
|
|
|
print(" ### Traitement du jour du mois = ", local_start_day)
|
|
|
|
day_in_Formated_Month = 0
|
|
|
|
for exist_data in Formated_Month :
|
|
if( "day_month" in exist_data.keys() and exist_data["day_month"] == local_start_day ):
|
|
exist_data["tab_event"].append(local_node)
|
|
day_in_Formated_Month = 1
|
|
|
|
if( day_in_Formated_Month == 0 ):
|
|
new_node = {}
|
|
new_node['day_month'] = local_start_day
|
|
new_node['tab_event'] = []
|
|
new_node['tab_event'].append(local_node)
|
|
|
|
Formated_Month.append(new_node)
|
|
|
|
|
|
return True, Formated_Month
|
|
|
|
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 reformater le mois type type "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction permet de créer les planification au mois.
|
|
|
|
mais avant tout traitement, un reformatage est necessaure
|
|
avec la fontion (MOIS) : Convert_And_ReFormat_Month_Type
|
|
"""
|
|
def Create_Automatic_Sequence_From_Month_Model(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'session_id', 'planif_date_debut', 'planif_date_fin', "semaine_tab_event", "ecrase_existing"]
|
|
|
|
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', 'session_id', 'planif_date_debut', 'planif_date_fin', 'semaine_tab_event']
|
|
|
|
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
|
|
|
|
# Verification de l'existence et de la session
|
|
is_existe_valide_session_id = MYSY_GV.dbname["session_formation"].count_documents(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
if (is_existe_valide_session_id <= 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - L'identifiant de la session n'est pas valide ")
|
|
return False, "L'identifiant de la session n'est pas valide "
|
|
|
|
is_existe_valide_session_data = MYSY_GV.dbname["session_formation"].find_one(
|
|
{'_id': ObjectId(str(diction['session_id'])),
|
|
'partner_owner_recid': str(my_partner['recid']),
|
|
'valide': '1'})
|
|
|
|
date_session_debut = str(is_existe_valide_session_data['date_debut'])[0:10]
|
|
date_session_fin = str(is_existe_valide_session_data['date_fin'])[0:10]
|
|
|
|
|
|
# Controle de cohérence sur les dates
|
|
local_status = mycommon.CheckisDate(str(diction['planif_date_debut'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de debut n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, " La date de debut n'est pas au format jj/mm/aaaa "
|
|
|
|
local_status = mycommon.CheckisDate(str(diction['planif_date_fin'])[0:10])
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date de fin n'est pas au format jj/mm/aaaa ")
|
|
|
|
return False, "La date de fin n'est pas au format jj/mm/aaaa "
|
|
|
|
|
|
if (datetime.strptime(str(diction['planif_date_debut'])[0:10], '%d/%m/%Y') > datetime.strptime(
|
|
str(diction['planif_date_fin'])[0:10], '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(
|
|
diction['planif_date_debut'])[0:10] +
|
|
" est postérieure à la date de fin " + str(diction['planif_date_fin'])[0:10])
|
|
|
|
return False, " La date debut de formation " + str(diction['planif_date_debut'])[0:10] + \
|
|
" est postérieure à la date de fin de formation " + str(diction['planif_date_fin'])[0:10] + " "
|
|
|
|
semaine_tab_event = diction['semaine_tab_event']
|
|
|
|
|
|
semaine_tab_event_JSON = ast.literal_eval(semaine_tab_event)
|
|
|
|
|
|
local_status, local_retval = Convert_And_ReFormat_Month_Type(semaine_tab_event_JSON)
|
|
if( local_status is False):
|
|
return local_status, local_retval
|
|
|
|
|
|
formated_mois_tab_event = local_retval
|
|
|
|
print(" ### formated_mois_tab_event = ", formated_mois_tab_event)
|
|
|
|
date_debut_periode_planif = datetime.strptime(str(diction['planif_date_debut'])[0:10], '%d/%m/%Y')
|
|
date_fin_periode_planif = datetime.strptime(str(diction['planif_date_fin'])[0:10], '%d/%m/%Y')
|
|
|
|
"""
|
|
/!\ Suppression des sequences qui existe et reservation dans les agenda par rapport à cette session
|
|
si l'option est activée
|
|
"""
|
|
if( "ecrase_existing" in diction.keys() and diction['ecrase_existing'] == "1"):
|
|
for local_retval in MYSY_GV.dbname['session_formation_sequence'].find(
|
|
{'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), }):
|
|
deleted_data_agenda = MYSY_GV.dbname['agenda'].delete_many(
|
|
{'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(
|
|
my_partner['recid']), })
|
|
|
|
deleted_data_affectation = MYSY_GV.dbname['session_formation_sequence_affectation'].delete_many(
|
|
{'sequence_session_id': str(local_retval['_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
deleted_data_sequence = MYSY_GV.dbname['session_formation_sequence'].delete_many(
|
|
{'session_id': str(diction['session_id']),
|
|
'partner_owner_recid': str(my_partner['recid']), })
|
|
|
|
cpt = 0
|
|
|
|
nb_sequence = 0
|
|
|
|
|
|
|
|
for single_date in mycommon.daterange(date_debut_periode_planif, date_fin_periode_planif):
|
|
#print(single_date.strftime("%Y-%m-%d"))
|
|
#print(single_date.strftime("%A"))
|
|
|
|
"""
|
|
Recuperation des events associé à ce jour
|
|
"""
|
|
local_day = single_date.strftime("%d")
|
|
tab_events = []
|
|
for local_tmp in formated_mois_tab_event:
|
|
if( "day_month" in local_tmp.keys() and local_tmp['day_month'] == local_day ):
|
|
tab_events = local_tmp['tab_event']
|
|
|
|
#print(" TAB EVENT = ", tab_events)
|
|
for local_event in tab_events :
|
|
|
|
local_start_date = datetime.strptime(str(local_event['start']), "%Y-%m-%d %H:%M:%S")
|
|
local_start_hour = local_start_date.strftime("%H:%M")
|
|
|
|
local_end_date = datetime.strptime(str(local_event['end']), "%Y-%m-%d %H:%M:%S")
|
|
local_end_hour = local_end_date.strftime("%H:%M")
|
|
|
|
sequence_data = {}
|
|
sequence_data['token'] = diction['token']
|
|
sequence_data['type'] = 'planning'
|
|
sequence_data['session_id'] = diction['session_id']
|
|
sequence_data['sequence_title'] = local_event['title']
|
|
|
|
sequence_data['agenda'] = local_event['agenda']
|
|
sequence_data['objectif'] = local_event['objectif']
|
|
sequence_data['commentaire'] = local_event['comment']
|
|
|
|
sequence_data['check_chevauchement'] = "0"
|
|
|
|
sequence_data['sequence_start'] = str(single_date.strftime("%d/%m/%Y")) + " " + str( local_start_hour).strip()
|
|
sequence_data['sequence_end'] = str(single_date.strftime("%d/%m/%Y")) + " " + str(local_end_hour).strip()
|
|
|
|
|
|
#print(" #### sequence_data = ", sequence_data)
|
|
|
|
local_status, local_event = Add_Session_Sequence(sequence_data)
|
|
|
|
#print(" ### OK ")
|
|
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " WARNING : " + str(local_event))
|
|
else:
|
|
nb_sequence = nb_sequence + 1
|
|
|
|
cpt = cpt + 1
|
|
|
|
|
|
return True, str(nb_sequence) + " séquence(s) automatiquement créée(s) ", str(nb_sequence)
|
|
|
|
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 dupliquer le mois "
|
|
|
|
|