misc: remove possibility to download PDF of statistics (#35281)
This commit is contained in:
parent
9ad71a9805
commit
0a55d2dfc0
|
@ -1,31 +0,0 @@
|
|||
var page = require('webpage').create();
|
||||
var system = require('system');
|
||||
|
||||
page.paperSize = {
|
||||
width: '29cm',
|
||||
height: '21cm',
|
||||
margin: {
|
||||
top: '1cm', left: '1cm', right: '1cm', bottom: '1cm'
|
||||
}
|
||||
};
|
||||
|
||||
page.open(system.args[1], function() {
|
||||
x = page.evaluate(function() {
|
||||
$('#top, #header, #sidebar, #sidebar-toggle, #breadcrumb, a.back').hide();
|
||||
$('#sidepage, #main').removeClass('sidepage-expanded');
|
||||
$('html').css('background', 'white').css('font-size', '8pt');
|
||||
$('div#main').css('width', '95%');
|
||||
$('div#main-content').css('width', '95%').css('border', 'none');
|
||||
$('#statistics .criterias').css('display', 'block');
|
||||
$('div#main-content > h2').css({
|
||||
'border-bottom': '1px solid #666',
|
||||
'font-weight': 'bold'});
|
||||
var date = $('<p>' + new Date().toLocaleString() + '</p>').appendTo('div#main-content');
|
||||
date.css({
|
||||
'position': 'absolute',
|
||||
'top': '2ex',
|
||||
'right': '1em'});
|
||||
});
|
||||
page.render(system.args[1] + '.pdf');
|
||||
phantom.exit();
|
||||
});
|
2
setup.py
2
setup.py
|
@ -122,7 +122,7 @@ setup(
|
|||
data_tree('share/wcs/themes/', 'data/themes/') + \
|
||||
data_tree('share/wcs/vendor/', 'data/vendor/') + \
|
||||
data_tree('share/wcs/qommon/', 'wcs/qommon/static/') +
|
||||
[('share/wcs/', ['data/webbots', 'data/print-html-as-pdf.js'])]
|
||||
[('share/wcs/', ['data/webbots'])]
|
||||
)
|
||||
|
||||
if local_cfg:
|
||||
|
|
|
@ -1774,8 +1774,6 @@ class FormPage(Directory):
|
|||
r += htmltext('<form id="listing-settings" action="stats">')
|
||||
r += self.get_filter_sidebar(selected_filter=selected_filter, mode='stats')
|
||||
r += htmltext('<button class="refresh">%s</button>') % _('Refresh')
|
||||
if misc.can_decorate_as_pdf():
|
||||
r += htmltext('<button class="pdf">%s</button>') % _('Download PDF')
|
||||
r += htmltext('</form>')
|
||||
return r.getvalue()
|
||||
|
||||
|
@ -1879,13 +1877,6 @@ class FormPage(Directory):
|
|||
page += htmltext('<h2>%s - %s</h2>') % (self.formdef.name, _('Statistics'))
|
||||
page += htmltext(r)
|
||||
page += htmltext('<a class="back" href=".">%s</a>') % _('Back')
|
||||
|
||||
if 'pdf' in get_request().form:
|
||||
pdf_content = misc.decorate_as_pdf(page.getvalue())
|
||||
response = get_response()
|
||||
response.set_content_type('application/pdf')
|
||||
return pdf_content
|
||||
|
||||
return page.getvalue()
|
||||
|
||||
def stats_fields(self, values, excluded_fields=None):
|
||||
|
|
|
@ -515,28 +515,6 @@ def json_loads(value, charset=None):
|
|||
charset = (get_publisher() and get_publisher().site_charset) or 'utf-8'
|
||||
return json_encode_helper(json.loads(value), charset)
|
||||
|
||||
def can_decorate_as_pdf():
|
||||
return os.path.exists('/usr/bin/phantomjs')
|
||||
|
||||
def decorate_as_pdf(content):
|
||||
from qommon import template
|
||||
html_page = get_publisher().render_response(content)
|
||||
html_page = html_page.replace('<head>',
|
||||
'<head><base href="%s"><meta charset="%s">' %
|
||||
(get_publisher().get_frontoffice_url(),
|
||||
get_publisher().site_charset))
|
||||
tmpfile = tempfile.NamedTemporaryFile(suffix='.html', delete=False)
|
||||
tmpfile.write(html_page)
|
||||
tmpfile.close()
|
||||
phantomjs_script = os.path.join(get_publisher().DATA_DIR, 'print-html-as-pdf.js')
|
||||
subprocess.check_call(['phantomjs', '--ssl-protocol=any', phantomjs_script, tmpfile.name])
|
||||
pdf_fd = open(tmpfile.name + '.pdf')
|
||||
pdf_content = pdf_fd.read()
|
||||
pdf_fd.close()
|
||||
os.unlink(tmpfile.name + '.pdf')
|
||||
os.unlink(tmpfile.name)
|
||||
return pdf_content
|
||||
|
||||
def json_response(data):
|
||||
get_response().set_content_type('application/json')
|
||||
if get_request().get_environ('HTTP_ORIGIN'):
|
||||
|
|
Loading…
Reference in New Issue