ajout pdfkit dans production
This commit is contained in:
@@ -49,9 +49,13 @@ class GlobalLayout(object):
|
||||
|
||||
def isWebPage(self):
|
||||
# test view name
|
||||
if self.request.matched_route.name == 'rdf_rapport':
|
||||
# oui, page PDF
|
||||
return False
|
||||
if self.request.matched_route:
|
||||
if self.request.matched_route.name == 'rdf_rapport':
|
||||
# oui, page PDF
|
||||
return False
|
||||
else:
|
||||
# non, page web
|
||||
return True
|
||||
else:
|
||||
# non, page web
|
||||
return True
|
||||
|
||||
@@ -181,4 +181,45 @@
|
||||
width: 350px;
|
||||
height: 150px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.gly-spin {
|
||||
-webkit-animation: spin 2s infinite linear;
|
||||
-moz-animation: spin 2s infinite linear;
|
||||
-o-animation: spin 2s infinite linear;
|
||||
animation: spin 2s infinite linear;
|
||||
}
|
||||
@-moz-keyframes spin {
|
||||
0% {
|
||||
-moz-transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-moz-transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@-o-keyframes spin {
|
||||
0% {
|
||||
-o-transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-o-transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@keyframes spin {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(359deg);
|
||||
transform: rotate(359deg);
|
||||
}
|
||||
}
|
||||
@@ -351,8 +351,8 @@
|
||||
<br />
|
||||
<a class="btn btn-default" href="/rdf_rapport/${rapport.no_id}">
|
||||
<span class="glyphicon glyphicon-file"></span> Aperçu PDF</a>
|
||||
<button class="btn btn-warning" type="submit" name="form.generate">
|
||||
<span class="glyphicon glyphicon-file"></span> Générer PDF</button>
|
||||
<button id="generateButton" class="btn btn-warning" type="submit" name="form.generate">
|
||||
<i class="glyphicon glyphicon-refresh"></i> Générer PDF</button>
|
||||
<a class="btn btn-primary" href="/rdf_bill/${rapport.no_id}">
|
||||
<span class="glyphicon glyphicon-fith-listle"></span> Générer Facture</a>
|
||||
</div>
|
||||
@@ -366,6 +366,13 @@
|
||||
|
||||
</div>
|
||||
<div metal:fill-slot="additional_scripts">
|
||||
<script type="text/javascript">
|
||||
$('#generateButton').on('click', function(){
|
||||
$('i.gly-spin').removeClass('gly-spin');
|
||||
$('i').addClass('gly-spin');
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- JSignature plugin -->
|
||||
<script src="${request.static_url('mondumas:static/dist/jSignature/libs/jSignature.min.js')}"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<!-- Bootstrap + jQuery JavaScript plugins) -->
|
||||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
|
||||
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
|
||||
|
||||
<!-- Bootstrap moment plugin -->
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
|
||||
|
||||
@@ -575,25 +575,30 @@ def rdf_view(request):
|
||||
path = '%s/%s/%s/%s' % (request.registry.settings['mondumas.devfac_dir'], 'PL', rapport.nochantier, norapport)
|
||||
os.makedirs(path, exist_ok=True)
|
||||
# générer le rapport en PDF
|
||||
filename = "PL-DD%s-rapport_RDF_no_%s.PDF" % (str(rapport.nochantier), norapport)
|
||||
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")
|
||||
import pdb;pdb.set_trace()
|
||||
try:
|
||||
pdfkit.from_url(origin, dest, configuration=config, options=options)
|
||||
except:
|
||||
request.session.flash(u"Erreur de génération du PDF. Pensez à créer le lien static/DEVFAC", 'danger')
|
||||
return HTTPFound(location=request.route_url('rdf_view', no_id=norapport))
|
||||
else:
|
||||
insert_dossier_attaches(request, nodossier, 0, filename, '160 Ko', logged_in)
|
||||
# si generation pdf, maj de la date du rapport
|
||||
new_values = {}
|
||||
new_values['date_rapport'] = date.today()
|
||||
update_rapport(request, nodossier, rapport.date_inter.strftime('%Y-%m-%d'), new_values)
|
||||
|
||||
request.session.flash(u"Le rapport a été génré avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('dossier_view', nodossier=nodossier))
|
||||
# developpement ou production
|
||||
if "smtp.orange" in request.registry.settings["mail.host"] :
|
||||
origin = 'https://gestion.entreprise-dumas.com/rdf_rapport/%s' % norapport
|
||||
try:
|
||||
pdfkit.from_url(origin, dest, options=options)
|
||||
except:
|
||||
request.session.flash(u"Erreur de génération du PDF. Pensez à créer le lien static/DEVFAC", 'danger')
|
||||
return HTTPFound(location=request.route_url('rdf_view', no_id=norapport))
|
||||
else:
|
||||
origin = request.route_url('rdf_rapport', no_id=norapport)
|
||||
pdfkit.from_url(origin, dest, configuration=config, options=options)
|
||||
|
||||
insert_dossier_attaches(request, nodossier, 0, filename, '160 Ko', logged_in)
|
||||
# si generation pdf, maj de la date du rapport
|
||||
new_values = {}
|
||||
new_values['date_rapport'] = date.today()
|
||||
update_rapport(request, nodossier, rapport.date_inter.strftime('%Y-%m-%d'), new_values)
|
||||
|
||||
request.session.flash(u"Le rapport a été génré avec succès.", 'success')
|
||||
return HTTPFound(location=request.route_url('dossier_view', nodossier=nodossier))
|
||||
|
||||
if 'form.validate' in request.params:
|
||||
validate_rapport(request, norapport)
|
||||
|
||||
Reference in New Issue
Block a user