22/11/2023 - 23h00

master
cherif 2023-11-22 23:19:56 +01:00
parent da094a3759
commit 532c98415a
5 changed files with 1633 additions and 4 deletions

View File

@ -4,8 +4,9 @@
<list default="true" id="c6d0259a-16e1-410d-91a1-830590ee2a08" name="Changes" comment="20/11/2023 - 21h00">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Log/log_file.log" beforeDir="false" afterPath="$PROJECT_DIR$/Log/log_file.log" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Session_Formation_Sequence.py" beforeDir="false" afterPath="$PROJECT_DIR$/Session_Formation_Sequence.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/agenda.py" beforeDir="false" afterPath="$PROJECT_DIR$/agenda.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/base_config_modele_journee.py" beforeDir="false" afterPath="$PROJECT_DIR$/base_config_modele_journee.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/base_partner_session_step.py" beforeDir="false" afterPath="$PROJECT_DIR$/base_partner_session_step.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

File diff suppressed because it is too large Load Diff

View File

@ -37,6 +37,109 @@ from email.mime.base import MIMEBase
from email import encoders
"""
Ajout et mise à jour d'un modele de journée
"""
def Add_Update_Modele_Journee(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token', '_id', 'modele_journee']
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', 'modele_journee']
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
journee_model_id = ""
if ("_id" in diction.keys()):
if diction['_id']:
journee_model_id = diction['_id']
my_data = diction['modele_journee']
my_data_JSON = json.loads(str(my_data))
my_data_JSON['valide'] = '1'
my_data_JSON['locked'] = '0'
my_data_JSON['partner_owner_recid'] = str(my_partner['recid'])
print(" #### my_data_JSON = ", my_data_JSON)
# Si journee_model_id est vide on est en mode creation, si non on est en mode mise à jour
if( str(journee_model_id).strip() != ""):
# Verifier si l'_id existe vraiment en base de donnée
is_journee_model_id_valide_exist = MYSY_GV.dbname['base_config_modele_journee'].count_documents({'_id':ObjectId(str(journee_model_id)),
'valide':'1',
'locked':'0',
'partner_owner_recid':str(my_partner['recid'])})
if( is_journee_model_id_valide_exist <= 0 ):
mycommon.myprint(str(
inspect.stack()[0][3]) + " L'identifiant du modèle est invalide ")
return False, " L'identifiant du modèle est invalide "
# Il s'agit d'une mise à jour
my_data_JSON['date_update'] = str(datetime.now())
result = MYSY_GV.dbname['base_config_modele_journee'].find_one_and_update(
{'partner_owner_recid': str(my_partner['recid']),
'_id': ObjectId(str(diction['_id'])),
'valide': '1',
'locked': '0'},
{"$set": my_data_JSON},
return_document=ReturnDocument.AFTER,
upsert=False,
)
else:
# Il s'agit d'une creation
result = MYSY_GV.dbname['base_config_modele_journee'].insert_one(my_data_JSON)
return True, " La configuration a été correctement ajoutée / 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 d'ajouter la configuration "
"""
Recuperation d'un journée type en partant de l'_id
"""
@ -98,3 +201,97 @@ def Get_Given_Modele_Journee(diction):
return False, " Impossible de récupérer la liste des points de paramétrage "
"""
Recuperation d'un journée type en par defaut
"""
def Get_Default_Modele_Journee(diction):
try:
diction = mycommon.strip_dictionary(diction)
"""
Verification des input acceptés
"""
field_list = ['token',]
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', ]
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 = []
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
'locked': '0'}
New_retVal_count = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry)
if( New_retVal_count > 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Plusieurs modèles existe. Les données sont incohérentes ")
return False, " Plusieurs modèles existe. Les données sont incohérentes",
elif (New_retVal_count <= 0):
# Aucun modèle pour ce partenaire, on va aller chercher le modèle par defaut de mysy
qry_mysy = {'partner_owner_recid': "default", 'valide': '1',
'locked': '0'}
New_retVal_count_mysy = MYSY_GV.dbname['base_config_modele_journee'].count_documents(qry_mysy)
if( New_retVal_count_mysy != 1):
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Aucun modèle de journée de travail n'est configuré dans le système ")
return False, " Aucun modèle de journée de travail n'est configuré dans le système ",
else:
New_retVal_mysy_data = MYSY_GV.dbname['base_config_modele_journee'].find_one( qry_mysy)
RetObject.append(mycommon.JSONEncoder().encode(New_retVal_mysy_data))
# print(" ### retval_json =", retval_json)
return True, RetObject
elif (New_retVal_count <= 1):
qry = {'partner_owner_recid': str(my_partner['recid']), 'valide': '1',
'locked': '0'}
New_retVal_data = MYSY_GV.dbname['base_config_modele_journee'].find_one(qry)
RetObject.append(mycommon.JSONEncoder().encode(New_retVal_data))
# print(" ### retval_json =", retval_json)
return True, RetObject
else:
mycommon.myprint(
str(inspect.stack()[0][3]) + " - Impossible de trouver un modèle de journée de travail dans le système ")
return False, " Impossible de trouver un modèle de journée de travail dans le système ",
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 points de paramétrage (jounée de travail) "

View File

@ -112,8 +112,6 @@ def Add_Update_Partner_session_step(diction):
)
return True, " La configuration a été correctement ajoutée / Mise à jour"
except Exception as e:

29
main.py
View File

@ -61,6 +61,8 @@ import agenda as agenda
import base_partner_session_step as base_partner_session_step
import Session_Formation_Sequence as Session_Formation_Sequence
import base_config_modele_journee as base_config_modele_journee
app = Flask(__name__)
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'
@ -5654,6 +5656,33 @@ def Create_Automatic_Sequence():
return jsonify(status=status, message=retval)
"""
API Creation d'un modèle journée de travail
"""
@app.route('/myclass/api/Add_Update_Modele_Journee/', methods=['POST','GET'])
@crossdomain(origin='*')
def Add_Update_Modele_Journee():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Add_Update_Modele_Journee payload = ",payload)
status, retval = base_config_modele_journee.Add_Update_Modele_Journee(payload)
return jsonify(status=status, message=retval)
"""
API Recuperation du modèle journée de travail du partenaire ou celui par defaut du système
"""
@app.route('/myclass/api/Get_Default_Modele_Journee/', methods=['POST','GET'])
@crossdomain(origin='*')
def Get_Default_Modele_Journee():
# On recupere le corps (payload) de la requete
payload = mycommon.strip_dictionary (request.form.to_dict())
print(" ### Get_Default_Modele_Journee payload = ",payload)
status, retval = base_config_modele_journee.Get_Default_Modele_Journee(payload)
return jsonify(status=status, message=retval)
if __name__ == '__main__':
print(" debut api")
context = SSL.Context(SSL.SSLv23_METHOD)