TG-62 template et API insert
This commit is contained in:
82
backend/app/api/ExportPdfAPI.py
Normal file
82
backend/app/api/ExportPdfAPI.py
Normal file
@ -0,0 +1,82 @@
|
||||
from flask_restful import Resource
|
||||
|
||||
from app.model import *
|
||||
from app.tools.LibPdf import fusion_fichiers
|
||||
|
||||
|
||||
class ExportPdfAPI(Resource):
|
||||
def get(self, uid=0, gid=0, name=""):
|
||||
if uid > 0:
|
||||
|
||||
user = getUser(uid=uid)
|
||||
|
||||
group = getGroup(gid)
|
||||
|
||||
if user is None:
|
||||
return {"ERROR": "The user with id " + str(gid) + " does not exists !"}, 400
|
||||
|
||||
prenom = user["name"].split(" ", 1)
|
||||
nom = user["name"].split(" ", 2)
|
||||
|
||||
group["name"]
|
||||
|
||||
annee1 = group["year"]
|
||||
annee2 = int(group["year"]) + 1
|
||||
promo = group["class_short"]
|
||||
|
||||
group["class_long"]
|
||||
group["departement"]
|
||||
group["resp_id"]
|
||||
group["sec_id"]
|
||||
group["ressources_dir"]
|
||||
|
||||
self.data = {
|
||||
'page1.nom_master': 'Renan',
|
||||
'page1.nom_complet_master': 'Husson',
|
||||
'page1.annee_1': 'Husson',
|
||||
'page1.annee_2': 'Jean Jaures',
|
||||
'page1.nom_prenom': 'Panda',
|
||||
'page1.email': 'Panda',
|
||||
'page1.telephone': 'Panda',
|
||||
'page1.entreprise': 'Panda',
|
||||
'page1.tuteur_pedagogique': 'Panda',
|
||||
'page1.tuteur_entreprise': 'Panda',
|
||||
'page2.type_contrat_apprentissage': True,
|
||||
'page2.type_contrat_professionnalisation': True,
|
||||
'page2.type_contrat_stage': True,
|
||||
'page2.debut_contrat': 'Panda',
|
||||
'page2.fin_contrat': 'Panda',
|
||||
'page2.telephone': 'Panda',
|
||||
'page2.email': 'Panda',
|
||||
'page2.compostant_formation': 'Panda',
|
||||
'page2.responsable_pedagogique_formation': 'Panda',
|
||||
'page2.tel_responsable_pedagogique_formation': 'Panda',
|
||||
'page2.mail_responsable_pedagogique_formation': 'Panda',
|
||||
'page2.tel_tuteur_pedagogique': 'Panda',
|
||||
'page2.mail_tuteur_pedagogique': 'Panda',
|
||||
'page2.tuteur_entreprise': 'Panda',
|
||||
'page2.entreprise': 'Panda',
|
||||
'page2.adresse_entreprise': 'Panda',
|
||||
'page2.tel_tuteur_entreprise': 'Panda',
|
||||
'page2.mail_tuteur_entreprise': 'Panda',
|
||||
'page4.poste_occupe': 'Panda',
|
||||
'page4.poste_occupe_2': 'Panda',
|
||||
'PEntreprise.n_periode': 'Panda',
|
||||
'PEntreprise.debut_periode': 'Panda',
|
||||
'PEntreprise.fin_periode': 'Panda',
|
||||
'PEntreprise.travaux_entreprise': 'Panda',
|
||||
'PEntreprise.remarque_tuteur': 'Panda',
|
||||
'pagePFormation.n_periode': 'Panda',
|
||||
'pagePFormation.bilan_periode': 'Panda',
|
||||
|
||||
}
|
||||
|
||||
pdf_fusion = ["/page1.pdf", "/page2.pdf"]
|
||||
chemin_pdf = "/tmp"
|
||||
|
||||
nom_pdf = "Livret_Alternant_BOB_Armandeau.pdf"
|
||||
|
||||
fusion_fichiers(chemin_pdf, nom_pdf, pdf_fusion)
|
||||
|
||||
# Prenom NOM
|
||||
# remplir_template()
|
@ -55,15 +55,14 @@ def allowed_file(filename):
|
||||
|
||||
def upload_file(file_to_upload, upload_folder):
|
||||
"""
|
||||
rep de l'etu avec id
|
||||
:param file:
|
||||
televersement d'un fichier
|
||||
:param file_to_upload:
|
||||
:param upload_folder:
|
||||
:return:
|
||||
"""
|
||||
file_to_upload.save(os.path.join(upload_folder, secure_filename(file_to_upload.filename)))
|
||||
|
||||
|
||||
|
||||
def delete_file(pdf_path):
|
||||
if os.path.exists(pdf_path):
|
||||
os.remove(pdf_path)
|
||||
|
@ -1,20 +1,25 @@
|
||||
import filecmp
|
||||
import os
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from app.tools.LibPdf import upload_file
|
||||
from app.tools.LibPdf import upload_file, allowed_file
|
||||
|
||||
|
||||
class TestFusionTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.datadir = os.path.join(os.path.dirname(__file__))
|
||||
self.datadir = "upload/page1.pdf"
|
||||
self.file_name = "page1.pdf"
|
||||
|
||||
def test_fusion(self):
|
||||
with open("page1.pdf", 'rb') as fp:
|
||||
with open(self.file_name, 'rb') as fp:
|
||||
file = FileStorage(fp)
|
||||
upload_file(file, "upload")
|
||||
|
||||
# self.assertTrue(Path(self.datadir + "/testFusion.pdf").is_file(), "Pdf fusionne inexistant")
|
||||
# self.assertTrue(len(get_pdf_from_directory(self.datadir)) > 0, "pdf non trouve")
|
||||
# os.remove(self.datadir + "/testFusion.pdf")
|
||||
self.assertTrue(Path(self.datadir).is_file(), "Pdf upload inexistant")
|
||||
self.assertTrue(filecmp.cmp(self.datadir, self.file_name), "fichiers non identique")
|
||||
self.assertTrue(allowed_file(self.file_name), "format non conforme")
|
||||
|
||||
os.remove(self.datadir)
|
||||
|
Reference in New Issue
Block a user