diff --git a/GlobalVariable.py b/GlobalVariable.py index df6c595..c8107a3 100644 --- a/GlobalVariable.py +++ b/GlobalVariable.py @@ -181,3 +181,7 @@ elif (MYSY_ENV == "DEV"): INVOICE_FTP_LOCAL_STORAGE_DIRECTORY = "/var/www/html/sftp_iexercice/mysy_invoices_dev/" +""" +Cette Variable definit le nombre de formation associées à retourner +""" +LIMIT_ASSOCIATED_TRAINING = 3 \ No newline at end of file diff --git a/class_mgt.py b/class_mgt.py index 131e567..e5d388a 100644 --- a/class_mgt.py +++ b/class_mgt.py @@ -2276,4 +2276,148 @@ def UpdataPartnerRankingClass(diction): except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno)) - return False, "Impossible de mettre à jour le rang des formations" \ No newline at end of file + return False, "Impossible de mettre à jour le rang des formations" + + +""" +Cette fonction retourne les X formations du meme organisme de formations +associé à une formation données : current_internal_code + +limit : X +condition : internal_url != current_internal_code +partner_owner_recid = current_partner_owner_recid + +""" +def get_associated_class_of_partnair(diction): + try: + ''' + # Verification que les champs reçus dans l'API sont bien dans la liste des champs autorisés + # Cela evite le cas ou une entité tierce ajouter les valeurs inconnu dans l'API + # Ici on doit mettre tous les champs possible (obligatoire ou non) de la BDD dans la liste + # field_list. + ''' + field_list = ['internal_url', 'token', 'title', 'valide', 'locked', 'user_ip', 'user_country_code', 'user_country_name', 'user_city', + 'user_postal', 'user_latitude', 'user_longitude', 'user_state'] + + incom_keys = diction.keys() + for val in incom_keys: + if val not in field_list: + mycommon.myprint( str(inspect.stack()[0][3])+ " - Creation partner account : Le champ '" + val + "' n'existe pas, Creation formation annulée") + return False, " Impossible de recuperer la formation" + + ''' + Une fois qu'on a controlé que toutes les clés mise dans l'API sont correcte. etape precedente, + On controle que les champs obligatoires sont presents dans la liste + ''' + field_list_obligatoire = ['internal_url'] + + 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, " Impossible de recuperer la formation" + + # recuperation des paramettre + mydata = {} + my_internal_url = "" + my_token = "" + + + if ("internal_url" in diction.keys()): + if diction['internal_url']: + my_internal_url = diction['internal_url'] + + coll_name = MYSY_GV.dbname['myclass'] + + # verifier que le token et l'email sont ok + coll_token = MYSY_GV.dbname['user_token'] + + # Verification de la validité du token dans le cas des user en mode connecté + ''' + /!\ Important : si le token est vide, alors c'est une recherche faite en mode non-connecté. + on doit l'accepter. + + le controle de la validé du token est faite que ce dernier n'est pas vide. + ''' + + partner_recid = "None" + + # Recuperation du partner_owner_recid de la formation + query = {'internal_url':my_internal_url} + tmp = coll_name.count_documents(query) + if( tmp <= 0 ): + mycommon.myprint(str(inspect.stack()[0][3]) + " - La valeur : internal_url '" + my_internal_url + "' est KOO dans la myclass") + return False, " Impossible de recuperer la formation" + + tmp_val = coll_name.find_one({'internal_url':my_internal_url},{'partner_owner_recid':1}) + print(str(tmp_val)) + if( tmp_val and tmp_val['partner_owner_recid']): + partner_recid = tmp_val['partner_owner_recid'] + else: + mycommon.myprint(str(inspect.stack()[0][ + 3]) + " - La valeur :tmp_val and tmp_val[0] and tmp_val[0]['partner_owner_recid'] est KOO dans la myclass") + return False, " Impossible de recuperer la formation" + + + + RetObject = [] + filt_external_code = {} + internal_url = "" + if ("internal_url" in diction.keys()): + filt_external_code = {'internal_url':str(diction['internal_url'])} + internal_url = str(diction['internal_url']) + + #print(' ICICICIC '+str(filt_external_code)) + + filt_title = {} + if ("title" in diction.keys()): + filt_title = {'title': {'$regex': str(diction['title'])}} + + + print(" #### avant requete get partner_owner_recid laa ="+str(partner_recid)+ + " internal_url = "+str(my_internal_url)+ + " filt_title = "+str(filt_title)) + + for retVal in coll_name.find({'valide':'1','locked':'0','internal_url': { '$ne': internal_url }, + 'partner_owner_recid':partner_recid, 'published':'1'}, + {"_id": 0, "indexed": 0, "indexed_desc": 0, "indexed_obj": 0, "indexed_title": 0, + "valide": 0, "locked": 0, "partner_owner_recid": 0, } + ).limit(MYSY_GV.LIMIT_ASSOCIATED_TRAINING): + + + + if ("description" in retVal.keys()): + tmp_str = retVal['description'] + if (len(retVal['description']) > MYSY_GV.MAX_CARACT_DETAIL): + retVal['description'] = tmp_str[:MYSY_GV.MAX_CARACT_DETAIL] + " ..." + + + if ("objectif" in retVal.keys()): + tmp_str = retVal['objectif'] + if (len(retVal['objectif']) > MYSY_GV.MAX_CARACT_DETAIL): + retVal['objectif'] = tmp_str[:MYSY_GV.MAX_CARACT_DETAIL] + " ..." + + + + if ("programme" in retVal.keys()): + tmp_str = retVal['programme'] + if (len(retVal['programme']) > MYSY_GV.MAX_CARACT_DETAIL): + retVal['programme'] = tmp_str[:MYSY_GV.MAX_CARACT_DETAIL] + " ..." + + + if ("pedagogie" in retVal.keys()): + tmp_str = retVal['pedagogie'] + if (len(retVal['pedagogie']) > MYSY_GV.MAX_CARACT_DETAIL): + retVal['pedagogie'] = tmp_str[:MYSY_GV.MAX_CARACT_DETAIL] + " ..." + + + #mycommon.myprint(str(retVal)) + user = retVal + RetObject.append(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 recuperer la formation" diff --git a/main.py b/main.py index 7cdea66..b149f26 100644 --- a/main.py +++ b/main.py @@ -270,10 +270,27 @@ def get_class(): # On recupere le corps (payload) de la requete payload = request.form.to_dict() print(" ### payload = ",str(payload)+" IP requester = "+str(request.remote_addr)) - status, retval = cm.get_class(payload) return jsonify(status=status, message=retval) +""" +Cette API retourne les X formations du meme organisme de formations +associé à une formation données : current_internal_code + +limit : X +condition : internal_url != current_internal_code +partner_owner_recid = current_partner_owner_recid + +""" +@app.route('/myclass/api/get_associated_class_of_partnair/', methods=['POST','GET']) +@crossdomain(origin='*') +def get_associated_class_of_partnair(): + # On recupere le corps (payload) de la requete + payload = request.form.to_dict() + print(" ### payload = ",str(payload)+" IP requester = "+str(request.remote_addr)) + status, retval = cm.get_associated_class_of_partnair(payload) + return jsonify(status=status, message=retval) + ''' Cette api recupete la formation d'un partenaire donnée