42
51
return default_name
44
53
def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
56
if report_xml.report_type != 'webkit':
57
return super(WebKitParser,self).create_single_pdf(cr, uid, ids, data, report_xml, context=context)
59
self.report_xml = report_xml
60
self.parser_instance = self.parser(cr, uid, self.name2, context=context)
61
self.pool = pooler.get_pool(cr.dbname)
63
if not context.get('splitbrowse'):
64
objs = self.getObjects(cr, uid, ids, context)
67
self.parser_instance.localcontext['ids'] = ids
68
self.parser_instance.localcontext['context'] = context
69
self.parser_instance.set_context(objs, data, ids, report_xml.report_type)
72
if report_xml.report_file:
73
path = addons.get_module_resource(report_xml.report_file)
74
if path and os.path.exists(path):
75
template = file(path).read()
46
78
f = file_open(self.tmpl)
47
report_xml.report_webkit_data = f.read()
48
report_xml.report_file = None
49
report_xml.webkit_debug = 1
50
report_xml.header= " "
51
report_xml.webkit_header.html = "${_debug or ''|n}"
52
return super(SpreadsheetReport, self).create_single_pdf(cr, uid, ids, data, report_xml, context)
83
raise osv.except_osv(_('Error!'), _('Webkit Report template not found !'))
85
self.localcontext.update({'lang': context.get('lang')})
86
self.parser_instance.localcontext.update({'setLang':self.setLang})
87
self.parser_instance.localcontext.update({'formatLang':self.formatLang})
90
null, tmpname = tempfile.mkstemp()
91
fileout = codecs.open(tmpname, 'wb', 'utf8')
92
body_mako_tpl = Template(template, input_encoding='utf-8', default_filters=['unicode'])
94
mako_ctx = Context(fileout, _=self.translate_call, **self.parser_instance.localcontext)
95
body_mako_tpl.render_context(mako_ctx)
98
msg = exceptions.text_error_template().render()
99
netsvc.Logger().notifyChannel('Webkit render', netsvc.LOG_ERROR, msg)
100
raise osv.except_osv(_('Webkit render'), msg)
102
# circular reference on parse_instance, force memory free
103
del self.parser_instance
105
if context.get('zipit'):
106
null1, tmpzipname = tempfile.mkstemp()
107
zf = zipfile.ZipFile(tmpzipname, 'w')
108
zf.write(tmpname, 'export_result.xls', zipfile.ZIP_DEFLATED)
110
out = file(tmpzipname, 'rb').read()
113
os.unlink(tmpzipname)
117
out = file(tmpname, 'rb').read()
54
122
def getObjects(self, cr, uid, ids, context):
55
123
table_obj = pooler.get_pool(cr.dbname).get(self.table)
61
129
def create(self, cr, uid, ids, data, context=None):
62
130
a = super(SpreadsheetReport, self).create(cr, uid, ids, data, context)
131
# This permit to test XLS report generation with tools.tests_reports without given some warning
132
# Cf. tools/tests_reports.py:89
133
if context and context.get('from_yml', False) and context.get('from_yml') is True:
134
return (a[0], 'foobar')
67
137
class SpreadsheetCreator(object):
68
138
def __init__(self, title, headers, datas):