25/10/22 - 22h30
parent
914c0393c4
commit
3e34531a14
|
@ -163,6 +163,11 @@ Repertoire de depot des factures
|
||||||
#INVOICE_DIRECTORY = "/var/www/html/sftp_iexercice/mysy_invoices"
|
#INVOICE_DIRECTORY = "/var/www/html/sftp_iexercice/mysy_invoices"
|
||||||
INVOICE_DIRECTORY = "./Invoices/"
|
INVOICE_DIRECTORY = "./Invoices/"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Repertoire pour les liste d'emargement
|
||||||
|
"""
|
||||||
|
EMARGEMENT_DIRECTORY = "./Emargement/"
|
||||||
|
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
170
emargement.py
170
emargement.py
|
@ -18,7 +18,11 @@ import GlobalVariable as MYSY_GV
|
||||||
from math import isnan
|
from math import isnan
|
||||||
import GlobalVariable as MYSY_GV
|
import GlobalVariable as MYSY_GV
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from xhtml2pdf import pisa
|
||||||
|
import jinja2
|
||||||
|
import ftplib
|
||||||
|
import pysftp
|
||||||
|
from flask import send_file
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Creation du tableau d'emargement
|
Creation du tableau d'emargement
|
||||||
|
@ -344,3 +348,167 @@ def UpdateUserEmargementDate(diction):
|
||||||
exc_type, exc_obj, exc_tb = sys.exc_info()
|
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))
|
mycommon.myprint(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
return False, "Impossible de valider l'émargement"
|
return False, "Impossible de valider l'émargement"
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Cette fonction genere un fichier pdf pour les liste d'emargement
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def GerneratePDFEmargementList(diction):
|
||||||
|
try:
|
||||||
|
field_list = ['session_id', 'email', 'date', 'token', 'class_internal_url']
|
||||||
|
incom_keys = diction.keys()
|
||||||
|
for val in incom_keys:
|
||||||
|
if val not in field_list:
|
||||||
|
mycommon.myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " - La valeur '" + val + "' n'est pas presente dans liste ")
|
||||||
|
return False, " Impossible d'imprimer la liste d'emargement"
|
||||||
|
|
||||||
|
"""
|
||||||
|
Verification de la liste des champs obligatoires
|
||||||
|
"""
|
||||||
|
field_list_obligatoire = ['session_id', 'token', 'class_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 d'imprimer la liste d'emargement"
|
||||||
|
|
||||||
|
query_get_data = {}
|
||||||
|
mytoken = ""
|
||||||
|
if ("token" in diction.keys()):
|
||||||
|
if diction['token']:
|
||||||
|
mytoken = diction['token']
|
||||||
|
|
||||||
|
partner_recid = mycommon.get_parnter_recid_from_token(mytoken)
|
||||||
|
if (partner_recid is False):
|
||||||
|
mycommon.myprint(str(inspect.stack()[0][3]) + " - Impossible d'imprimer la liste d'emargement ")
|
||||||
|
return False, " Impossible d'imprimer la liste d'emargement"
|
||||||
|
|
||||||
|
myclass_internal_url = ""
|
||||||
|
if ("class_internal_url" in diction.keys()):
|
||||||
|
if diction['class_internal_url']:
|
||||||
|
myclass_internal_url = diction['class_internal_url']
|
||||||
|
|
||||||
|
mysession_id = ""
|
||||||
|
if ("session_id" in diction.keys()):
|
||||||
|
if diction['session_id']:
|
||||||
|
mysession_id = diction['session_id']
|
||||||
|
query_get_data['session_id'] = diction['session_id']
|
||||||
|
|
||||||
|
myemail = ""
|
||||||
|
if ("email" in diction.keys()):
|
||||||
|
if diction['email']:
|
||||||
|
myemail = diction['email']
|
||||||
|
query_get_data['email'] = diction['email']
|
||||||
|
|
||||||
|
mydate = ""
|
||||||
|
if ("date" in diction.keys()):
|
||||||
|
if diction['date']:
|
||||||
|
mydate = diction['date']
|
||||||
|
query_get_data['date'] = diction['date']
|
||||||
|
|
||||||
|
## Recuperation des données
|
||||||
|
coll_emargement = MYSY_GV.dbname['emargement']
|
||||||
|
|
||||||
|
#print("### query_get_data = " + str(query_get_data))
|
||||||
|
|
||||||
|
tab_users = []
|
||||||
|
for val_tmp in coll_emargement.find(query_get_data).sort([("date", pymongo.ASCENDING)]):
|
||||||
|
local_tmp = {}
|
||||||
|
local_tmp['email'] = val_tmp['email']
|
||||||
|
local_tmp['nom'] = val_tmp['nom']
|
||||||
|
local_tmp['prenom'] = val_tmp['prenom']
|
||||||
|
local_tmp['matin'] = val_tmp['matin']
|
||||||
|
local_tmp['apresmidi'] = val_tmp['apresmidi']
|
||||||
|
local_tmp['date'] = val_tmp['date']
|
||||||
|
|
||||||
|
tab_users.append(local_tmp)
|
||||||
|
|
||||||
|
#print(' ### tab_users = ' + str(tab_users))
|
||||||
|
|
||||||
|
## Recuperation des info de la formation
|
||||||
|
class_title = ""
|
||||||
|
for val_tmp in MYSY_GV.dbname['myclass'].find({'internal_url': str(myclass_internal_url)}):
|
||||||
|
class_title = val_tmp['title']
|
||||||
|
|
||||||
|
mytoday = datetime.today().strftime("%d/%m/%Y")
|
||||||
|
|
||||||
|
#print(' ### class_title = ' + str(class_title))
|
||||||
|
|
||||||
|
templateLoader = jinja2.FileSystemLoader(searchpath="./")
|
||||||
|
templateEnv = jinja2.Environment(loader=templateLoader)
|
||||||
|
TEMPLATE_FILE = "Template/tpl_emargement.html"
|
||||||
|
template = templateEnv.get_template(TEMPLATE_FILE)
|
||||||
|
# This data can come from database query
|
||||||
|
body = {
|
||||||
|
"data": {
|
||||||
|
"title": str(class_title),
|
||||||
|
"date": str(mytoday),
|
||||||
|
},
|
||||||
|
"user": tab_users
|
||||||
|
}
|
||||||
|
|
||||||
|
#print(" ### body = " + str(body))
|
||||||
|
|
||||||
|
sourceHtml = template.render(json_data=body["data"], users=body["user"])
|
||||||
|
orig_file_name = "test_emargement.pdf"
|
||||||
|
outputFilename = str(MYSY_GV.EMARGEMENT_DIRECTORY) + str(orig_file_name)
|
||||||
|
|
||||||
|
# open output file for writing (truncated binary)
|
||||||
|
resultFile = open(outputFilename, "w+b")
|
||||||
|
|
||||||
|
# convert HTML to PDF
|
||||||
|
pisaStatus = pisa.CreatePDF(
|
||||||
|
src=sourceHtml, # the HTML to convert
|
||||||
|
dest=resultFile) # file handle to receive result
|
||||||
|
|
||||||
|
# close output file
|
||||||
|
resultFile.close()
|
||||||
|
|
||||||
|
#print(" ### outputFilename = "+str(outputFilename))
|
||||||
|
if os.path.exists(outputFilename):
|
||||||
|
#print(" ### ok os.path.exists(outputFilename) "+str(outputFilename))
|
||||||
|
return True, send_file(outputFilename, as_attachment=True)
|
||||||
|
|
||||||
|
# myprint(str(inspect.stack()[0][3]) +" debut envoie de la factureeee "+diction['invoice_id'])
|
||||||
|
|
||||||
|
# email.SendInvoiceEmail(str(diction['invoice_email']), diction)
|
||||||
|
|
||||||
|
# On deplace la facture vers le serveur ftp
|
||||||
|
'''myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " deplacement de la facture vers " + str(
|
||||||
|
outputFilename))
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
cnopts = pysftp.CnOpts()
|
||||||
|
cnopts.hostkeys = None
|
||||||
|
with pysftp.Connection(host=MYSY_GV.MYSY_FTP_HOST, username=MYSY_GV.MYSY_FTP_LOGIN,
|
||||||
|
password=MYSY_GV.MYSY_FTP_PWD, cnopts=cnopts) as session:
|
||||||
|
print("Connection successfully established ... ")
|
||||||
|
localFilePath = outputFilename
|
||||||
|
remoteFilePath = str(MYSY_GV.INVOICE_FTP_LOCAL_STORAGE_DIRECTORY) + str(orig_file_name)
|
||||||
|
|
||||||
|
# print(" DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(remoteFilePath) + " AVANTTT TRAITEMENT")
|
||||||
|
# Use put method to upload a file
|
||||||
|
session.put(localFilePath, remoteFilePath)
|
||||||
|
# Switch to a remote directory
|
||||||
|
myprint(
|
||||||
|
str(inspect.stack()[0][3]) + " DEPLACEMENT DE " + str(localFilePath) + " VERS " + str(
|
||||||
|
remoteFilePath) + " EST OKKKK")
|
||||||
|
|
||||||
|
"""
|
||||||
|
# return True on success and False on errors
|
||||||
|
print(pisaStatus.err, type(pisaStatus.err))
|
||||||
|
|
||||||
|
return True, " le fichier generé "
|
||||||
|
except Exception as e:
|
||||||
|
exc_type, exc_obj, exc_tb = sys.exc_info()
|
||||||
|
print(str(inspect.stack()[0][3]) + " -" + str(e) + " - ERRORRRR AT Line : " + str(exc_tb.tb_lineno))
|
||||||
|
return False, False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
21
main.py
21
main.py
|
@ -1818,7 +1818,28 @@ def GetSessionFormation():
|
||||||
localStatus, message= SF.GetSessionFormation(payload)
|
localStatus, message= SF.GetSessionFormation(payload)
|
||||||
return jsonify(status=localStatus, message=message )
|
return jsonify(status=localStatus, message=message )
|
||||||
|
|
||||||
|
"""
|
||||||
|
API de generation de liste PDF des liste d'emargement
|
||||||
|
"""
|
||||||
|
@app.route('/myclass/api/GerneratePDFEmargementList/<token>/<session_id>/<internal_url>', methods=['POST','GET'])
|
||||||
|
@crossdomain(origin='*')
|
||||||
|
def GerneratePDFEmargementList(token, session_id, internal_url):
|
||||||
|
# On recupere le corps (payload) de la requete
|
||||||
|
payload = request.form.to_dict()
|
||||||
|
payload = {}
|
||||||
|
payload['token'] = str(token)
|
||||||
|
payload['session_id'] = str(session_id)
|
||||||
|
payload['class_internal_url'] = str(internal_url)
|
||||||
|
|
||||||
|
print(" ### GerneratePDFEmargementList : payload = ",str(payload))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
localStatus, response= emargement.GerneratePDFEmargementList(payload)
|
||||||
|
if(localStatus ):
|
||||||
|
return response
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(" debut api")
|
print(" debut api")
|
||||||
|
|
|
@ -32,6 +32,11 @@ import email_mgt as email_mgt
|
||||||
import random
|
import random
|
||||||
import json
|
import json
|
||||||
import Ela_Spacy as ElaSpacy
|
import Ela_Spacy as ElaSpacy
|
||||||
|
from flask import Flask, Response, render_template
|
||||||
|
from xhtml2pdf import pisa
|
||||||
|
import jinja2
|
||||||
|
import ftplib
|
||||||
|
import pysftp
|
||||||
|
|
||||||
class JSONEncoder(json.JSONEncoder):
|
class JSONEncoder(json.JSONEncoder):
|
||||||
def default(self, o):
|
def default(self, o):
|
||||||
|
@ -2291,3 +2296,5 @@ Cette fonction enleve les caractères non ascii
|
||||||
"""
|
"""
|
||||||
def remove_non_ascii(string):
|
def remove_non_ascii(string):
|
||||||
return ''.join(char for char in string if ord(char) < 128)
|
return ''.join(char for char in string if ord(char) < 128)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue