Elyos_FI_Back_Office/agenda.py

987 lines
43 KiB
Python

"""
Ce fichier permet de gerer les agenda des
- employés,
- salles de classe
- materiels pédagogiques,
- etc
"""
import bson
import pymongo
from pymongo import MongoClient
import json
from bson import ObjectId
import re
from datetime import datetime
import prj_common as mycommon
import secrets
import inspect
import sys, os
import csv
import pandas as pd
from pymongo import ReturnDocument
import GlobalVariable as MYSY_GV
from math import isnan
import GlobalVariable as MYSY_GV
import ela_index_bdd_classes as eibdd
import email_mgt as email
import jinja2
from flask import send_file
from xhtml2pdf import pisa
from email.message import EmailMessage
from email.mime.text import MIMEText
from email import encoders
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
"""
Cette fonction ajoute ou met à jour un eventement de l'agenda
/!\ : Important :
- Pour les eemployé et le materiel, on utilise le related_collection_recid
"""
def Add_Update_Agenda_Event(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', 'related_collection', 'event_title', 'event_start', 'event_end', 'related_collection_recid', 'comment',
'event_type', 'justified', 'linked_collection', 'linked_collection_recid',
'related_role']
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', 'related_collection', 'event_title', 'event_start', 'event_end', 'related_collection_recid',]
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'existance et de l'acceptation d'un evement pour le 'related_collection'
if( diction['related_collection'] not in MYSY_GV.ALLOWED_AGENDA_RELATED_COLLECTION):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'objet metier "+str(diction['related_collection'] )+" n'accepte pas de planning")
return False, " L'objet metier "+str(diction['related_collection'] )+" n'accepte pas de planning "
partner_owner_recid = "partner_owner_recid"
if( str(diction['related_collection']) in ['ressource_humaine', 'ressource_materielle']):
partner_owner_recid = "partner_recid"
# Verifier que 'related_collection_recid' existe et est valide dans la collection 'related_collection'
is_existe_valide_related_collection_recid = MYSY_GV.dbname[str(diction['related_collection'])].count_documents({'_id':ObjectId(str(diction['related_collection_recid'])),
partner_owner_recid:str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_existe_valide_related_collection_recid <= 0):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant du 'related_collection_recid' n'est pas valide ")
return False, " L'identifiant du 'related_collection_recid' n'est pas valide "
if (datetime.strptime(str(diction['event_start'])[0:16], '%Y-%m-%dT%H:%M') >= datetime.strptime(str(diction['event_end'])[0:16],
'%Y-%m-%dT%H:%M')):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de fin " + str(
diction['event_end']) + " doit être postérieure à la date de début " + str(
diction['event_start']) + " ")
return False, " La date de fin " + str(
diction['event_end']) + " doit être postérieure à la date de début " + str(diction['event_start']) + " "
mydata = {}
mydata['related_collection'] = str(diction['related_collection'])
mydata['related_collection_recid'] = str(diction['related_collection_recid'])
mydata['event_title'] = str(diction['event_title'])
mydata['event_start'] = str(diction['event_start'])
mydata['event_end'] = str(diction['event_end'])
if( "linked_collection" in diction.keys() ):
mydata['linked_collection'] = str(diction['linked_collection'])
else:
mydata['linked_collection'] = ""
if ("linked_collection_recid" in diction.keys()):
mydata['linked_collection_recid'] = str(diction['linked_collection_recid'])
else:
mydata['linked_collection_recid'] = ""
if ("related_role" in diction.keys()):
mydata['related_role'] = str(diction['related_role'])
else:
mydata['related_role'] = ""
comment = ""
if( "comment" in diction.keys()):
comment = str(diction['comment'])
mydata['comment'] = comment
event_type = ""
if ("event_type" in diction.keys()):
event_type = str(diction['event_type'])
mydata['event_type'] = event_type
justified = ""
if ("justified" in diction.keys()):
justified = str(diction['justified'])
mydata['justified'] = justified
if( len(str(diction['_id']).strip()) > 0):
# Verifier si l'id de l'evenement existe
is_event_exist = MYSY_GV.dbname['agenda'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_event_exist > 0 ):
# L'eventement existe est valide, on autorise la mise à jour
mydata['date_update'] = str(datetime.now())
update = MYSY_GV.dbname['agenda'].update_one({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'},
{'$set':mydata}
)
"""
# Ajout de l'evenement dans l'historique
/!\ ici on le fait pour l'objet concerné par l'agenda
"""
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
history_event_dict = {}
history_event_dict['token'] = str(diction['token'])
history_event_dict['related_collection'] = str(diction['related_collection'])
history_event_dict['related_collection_recid'] = str(diction['related_collection_recid'])
history_event_dict['action_date'] = str(now)
history_event_dict['action_description'] = " Mise à jour entrée Agenda Titre : '" + str(
diction['event_title']) + "', Debut : '" + str(diction['event_start']) + "', Fin : '" + str(
diction['event_end']) + "' "
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
if (local_status is False):
mycommon.myprint(
" WARNING : Impossible de logguer l'historique pour l'entrée Agenda: " + str(diction['_id']))
return True, " L'événement a été mis à jour"
else:
# L'identifiant fournit est invalide, on refuse la mise à jour
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant de l'événement n'est pas valide ")
return False, " L'identifiant de l'événement n'est pas valide "
else:
# Il s'agit de la creation d'un evenement.
mydata['partner_owner_recid'] = str(my_partner['recid'])
mydata['valide'] = "1"
mydata['locked'] = "0"
insert = MYSY_GV.dbname['agenda'].insert_one(mydata)
"""
# Ajout de l'evenement dans l'historique
/!\ ici on le fait pour l'objet concerné par l'agenda
"""
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
history_event_dict = {}
history_event_dict['token'] = str(diction['token'])
history_event_dict['related_collection'] = str(diction['related_collection'])
history_event_dict['related_collection_recid'] = str(diction['related_collection_recid'])
history_event_dict['action_date'] = str(now)
history_event_dict['action_description'] = " Creation entrée Agenda Titre : '"+str(diction['event_title'])+"', Debut : '"+str(diction['event_start'])+"', Fin : '"+str(diction['event_end'])+"' "
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
if (local_status is False):
mycommon.myprint(
" WARNING : Impossible de logguer l'historique pour l'entrée Agenda: " + str(diction['_id']))
return True, " L'événement a été ajouté"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'ajouter ou mettre à jour l'événement "
"""
Cette fonction ajoute ou met à jour un eventement de l'agenda
/!\ : Important :
- Pour les apprenant (inscription), on utilise 'related_collection_email' car la clé des apprenant est l'email
"""
def Add_Update_Agenda_Event_Stagiaire(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', 'related_collection', 'event_title', 'event_start', 'event_end', 'comment',
'event_type', 'justified', 'related_collection_email', 'inscription_id']
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes"
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', '_id', 'related_collection', 'event_title', 'event_start', 'event_end', 'related_collection_email',]
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'existance et de l'acceptation d'un evement pour le 'related_collection'
if( diction['related_collection'] not in MYSY_GV.ALLOWED_AGENDA_RELATED_COLLECTION):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'objet metier "+str(diction['related_collection'] )+" n'accepte pas de planning")
return False, " L'objet metier "+str(diction['related_collection'] )+" n'accepte pas de planning "
# Verifier que 'related_collection_email' existe et est valide dans la collection 'related_collection'
"""
/!\ : 24/12/2023 -
Quand on est sur une inscription, on travail avec l'adresse emai. Cela devra bientot changé
une fois que le module 'apprenant' est ok, alors on pourra tout basculer sur l'apprenant et travailler avec l'_id
"""
if( str(str(diction['related_collection'])) == "inscription") :
is_existe_valide_related_collection_recid = MYSY_GV.dbname[str(diction['related_collection'])].count_documents({'email':str(diction['related_collection_email']),
'partner_owner_recid':str(my_partner['recid']),
'status':'1'
})
if( is_existe_valide_related_collection_recid <= 0):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant du 'related_collection_recid' n'est pas valide ")
return False, " L'identifiant du 'related_collection_recid' n'est pas valide "
else:
is_existe_valide_related_collection_recid = MYSY_GV.dbname[
str(diction['related_collection'])].count_documents({'_id': ObjectId(str(diction['inscription_id'])),
'partner_owner_recid': str(my_partner['recid']),
'valide': '1',
'locked':'0'
})
if (is_existe_valide_related_collection_recid <= 0):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant du 'related_collection_recid' n'est pas valide ")
return False, " L'identifiant du 'related_collection_recid' n'est pas valide "
if (datetime.strptime(str(diction['event_start'])[0:16], '%Y-%m-%dT%H:%M') >= datetime.strptime(str(diction['event_end'])[0:16],
'%Y-%m-%dT%H:%M')):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de fin " + str(
diction['event_end']) + " doit être postérieure à la date de début " + str(
diction['event_start']) + " ")
return False, " La date de fin " + str(
diction['event_end']) + " doit être postérieure à la date de début " + str(diction['event_start']) + " "
mydata = {}
mydata['related_collection'] = str(diction['related_collection'])
mydata['related_collection_email'] = str(diction['related_collection_email'])
mydata['event_title'] = str(diction['event_title'])
mydata['event_start'] = str(diction['event_start'])
mydata['event_end'] = str(diction['event_end'])
comment = ""
if( "comment" in diction.keys()):
comment = str(diction['comment'])
mydata['comment'] = comment
event_type = ""
if ("event_type" in diction.keys()):
event_type = str(diction['event_type'])
mydata['event_type'] = event_type
justified = ""
if ("justified" in diction.keys()):
justified = str(diction['justified'])
mydata['justified'] = justified
if( len(str(diction['_id']).strip()) > 0):
# Verifier si l'id de l'evenement existe
is_event_exist = MYSY_GV.dbname['agenda'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_event_exist > 0 ):
# L'eventement existe est valide, on autorise la mise à jour
mydata['date_update'] = str(datetime.now())
mydata['update_by'] = str(my_partner['_id'])
update = MYSY_GV.dbname['agenda'].update_one({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'},
{'$set':mydata}
)
return True, " L'événement a été mis à jour"
else:
# L'identifiant fournit est invalide, on refuse la mise à jour
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant de l'événement n'est pas valide ")
return False, " L'identifiant de l'événement n'est pas valide "
else:
# Il s'agit de la creation d'un evenement.
mydata['partner_owner_recid'] = str(my_partner['recid'])
mydata['valide'] = "1"
mydata['locked'] = "0"
insert = MYSY_GV.dbname['agenda'].insert_one(mydata)
# Recup de l'id de l'apprenant
inscription_id = ""
if( "inscription_id" in diction.keys() ):
inscription_id = str(diction['inscription_id'])
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
history_event_dict = {}
history_event_dict['token'] = diction['token']
history_event_dict['related_collection'] = "inscription"
history_event_dict['related_collection_recid'] = str(inscription_id)
history_event_dict['action_date'] = str(now)
history_event_dict['action_description'] = "Absence du "+str( mydata['event_start'] )+" au "+str(mydata['event_end'])+" "
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
if (local_status is False):
mycommon.myprint(
" WARNING : Impossible de logguer l'historique pour l'évènement : "+str(history_event_dict))
return True, " L'événement a été ajouté"
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible d'ajouter ou mettre à jour l'événement "
"""
Recuperation de la liste des agenda
"""
def get_Agenda_Event_List(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'related_collection_recid']
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', 'related_collection', 'related_collection_recid']
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
qry = {'related_collection':str(diction['related_collection']), 'related_collection_recid':str(diction['related_collection_recid']),
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}
for New_retVal in MYSY_GV.dbname['agenda'].find({'related_collection':str(diction['related_collection']), 'related_collection_recid':str(diction['related_collection_recid']),
'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 la liste des evenements "
"""
Recuperation de la liste des agenda pour plusieurs personnes
"""
def get_Agenda_Event_List_For_Many_Users(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'tab_related_collection_recid']
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', 'related_collection', 'tab_related_collection_recid']
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
my_related_collection_recid_ids = ""
if ("tab_related_collection_recid" in diction.keys()):
if diction['tab_related_collection_recid']:
my_related_collection_recid_ids = diction['tab_related_collection_recid']
tab_my_related_collection_recid_ids = []
tab_my_related_collection_recid_ids_tmp = str(my_related_collection_recid_ids).split(",")
for my_id in tab_my_related_collection_recid_ids_tmp:
if( my_id ):
tab_my_related_collection_recid_ids.append(str(my_id))
RetObject = []
val_tmp = 1
qry = {'related_collection':str(diction['related_collection']),
'related_collection_recid': {'$in': tab_my_related_collection_recid_ids},
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}
print(" ### get_Agenda_Event_List_For_Many_Users QRY = ", qry)
for New_retVal in MYSY_GV.dbname['agenda'].find({'related_collection':str(diction['related_collection']), 'related_collection_recid': {
'$in': tab_my_related_collection_recid_ids},
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}):
user = New_retVal
user['id'] = str(New_retVal['_id'])
user['group'] = str(New_retVal['related_collection_recid'])
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
return True, RetObject
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de récupérer la liste des évènements de plusieurs utilisateur "
"""
Recuperation de la liste des agenda pour un stagiaie
"""
def get_Agenda_Event_List_Stagiaire(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'related_collection_email']
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', 'related_collection', 'related_collection_email']
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['agenda'].find({'related_collection':str(diction['related_collection']), 'related_collection_email':str(diction['related_collection_email']),
'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 la liste des évènements "
"""
Cette fonction retourne la liste de eventment d'un user/materiel avec
des filtre (exemple : event_type = absence, from start_date to end_date
"""
def get_Agenda_Event_List_With_Filter(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'related_collection_recid', 'event_type', 'start_date', 'end_date']
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', 'related_collection', 'related_collection_recid']
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes",
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
filt_event_type = {}
if ("event_type" in diction.keys()):
if( str(diction['event_type']).lower() not in MYSY_GV.AGENDA_EVENT_TYPE ):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Le type d'evenement '" + str(diction['event_type']) + "' n'est pas autorisé ")
return False, " Le type d'evenement '" + str(diction['event_type']) + "' n'est pas autorisé ",
filt_event_type = {'event_type':str(diction['event_type']).lower()}
RetObject = []
val_tmp = 1
for New_retVal in MYSY_GV.dbname['agenda'].find({'related_collection':str(diction['related_collection']), 'related_collection_recid':str(diction['related_collection_recid']),
'partner_owner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'}):
filter_date_debut = ""
if ("start_date" in diction.keys()):
if diction['start_date']:
filter_date_debut = str(diction['start_date'])[0:10]
local_status = mycommon.CheckisDate(filter_date_debut)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de debut "+ str(filter_date_debut)+" n'est pas au format 'jj/mm/aaaa' ")
return False, " La date de debut "+ str(filter_date_debut)+" n'est pas au format 'jj/mm/aaaa'"
filter_date_fin = ""
if ("end_date" in diction.keys()):
if diction['end_date']:
filter_date_fin = str(diction['end_date'])[0:10]
local_status = mycommon.CheckisDate(filter_date_fin)
if (local_status is False):
mycommon.myprint(
str(inspect.stack()[0][
3]) + " La date de fin "+ str(filter_date_fin)+" n'est pas au format 'jj/mm/aaaa' ")
return False, " La date de fin "+ str(filter_date_fin)+" n'est pas au format 'jj/mm/aaaa'"
New_retVal_start_date = datetime.strptime(str(New_retVal['event_start'])[0:10], '%Y-%m-%d')
New_retVal_end_date = datetime.strptime(str(New_retVal['event_end'])[0:10], '%Y-%m-%d')
print(" ### New_retVal_start_date = ", New_retVal_start_date)
print(" ### New_retVal_end_date = ", New_retVal_end_date)
## Application des filtre de date
if (filter_date_debut and filter_date_fin):
if ( datetime.strptime(str(New_retVal_start_date)[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_debut)[0:10], '%d/%m/%Y') and
New_retVal_end_date <= datetime.strptime(str(filter_date_fin)[0:10], '%d/%m/%Y')):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
elif (filter_date_debut):
if ( datetime.strptime(str(New_retVal_start_date)[0:10], '%d/%m/%Y') >= datetime.strptime(str(filter_date_debut)[0:10], '%d/%m/%Y')):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
elif (filter_date_fin):
if (New_retVal_end_date <= datetime.strptime(str(filter_date_fin)[0:10], '%d/%m/%Y')):
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
else:
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
return True, RetObject
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de récupérer la liste des evenements "
"""
Cette fonction supprime un evenement
"""
def Delete_Agenda_Event(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', ]
incom_keys = diction.keys()
for val in incom_keys:
if val not in field_list and val.startswith('my_') is False:
mycommon.myprint(str(
inspect.stack()[0][3]) + " Le champ '" + val + "' n'est pas autorisé")
return False, " Les informations fournies sont incorrectes"
"""
Verification des champs obligatoires
"""
field_list_obligatoire = ['token', '_id', ]
for val in field_list_obligatoire:
if val not in diction:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
return False, " Les informations fournies sont incorrectes"
"""
Verification de l'identité et autorisation de l'entité qui
appelle cette API
"""
token = ""
if ("token" in diction.keys()):
if diction['token']:
token = diction['token']
local_status, my_partner = mycommon.Check_Connexion_And_Return_Partner_Data(diction)
if (local_status is not True):
return local_status, my_partner
# Verifier si l'id de l'evenement existe
is_event_exist = MYSY_GV.dbname['agenda'].count_documents({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'})
if( is_event_exist > 0 ):
is_event_exist_data = MYSY_GV.dbname['agenda'].find_one({'_id': ObjectId(str(diction['_id'])),
'partner_owner_recid': str(my_partner['recid']),
'valide': '1',
'locked': '0'})
# L'eventement existe est valide, on autorise la suppression
update = MYSY_GV.dbname['agenda'].delete_one({'_id':ObjectId(str(diction['_id'])),
'partner_owner_recid':str(my_partner['recid']),
'valide':'1',
'locked':'0'},
)
"""
# Ajout de l'evenement dans l'historique
/!\ ici on le fait pour l'objet concerné par l'agenda
"""
now = str(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))
history_event_dict = {}
history_event_dict['token'] = str(diction['token'])
history_event_dict['related_collection'] = str(is_event_exist_data['related_collection'])
history_event_dict['related_collection_recid'] = str(is_event_exist_data['related_collection_recid'])
history_event_dict['action_date'] = str(now)
history_event_dict['action_description'] = " Suppression entrée Agenda Titre : '" + str(
is_event_exist_data['event_title']) + "', Debut : '"+str(is_event_exist_data['event_start'])+"', Fin : '"+str(is_event_exist_data['event_end'])+"' "
local_status, local_retval = mycommon.Collection_Historique.Add_Historique_Event(history_event_dict)
if (local_status is False):
mycommon.myprint(
" WARNING : Impossible de logguer l'historique pour l'entrée Agenda: " + str(diction['_id']))
return True, " L'événement a été supprimé"
else:
# L'identifiant fournit est invalide, on refuse la mise à jour
mycommon.myprint(
str(inspect.stack()[0][3]) + " - L'identifiant de l'événement n'est pas valide ")
return False, " L'identifiant de l'événement n'est pas valide "
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 ou mettre à jour l'événement "
"""
Cette fonction prends un id (_id de object), le type de ressource (employé ou materiel)
et retourn les données de lobjet
"""
def get_Ressource_Info_Data(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'related_collection_recid']
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', 'related_collection', 'related_collection_recid']
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
qry = MYSY_GV.dbname[str(diction['related_collection'])].find({'_id':ObjectId(str(diction['related_collection_recid'])),
'partner_recid':str(my_partner['recid']), 'valide':'1', 'locked':'0'})
for New_retVal in MYSY_GV.dbname[str(diction['related_collection'])].find({'_id':ObjectId(str(diction['related_collection_recid'])),
'partner_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 la liste des evenements "
"""
Cette fonction prends un id (_id de object), le type de ressource (employé ou materiel)
et retourn les données de lobjet pour un stagiaire
"""
def get_Ressource_Info_Data_Satgiaire(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', 'related_collection', 'related_collection_email']
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', 'related_collection', 'related_collection_email']
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[str(diction['related_collection'])].find({'email':str(diction['related_collection_email']),
'partner_owner_recid':str(my_partner['recid']), 'status':'1'}):
user = New_retVal
user['id'] = str(val_tmp)
val_tmp = val_tmp + 1
RetObject.append(mycommon.JSONEncoder().encode(user))
return True, RetObject
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - Line : " + str(exc_tb.tb_lineno))
return False, " Impossible de récupérer la liste des evenements "