0001-misc-remove-possibility-to-download-PDF-of-statistic.patch
data/print-html-as-pdf.js | ||
---|---|---|
1 |
var page = require('webpage').create(); |
|
2 |
var system = require('system'); |
|
3 | ||
4 |
page.paperSize = { |
|
5 |
width: '29cm', |
|
6 |
height: '21cm', |
|
7 |
margin: { |
|
8 |
top: '1cm', left: '1cm', right: '1cm', bottom: '1cm' |
|
9 |
} |
|
10 |
}; |
|
11 | ||
12 |
page.open(system.args[1], function() { |
|
13 |
x = page.evaluate(function() { |
|
14 |
$('#top, #header, #sidebar, #sidebar-toggle, #breadcrumb, a.back').hide(); |
|
15 |
$('#sidepage, #main').removeClass('sidepage-expanded'); |
|
16 |
$('html').css('background', 'white').css('font-size', '8pt'); |
|
17 |
$('div#main').css('width', '95%'); |
|
18 |
$('div#main-content').css('width', '95%').css('border', 'none'); |
|
19 |
$('#statistics .criterias').css('display', 'block'); |
|
20 |
$('div#main-content > h2').css({ |
|
21 |
'border-bottom': '1px solid #666', |
|
22 |
'font-weight': 'bold'}); |
|
23 |
var date = $('<p>' + new Date().toLocaleString() + '</p>').appendTo('div#main-content'); |
|
24 |
date.css({ |
|
25 |
'position': 'absolute', |
|
26 |
'top': '2ex', |
|
27 |
'right': '1em'}); |
|
28 |
}); |
|
29 |
page.render(system.args[1] + '.pdf'); |
|
30 |
phantom.exit(); |
|
31 |
}); |
setup.py | ||
---|---|---|
122 | 122 |
data_tree('share/wcs/themes/', 'data/themes/') + \ |
123 | 123 |
data_tree('share/wcs/vendor/', 'data/vendor/') + \ |
124 | 124 |
data_tree('share/wcs/qommon/', 'wcs/qommon/static/') + |
125 |
[('share/wcs/', ['data/webbots', 'data/print-html-as-pdf.js'])]
|
|
125 |
[('share/wcs/', ['data/webbots'])] |
|
126 | 126 |
) |
127 | 127 | |
128 | 128 |
if local_cfg: |
wcs/backoffice/management.py | ||
---|---|---|
1790 | 1790 |
r += htmltext('<form id="listing-settings" action="stats">') |
1791 | 1791 |
r += self.get_filter_sidebar(selected_filter=selected_filter, mode='stats') |
1792 | 1792 |
r += htmltext('<button class="refresh">%s</button>') % _('Refresh') |
1793 |
if misc.can_decorate_as_pdf(): |
|
1794 |
r += htmltext('<button class="pdf">%s</button>') % _('Download PDF') |
|
1795 | 1793 |
r += htmltext('</form>') |
1796 | 1794 |
return r.getvalue() |
1797 | 1795 | |
... | ... | |
1895 | 1893 |
page += htmltext('<h2>%s - %s</h2>') % (self.formdef.name, _('Statistics')) |
1896 | 1894 |
page += htmltext(r) |
1897 | 1895 |
page += htmltext('<a class="back" href=".">%s</a>') % _('Back') |
1898 | ||
1899 |
if 'pdf' in get_request().form: |
|
1900 |
pdf_content = misc.decorate_as_pdf(page.getvalue()) |
|
1901 |
response = get_response() |
|
1902 |
response.set_content_type('application/pdf') |
|
1903 |
return pdf_content |
|
1904 | ||
1905 | 1896 |
return page.getvalue() |
1906 | 1897 | |
1907 | 1898 |
def stats_fields(self, values, excluded_fields=None): |
wcs/qommon/misc.py | ||
---|---|---|
515 | 515 |
charset = (get_publisher() and get_publisher().site_charset) or 'utf-8' |
516 | 516 |
return json_encode_helper(json.loads(value), charset) |
517 | 517 | |
518 |
def can_decorate_as_pdf(): |
|
519 |
return os.path.exists('/usr/bin/phantomjs') |
|
520 | ||
521 |
def decorate_as_pdf(content): |
|
522 |
from qommon import template |
|
523 |
html_page = get_publisher().render_response(content) |
|
524 |
html_page = html_page.replace('<head>', |
|
525 |
'<head><base href="%s"><meta charset="%s">' % |
|
526 |
(get_publisher().get_frontoffice_url(), |
|
527 |
get_publisher().site_charset)) |
|
528 |
tmpfile = tempfile.NamedTemporaryFile(suffix='.html', delete=False) |
|
529 |
tmpfile.write(html_page) |
|
530 |
tmpfile.close() |
|
531 |
phantomjs_script = os.path.join(get_publisher().DATA_DIR, 'print-html-as-pdf.js') |
|
532 |
subprocess.check_call(['phantomjs', '--ssl-protocol=any', phantomjs_script, tmpfile.name]) |
|
533 |
pdf_fd = open(tmpfile.name + '.pdf') |
|
534 |
pdf_content = pdf_fd.read() |
|
535 |
pdf_fd.close() |
|
536 |
os.unlink(tmpfile.name + '.pdf') |
|
537 |
os.unlink(tmpfile.name) |
|
538 |
return pdf_content |
|
539 | ||
540 | 518 |
def json_response(data): |
541 | 519 |
get_response().set_content_type('application/json') |
542 | 520 |
if get_request().get_environ('HTTP_ORIGIN'): |
543 |
- |