""" 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 """ 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'] 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 " # 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_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 " 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']) comment = "" if( "comment" in diction.keys()): comment = str(diction['comment']) mydata['comment'] = comment 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} ) 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) 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 (draft) """ 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 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 evenement " """ 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 ): # 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'}, ) 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 "