858 lines
32 KiB
Python
858 lines
32 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", "list_class"]
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer 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']
|
|
|
|
# Verification s'il ya une liste de formation, et si cette liste est correcte
|
|
list_class = ""
|
|
if ("list_class" in diction.keys()):
|
|
list_class = diction['comment']
|
|
if (isinstance(list_class, list) is False):
|
|
mycommon.myprint(
|
|
" La liste des formation n'est pas de type list. ")
|
|
return False, "La liste des formation n'est pas de type list. "
|
|
|
|
|
|
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( date_debut and date_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( date_debut and date_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'
|
|
data['status'] = '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) "
|
|
|
|
|
|
"""
|
|
A présent que l'appel d'offre à été créé, on va verifier s'il y a des formations associées.
|
|
Si oui, on les ajoute à la collection ao_class
|
|
"""
|
|
list_class = ""
|
|
for val in list_class :
|
|
class_data = {}
|
|
if ("domain" in val.keys()):
|
|
class_data['domain'] = diction['domain']
|
|
|
|
if ("objectif" in val.keys()):
|
|
class_data['objectif'] = diction['objectif']
|
|
|
|
if ("nb_participant" in val.keys()):
|
|
class_data['nb_participant'] = diction['nb_participant']
|
|
|
|
if ("date_debut" in val.keys()):
|
|
class_data['date_debut'] = diction['date_debut']
|
|
|
|
if ("date_fin" in val.keys()):
|
|
class_data['date_fin'] = diction['date_fin']
|
|
|
|
if ("lieu" in val.keys()):
|
|
class_data['lieu'] = diction['lieu']
|
|
|
|
if ("budget" in val.keys()):
|
|
class_data['budget'] = diction['budget']
|
|
|
|
if ("comment" in val.keys()):
|
|
class_data['comment'] = diction['comment']
|
|
|
|
class_data['external_code'] = str(external_code)
|
|
class_data['partner_recid'] = str(my_partner['recid'])
|
|
class_data['valide'] = "1"
|
|
|
|
MYSY_GV.dbname['ao_class'].insert_one(class_data)
|
|
|
|
|
|
|
|
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 "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction ajoute et met à jour une formation associé à une appel d'offre
|
|
"""
|
|
def Add_Update_AO_Class(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', "external_code", "list_class"]
|
|
|
|
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', 'external_code']
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data_update = {}
|
|
|
|
external_code = ""
|
|
if ("external_code" in diction.keys()):
|
|
external_code = diction['external_code']
|
|
|
|
# Verification s'il ya une liste de formation, et si cette liste est correcte
|
|
list_class = ""
|
|
if ("list_class" in diction.keys()):
|
|
list_class = diction['comment']
|
|
if (isinstance(list_class, list) is False):
|
|
mycommon.myprint(
|
|
" La liste des formation n'est pas de type list. ")
|
|
return False, "La liste des formation n'est pas de type list. "
|
|
|
|
ret_val_message = ""
|
|
list_class = ""
|
|
cpt = 0
|
|
for val in list_class:
|
|
cpt = cpt + 1
|
|
class_data = {}
|
|
if ("domain" in val.keys()):
|
|
class_data['domain'] = diction['domain']
|
|
|
|
if ("title" in val.keys()):
|
|
class_data['title'] = diction['title']
|
|
|
|
if ("objectif" in val.keys()):
|
|
class_data['objectif'] = diction['objectif']
|
|
|
|
if ("nb_participant" in val.keys()):
|
|
class_data['nb_participant'] = diction['nb_participant']
|
|
|
|
if ("date_debut" in val.keys()):
|
|
class_data['date_debut'] = diction['date_debut']
|
|
|
|
if ("date_fin" in val.keys()):
|
|
class_data['date_fin'] = diction['date_fin']
|
|
|
|
if ("lieu" in val.keys()):
|
|
class_data['lieu'] = diction['lieu']
|
|
|
|
if ("budget" in val.keys()):
|
|
class_data['budget'] = diction['budget']
|
|
|
|
if ("comment" in val.keys()):
|
|
class_data['comment'] = diction['comment']
|
|
|
|
class_data['external_code'] = str(external_code)
|
|
class_data['partner_recid'] = str(my_partner['recid'])
|
|
class_data['valide'] = "1"
|
|
|
|
ret_val = MYSY_GV.dbname['ao_class'].find_one_and_update({'external_code': str(external_code),
|
|
'partner_recid':str(my_partner['recid']), 'valide': '1'},
|
|
{"$set": class_data},
|
|
upsert=True,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
if ("_id" not in ret_val.keys()):
|
|
ret_val_message = ret_val_message +" - Impossible de créer / mettre à jour la formation à la ligne "+str(cpt)
|
|
|
|
|
|
if(len(ret_val_message) > 2):
|
|
return True, str(ret_val_message)
|
|
|
|
return True, " La formation a été ajouter à l'appel d'offre"
|
|
|
|
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 formation à l'appel d'offre "
|
|
|
|
|
|
"""
|
|
Mise à jour d'un appel d'offre.
|
|
|
|
la clé pour la mise à jour est : "external_code" et "partner_recid" issue du token
|
|
|
|
/!\ Le status de l'appel d'offre est comme suit :
|
|
- 0 : Draft, en cours de conception
|
|
- 1 : lancé / publié
|
|
- 2 : cloturé
|
|
|
|
/!\ le scope : scope : public (tout internet), plateforme (que les personne enregistrées sur le mysy), restreint (l'utilisateur saisie une liste d'adresse email a qui l'envoyer)
|
|
- 0 : Tout public
|
|
- 1 : plateforme
|
|
- 2 : restreint (liste email) 343
|
|
|
|
|
|
"""
|
|
def Update_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",
|
|
"status"]
|
|
|
|
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', 'external_code']
|
|
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 récupérer les données du partenaire")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données du partenaire. "
|
|
|
|
"""
|
|
Recuperation des données fournies en entrée
|
|
"""
|
|
|
|
data_update = {}
|
|
|
|
external_code = ""
|
|
if ("external_code" in diction.keys()):
|
|
external_code = diction['external_code']
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['external_code'] = str(external_code)
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
description = ""
|
|
if ("description" in diction.keys()):
|
|
data_update['description'] = diction['description']
|
|
|
|
contact = ""
|
|
if ("contact" in diction.keys()):
|
|
data_update['contact'] = diction['contact']
|
|
|
|
description_critere_selection = ""
|
|
if ("description_critere_selection" in diction.keys()):
|
|
data_update['description_critere_selection'] = diction['description_critere_selection']
|
|
|
|
comment = ""
|
|
if ("comment" in diction.keys()):
|
|
data_update['comment'] = diction['comment']
|
|
|
|
status = ""
|
|
if ("status" in diction.keys()):
|
|
if( str(diction['status']) not in ["0", "1", "2"]):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le statut de l'appel d'offre doit etre 0, 1 ou 2. Information fournie :"+str(diction['status']) )
|
|
return False, " - Le statut de l'appel d'offre doit etre 0, 1 ou 2. Information fournie :"+str(diction['status'])+" "
|
|
|
|
data_update['status'] = diction['status']
|
|
|
|
|
|
list_produits_appel_offre = ""
|
|
if ("list_produits_appel_offre" in diction.keys()):
|
|
data_update['list_produits_appel_offre'] = diction['list_produits_appel_offre']
|
|
|
|
date_debut = ""
|
|
if ("date_debut" in diction.keys()):
|
|
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 "
|
|
|
|
data_update['date_debut'] = diction['date_debut']
|
|
|
|
date_fin = ""
|
|
if ("date_fin" in diction.keys()):
|
|
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 "
|
|
|
|
data_update['date_fin'] = diction['date_fin']
|
|
|
|
"""
|
|
Controle cohérence des dates debut et fin
|
|
"""
|
|
if (date_debut and date_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) + " "
|
|
|
|
|
|
date_deliberation = ""
|
|
if ("date_deliberation" in diction.keys()):
|
|
if diction['date_deliberation']:
|
|
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 "
|
|
|
|
data_update['date_deliberation'] = diction['date_deliberation']
|
|
|
|
data_update['date_update'] = str(datetime.now())
|
|
"""
|
|
Controle cohérence des dates debut et la date de deliberation
|
|
"""
|
|
if (date_debut and date_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) + " "
|
|
|
|
|
|
inserted_id = ""
|
|
result = MYSY_GV.dbname['appel_offre'].find_one_and_update(
|
|
data_cle,
|
|
{"$set": data_update},
|
|
upsert=False,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
if ("_id" not in result.keys()):
|
|
mycommon.myprint(
|
|
" Impossible de mettre à jour l'appel d'offre: external_code = " + str(external_code))
|
|
return False, " Impossible de mettre à jour l'appel d'offre "
|
|
|
|
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 donné
|
|
"""
|
|
def Get_Given_Appel_Offre(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'external_code']
|
|
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', 'external_code']
|
|
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_partner = mycommon.get_user_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
external_code = ""
|
|
if ("external_code" in diction.keys()):
|
|
external_code = diction['external_code']
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['external_code'] = str(external_code)
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
print(" #### data_cle 01= " + str(data_cle))
|
|
|
|
for retval in MYSY_GV.dbname['appel_offre'].find(data_cle):
|
|
user = 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 l'appel d'offre "
|
|
|
|
|
|
"""
|
|
Fonction retourne une liste de d'appel d'offre d'un partenaire
|
|
"""
|
|
def Get_List_Appel_Offre(diction):
|
|
try:
|
|
diction = mycommon.strip_dictionary(diction)
|
|
|
|
"""
|
|
Verification des input acceptés
|
|
"""
|
|
field_list = ['token', 'status']
|
|
|
|
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', 'external_code']
|
|
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_partner = mycommon.get_user_data_from_token(token)
|
|
if (local_status is False):
|
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur ")
|
|
return False, str(inspect.stack()[0][3]) + " - impossible de récupérer les données de l'utilisateur. "
|
|
|
|
|
|
|
|
"""
|
|
Clés de mise à jour
|
|
"""
|
|
data_cle = {}
|
|
data_cle['partner_recid'] = str(my_partner['recid'])
|
|
data_cle['valide'] = "1"
|
|
data_cle['locked'] = "0"
|
|
|
|
status = ""
|
|
if ("status" in diction.keys()):
|
|
if (str(diction['status']) not in ["0", "1", "2"]):
|
|
mycommon.myprint(
|
|
str(inspect.stack()[0][
|
|
3]) + " - Le statut de l'appel d'offre doit etre 0, 1 ou 2. Information fournie :" + str(
|
|
diction['status']))
|
|
return False, " - Le statut de l'appel d'offre doit etre 0, 1 ou 2. Information fournie :" + str(diction['status'])+" "
|
|
|
|
|
|
data_cle['status'] = diction['status']
|
|
|
|
|
|
RetObject = []
|
|
val_tmp = 1
|
|
|
|
print(" #### data_cle 01= " + str(data_cle))
|
|
|
|
for retval in MYSY_GV.dbname['appel_offre'].find(data_cle):
|
|
user = 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 appels d'offre "
|
|
|
|
|
|
"""
|
|
Cette fonction effectue une manifestation d'interet d'un institut de formation pour l'AO
|
|
"""
|
|
def Add_Manifestation_Interet_Appel_Offre(diction):
|
|
try:
|
|
return True, ""
|
|
|
|
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 la manifestation d'interet pour l'appel d'offre "
|
|
|
|
|
|
|
|
"""
|
|
Recuperation de list des manifesations d'interet pour un AO
|
|
"""
|
|
def Get_List_Manifestation_Interet_Appel_Offre(diction):
|
|
try:
|
|
return True, ""
|
|
|
|
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 recupérer la liste des manifestations d'interet pour l'appel d'offre "
|
|
|
|
|
|
|
|
|
|
"""
|
|
Cette fonction effectue une réponse à l'AO d'un institut de formation
|
|
"""
|
|
def Add_Reponse_Appel_Offre(diction):
|
|
try:
|
|
return True, ""
|
|
|
|
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 la réponse pour l'appel d'offre "
|
|
|
|
|
|
"""
|
|
Recuperation de list des réponses à un AO
|
|
"""
|
|
def Get_List_Reponse_Appel_Offre(diction):
|
|
try:
|
|
return True, ""
|
|
|
|
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 recupérer la liste des réponses pour l'appel d'offre "
|
|
|
|
|