379 lines
15 KiB
Python
379 lines
15 KiB
Python
"""
|
|
Ce fichier permet de gérer tout ce qui est lié
|
|
a un appel d'offre.
|
|
|
|
Pour memo appel d'offre est le moyen par le quel une société va soliciter des
|
|
organismes de formation pour repondre à un besoin de formation
|
|
"""
|
|
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
|
|
|
|
def Add_Appel_Offre(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "external_code", "description", "date_debut", "date_fin", "contact",
|
|
"date_deliberation", "description_critere_selection", "comment", "list_produits_appel_offre"]
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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', 'nom', 'prenom', 'email', 'tel_mobile', ]
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
data = {}
|
|
data['partner_recid'] = diction['partner_recid']
|
|
|
|
external_code = ""
|
|
if ("external_code" in diction.keys()):
|
|
if diction['external_code']:
|
|
external_code = diction['external_code']
|
|
data['external_code'] = diction['external_code']
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
if diction['description']:
|
|
description = diction['description']
|
|
data['description'] = diction['description']
|
|
|
|
date_debut = ""
|
|
if ("date_debut" in diction.keys()):
|
|
if diction['date_debut']:
|
|
date_debut = diction['date_debut']
|
|
data['date_debut'] = diction['date_debut']
|
|
|
|
local_status = mycommon.CheckisDate(date_debut)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date debut n'est pas au format jj/mm/aaaa ")
|
|
return False, " La date debut n'est pas au format jj/mm/aaaa "
|
|
|
|
|
|
date_fin = ""
|
|
if ("date_fin" in diction.keys()):
|
|
if diction['date_fin']:
|
|
date_fin = diction['date_fin']
|
|
data['date_fin'] = diction['date_fin']
|
|
|
|
local_status = mycommon.CheckisDate(date_fin)
|
|
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 "
|
|
|
|
|
|
"""
|
|
Controle cohérence des dates debut et fin
|
|
"""
|
|
if (datetime.strptime(str(date_debut).strip(), '%d/%m/%Y') > datetime.strptime(
|
|
str(date_fin).strip(), '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(date_debut) +" est postérieure à la date de fin " + str(date_fin) + " ")
|
|
|
|
return False, " La date debut " + str(date_debut) + " est postérieure à la date de fin " + str(date_fin) + " "
|
|
|
|
|
|
contact = ""
|
|
if ("contact" in diction.keys()):
|
|
if diction['contact']:
|
|
contact = diction['contact']
|
|
data['contact'] = diction['contact']
|
|
|
|
date_deliberation = ""
|
|
if ("date_deliberation" in diction.keys()):
|
|
if diction['date_deliberation']:
|
|
date_deliberation = diction['date_deliberation']
|
|
data['date_deliberation'] = diction['date_deliberation']
|
|
|
|
local_status = mycommon.CheckisDate(date_deliberation)
|
|
if (local_status is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - La date de deliberation n'est pas au format jj/mm/aaaa ")
|
|
return False, " La date de deliberation n'est pas au format jj/mm/aaaa "
|
|
|
|
"""
|
|
Controle cohérence des dates debut et la date de deliberation
|
|
"""
|
|
if (datetime.strptime(str(date_debut).strip(), '%d/%m/%Y') > datetime.strptime(
|
|
str(date_deliberation).strip(), '%d/%m/%Y')):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " La date debut " + str(date_debut) + " est postérieure à la date de deliberation " + str(
|
|
date_deliberation) + " ")
|
|
|
|
return False, " La date debut " + str(date_debut) + " est postérieure à la date de deliberation " + str(
|
|
date_deliberation) + " "
|
|
|
|
|
|
description_critere_selection = ""
|
|
if ("description_critere_selection" in diction.keys()):
|
|
if diction['description_critere_selection']:
|
|
description_critere_selection = diction['description_critere_selection']
|
|
data['description_critere_selection'] = diction['description_critere_selection']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
if diction['comment']:
|
|
comment = diction['comment']
|
|
data['comment'] = diction['comment']
|
|
|
|
list_produits_appel_offre = ""
|
|
if ("list_produits_appel_offre" in diction.keys()):
|
|
if diction['list_produits_appel_offre']:
|
|
list_produits_appel_offre = diction['list_produits_appel_offre']
|
|
data['list_produits_appel_offre'] = diction['list_produits_appel_offre']
|
|
|
|
|
|
"""
|
|
Verifier s'il n'y pas deja un appel d'offre avec le meme code externe et partner_recid
|
|
"""
|
|
tmp_count = MYSY_GV['appel_offre'].count_documents({'external_code': str(external_code),
|
|
'valide': '1', 'partner_recid':my_partner['recid']})
|
|
if (tmp_count > 0):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Cet appel d'offre est deja enregistré : external_code = ", str(external_code))
|
|
|
|
return False, " - Cet appel d'offre est deja enregistré "
|
|
|
|
data['partner_recid'] = my_partner['recid']
|
|
data['valide'] = '1'
|
|
data['locked'] = '0'
|
|
|
|
inserted_id = ""
|
|
inserted_id = MYSY_GV.dbname['appel_offre'].insert_one(data).inserted_id
|
|
if (not inserted_id):
|
|
mycommon.myprint(
|
|
" Impossible de créer l'appel d'offre (1) ")
|
|
return False, " Impossible de créer l'appel d'offre (1) "
|
|
|
|
|
|
return True, " L'appel d'ofre a été correctement créé"
|
|
|
|
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 l'appel d'offre "
|
|
|
|
|
|
"""
|
|
Mise à jour d'un appel d'offre
|
|
"""
|
|
def Update_Appel_Offre(diction):
|
|
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'nom', 'prenom', 'email', 'tel_mobile', 'date_naissance', 'adr_rue', 'adr_ville',
|
|
'adr_code_postal', 'adr_pays']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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', '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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
partner_recid = mycommon.get_parnter_recid_from_token(token)
|
|
if (partner_recid is False):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][3]) + " - partner_recid est KO. Les données de connexion sont incorrectes ")
|
|
return False, " Vous n'etes pas autorisé à utiliser cette API "
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_partner = mycommon.get_partner_data_from_recid(partner_recid)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données du partenaire. "
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data = {}
|
|
|
|
nom = ""
|
|
if ("nom" in diction.keys()):
|
|
nom = diction['nom']
|
|
data['nom'] = diction['nom']
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
date_cle = {}
|
|
date_cle['email'] = str(email)
|
|
date_cle['partner_recid'] = str(partner_recid)
|
|
date_cle['valide'] = "1"
|
|
date_cle['locked'] = "0"
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['candidat'].find_one_and_update(
|
|
date_cle,
|
|
{"$set": data},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if (not result.acknowledged):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour l'appel d'offre: " + str(email))
|
|
return False, " Impossible de mettre à jour l'appel d'offre: " + str(email) + " "
|
|
|
|
return True, " L'appel d'offre 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 l'appel d'offre' "
|
|
|
|
|
|
"""
|
|
fonction de recuperation d'un appel d'offre
|
|
"""
|
|
def Get_Appel_Offre(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'nom', 'prenom', 'email', 'tel_mobile', 'date_naissance', 'adr_rue', 'adr_ville',
|
|
'adr_code_postal', 'adr_pays', 'candidats_id', 'cpny']
|
|
incom_keys = diction.keys()
|
|
for val in incom_keys:
|
|
if val not in field_list:
|
|
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']
|
|
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']
|
|
|
|
# Verifier la validité du token
|
|
retval = mycommon.check_partner_token_validity("", token)
|
|
|
|
if retval is False:
|
|
return "Err_Connexion", " La session de connexion n'est pas valide"
|
|
|
|
# Recuperation des données du partenaire
|
|
local_status, my_user = mycommon.get_user_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de recuperer les données de l'utilisateur. "
|
|
|
|
RetObject = []
|
|
nb_val = 0
|
|
|
|
|
|
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 recuperer la liste des candidats " |