added generate report in pdf format
This commit is contained in:
@@ -22,8 +22,8 @@ from sqlalchemy.exc import DBAPIError
|
||||
from ..security import groupfinder
|
||||
|
||||
import os
|
||||
import uuid
|
||||
import shutil
|
||||
import pdfkit
|
||||
|
||||
from ..views.default import *
|
||||
from ..models.default import *
|
||||
@@ -546,6 +546,38 @@ def rdf_view(request):
|
||||
# lire tous les photos attachées
|
||||
photos = get_photos(request, rapport.nochantier, norapport)
|
||||
|
||||
if 'form.generate' in request.params:
|
||||
# génère la page rapport
|
||||
result = rdf_rapport(request)
|
||||
result['main_template'] = get_renderer('../templates/layouts/pdf.pt').implementation()
|
||||
htmlcontent = render('../templates/dossier/rdf_rapport.pt', result, request)
|
||||
htmlcontent = htmlcontent.encode('iso8859-15')
|
||||
|
||||
options = {
|
||||
'page-size': 'A4',
|
||||
'margin-top': '0.75in',
|
||||
'margin-right': '0.75in',
|
||||
'margin-bottom': '0.75in',
|
||||
'margin-left': '0.75in',
|
||||
}
|
||||
|
||||
# générer le rapport en PDF
|
||||
filename = "PL-DD%s-rapport RDF no %s.PDF" % (str(rapport.nochantier), norapport)
|
||||
dest = "mondumas/static/DEVFAC/DOCS_ATTACHES/PL/%s/%s" % (str(rapport.nochantier), filename)
|
||||
origin = request.route_url('rdf_rapport', no_id=norapport)
|
||||
config = pdfkit.configuration(wkhtmltopdf="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe")
|
||||
try:
|
||||
pdfkit.from_url(origin, dest, configuration=config, options=options)
|
||||
# pdfkit.from_string(htmlcontent, dest, configuration=config)
|
||||
except:
|
||||
request.session.flash(u"Une erreur est survenue pendant la génération du PDF.", 'danger')
|
||||
return HTTPFound(location=request.route_url('rdf_view', no_id=norapport))
|
||||
else:
|
||||
insert_dossier_attaches(request, nodossier, 0, filename, '160 Ko', logged_in)
|
||||
|
||||
request.session.flash(u"Le rapport a été génré avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('dossier_view', nodossier=nodossier))
|
||||
|
||||
return {
|
||||
'page_title': "Dossier %s : Rapport no %s du %s" % (nodossier, norapport, rapport.date_inter.strftime('%d-%m-%Y')),
|
||||
'url': url,
|
||||
@@ -558,3 +590,23 @@ def rdf_view(request):
|
||||
'docs_url': request.static_url(request.registry.settings['mondumas.devfac_url']),
|
||||
}
|
||||
|
||||
@view_config(route_name='rdf_rapport', renderer='../templates/dossier/rdf_rapport.pt')
|
||||
def rdf_rapport(request):
|
||||
norapport = request.matchdict['no_id']
|
||||
|
||||
# lire le rapport
|
||||
rapport = get_rapport_by_no_id(request, norapport)
|
||||
nodossier = 'PL-' + str(rapport.nochantier)
|
||||
|
||||
# lire tous les photos attachées
|
||||
photos = get_photos(request, rapport.nochantier, norapport)
|
||||
|
||||
return {
|
||||
'page_title': '',
|
||||
'rapport': rapport,
|
||||
'nodossier': nodossier,
|
||||
'nochantier': rapport.nochantier,
|
||||
'norapport': norapport,
|
||||
'photos': photos,
|
||||
'docs_url': request.static_url(request.registry.settings['mondumas.devfac_url']),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user