[IMP] qweb-pdf reports are now downloaded instead of being openned in a popup. It is done by using the 'session.get_file' of the webclient.

bzr revid: sle@openerp.com-20140218125322-yym87kc2c0guhgg2
This commit is contained in:
Simon Lejeune 2014-02-18 13:53:22 +01:00
parent ed9061893a
commit 3c6c3d91d5
2 changed files with 33 additions and 5 deletions

View File

@ -30,6 +30,7 @@ import logging
import tempfile
import lxml.html
import subprocess
import simplejson
from pyPdf import PdfFileWriter, PdfFileReader
from werkzeug.test import Client
@ -209,7 +210,7 @@ class Report(http.Controller):
"""Resolve an internal webpage url and return its content with the help of
werkzeug.test.client.
:param url: string representinf the url to resolve
:param url: string representing the url to resolve
:param post: a dict representing the query string
:returns: a tuple str(html), int(statuscode)
"""
@ -427,3 +428,18 @@ class Report(http.Controller):
content = merged.read()
merged.close()
return content
@http.route('/report/downloadpdf/', type='http', auth="user")
def report_pdf_attachment(self, data, token):
"""This function is only used by 'qwebactionmanager.js' in order to trigger the download of
a pdf report.
:param data: The JSON.stringified report internal url
:returns: Response with a filetoken cookie and an attachment header
"""
url = simplejson.loads(data)
pdf = self._get_url_content(url)
response = self._make_pdf_response(pdf)
response.set_cookie('fileToken', token)
response.headers.add('Content-Disposition', 'attachment; filename=report.pdf;')
return response

View File

@ -37,10 +37,22 @@ openerp.report = function(instance) {
});
report_url += "?" + $.param(action.datas.form);
}
instance.web.unblockUI();
window.open(report_url);
return;
if (action.report_type == 'qweb-html') {
// Open the html report in a popup
window.open(report_url);
instance.web.unblockUI();
return;
} else {
// Trigger the download of the pdf report
var c = openerp.webclient.crashmanager;
this.session.get_file({
url: '/report/downloadpdf',
data: {data: JSON.stringify(report_url)},
complete: openerp.web.unblockUI,
error: c.rpc_error.bind(c)
});
return;
}
} else {
return self._super(action, options);
}