Skip to content

Commit a9632ea

Browse files
committed
move from bazaar
1 parent abefb79 commit a9632ea

File tree

8 files changed

+295
-0
lines changed

8 files changed

+295
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# Copyright (C) 2014 CodUP (<http://codup.com>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
22+
import header
23+
import webkit_report
24+
25+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# Copyright (C) 2014 CodUP (<http://codup.com>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
22+
{
23+
'name': 'Webkit Report Zoom',
24+
'version': '1.0',
25+
'description': """
26+
Extend WebKit Report Engine with Zoom option.
27+
=============================================
28+
Feature:
29+
--------
30+
* Scale definition
31+
""",
32+
'author': 'CodUP',
33+
'website': 'http://codup.com',
34+
'category': 'Reporting',
35+
'sequence': 0,
36+
'depends': ['report_webkit'],
37+
'data': ['header_view.xml'],
38+
'installable': True,
39+
}
40+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# Copyright (C) 2014 CodUP (<http://codup.com>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
22+
from openerp.osv import fields, osv
23+
24+
class HeaderHTML(osv.osv):
25+
_name = 'ir.header_webkit'
26+
_inherit = 'ir.header_webkit'
27+
_columns = {
28+
'scale' : fields.float('Scale'),
29+
}
30+
_defaults = {
31+
'scale': 1,
32+
}
33+
34+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<openerp>
3+
<data>
4+
5+
<record id="view_header_webkit_form" model="ir.ui.view">
6+
<field name="name">res.company.header.html.form</field>
7+
<field name="model">ir.header_webkit</field>
8+
<field name="inherit_id" ref="report_webkit.header_webkit"/>
9+
<field name="arch" type="xml">
10+
<field name="format" position="after">
11+
<field name="scale"/>
12+
</field>
13+
</field>
14+
</record>
15+
16+
</data>
17+
</openerp>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Translation of OpenERP Server.
2+
# This file contains the translation of the following modules:
3+
# * report_webkit_zoom
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: OpenERP Server 7.0-20140125-002455\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2014-04-06 12:07+0000\n"
10+
"PO-Revision-Date: 2014-04-06 12:07+0000\n"
11+
"Last-Translator: <>\n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: report_webkit_zoom
19+
#: field:ir.header_webkit,scale:0
20+
msgid "Scale"
21+
msgstr ""
22+
23+
#. module: report_webkit_zoom
24+
#: model:ir.model,name:report_webkit_zoom.model_ir_header_webkit
25+
msgid "ir.header_webkit"
26+
msgstr ""
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Translation of OpenERP Server.
2+
# This file contains the translation of the following modules:
3+
# * report_webkit_zoom
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: OpenERP Server 7.0-20140125-002455\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"POT-Creation-Date: 2014-04-06 12:07+0000\n"
10+
"PO-Revision-Date: 2014-04-06 12:07+0000\n"
11+
"Last-Translator: <>\n"
12+
"Language-Team: \n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: \n"
17+
18+
#. module: report_webkit_zoom
19+
#: field:ir.header_webkit,scale:0
20+
msgid "Scale"
21+
msgstr "Масштаб"
22+
23+
#. module: report_webkit_zoom
24+
#: model:ir.model,name:report_webkit_zoom.model_ir_header_webkit
25+
msgid "ir.header_webkit"
26+
msgstr ""
27+
12.3 KB
Loading
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# -*- coding: utf-8 -*-
2+
##############################################################################
3+
#
4+
# OpenERP, Open Source Management Solution
5+
# Copyright (C) 2014 CodUP (<http://codup.com>).
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as
9+
# published by the Free Software Foundation, either version 3 of the
10+
# License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
##############################################################################
21+
22+
import subprocess
23+
import os
24+
import tempfile
25+
import time
26+
from openerp.tools.translate import _
27+
from openerp.osv.osv import except_osv
28+
from openerp.addons.report_webkit.webkit_report import WebKitParser
29+
30+
import logging
31+
_logger = logging.getLogger(__name__)
32+
33+
def generate_pdf(self, comm_path, report_xml, header, footer, html_list, webkit_header=False):
34+
"""Call webkit in order to generate pdf"""
35+
if not webkit_header:
36+
webkit_header = report_xml.webkit_header
37+
tmp_dir = tempfile.gettempdir()
38+
out_filename = tempfile.mktemp(suffix=".pdf", prefix="webkit.tmp.")
39+
file_to_del = [out_filename]
40+
if comm_path:
41+
command = [comm_path]
42+
else:
43+
command = ['wkhtmltopdf']
44+
45+
command.append('--quiet')
46+
# default to UTF-8 encoding. Use <meta charset="latin-1"> to override.
47+
command.extend(['--encoding', 'utf-8'])
48+
if header :
49+
head_file = file( os.path.join(
50+
tmp_dir,
51+
str(time.time()) + '.head.html'
52+
),
53+
'w'
54+
)
55+
head_file.write(header)
56+
head_file.close()
57+
file_to_del.append(head_file.name)
58+
command.extend(['--header-html', head_file.name])
59+
if footer :
60+
foot_file = file( os.path.join(
61+
tmp_dir,
62+
str(time.time()) + '.foot.html'
63+
),
64+
'w'
65+
)
66+
foot_file.write(footer)
67+
foot_file.close()
68+
file_to_del.append(foot_file.name)
69+
command.extend(['--footer-html', foot_file.name])
70+
71+
if webkit_header.scale :
72+
command.extend(['--zoom', str(webkit_header.scale).replace(',', '.')])
73+
if webkit_header.margin_top :
74+
command.extend(['--margin-top', str(webkit_header.margin_top).replace(',', '.')])
75+
if webkit_header.margin_bottom :
76+
command.extend(['--margin-bottom', str(webkit_header.margin_bottom).replace(',', '.')])
77+
if webkit_header.margin_left :
78+
command.extend(['--margin-left', str(webkit_header.margin_left).replace(',', '.')])
79+
if webkit_header.margin_right :
80+
command.extend(['--margin-right', str(webkit_header.margin_right).replace(',', '.')])
81+
if webkit_header.orientation :
82+
command.extend(['--orientation', str(webkit_header.orientation).replace(',', '.')])
83+
if webkit_header.format :
84+
command.extend(['--page-size', str(webkit_header.format).replace(',', '.')])
85+
count = 0
86+
for html in html_list :
87+
html_file = file(os.path.join(tmp_dir, str(time.time()) + str(count) +'.body.html'), 'w')
88+
count += 1
89+
html_file.write(html)
90+
html_file.close()
91+
file_to_del.append(html_file.name)
92+
command.append(html_file.name)
93+
command.append(out_filename)
94+
stderr_fd, stderr_path = tempfile.mkstemp(text=True)
95+
file_to_del.append(stderr_path)
96+
try:
97+
status = subprocess.call(command, stderr=stderr_fd)
98+
os.close(stderr_fd) # ensure flush before reading
99+
stderr_fd = None # avoid closing again in finally block
100+
fobj = open(stderr_path, 'r')
101+
error_message = fobj.read()
102+
fobj.close()
103+
if not error_message:
104+
error_message = _('No diagnosis message was provided')
105+
else:
106+
error_message = _('The following diagnosis message was provided:\n') + error_message
107+
if status :
108+
raise except_osv(_('Webkit error' ),
109+
_("The command 'wkhtmltopdf' failed with error code = %s. Message: %s") % (status, error_message))
110+
pdf_file = open(out_filename, 'rb')
111+
pdf = pdf_file.read()
112+
pdf_file.close()
113+
finally:
114+
if stderr_fd is not None:
115+
os.close(stderr_fd)
116+
for f_to_del in file_to_del:
117+
try:
118+
os.unlink(f_to_del)
119+
except (OSError, IOError), exc:
120+
_logger.error('cannot remove file %s: %s', f_to_del, exc)
121+
return pdf
122+
123+
WebKitParser.generate_pdf = generate_pdf
124+
125+
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 commit comments

Comments
 (0)