StringIO doesn't like buffer from DB
issue2296 review171006 (transplanted from 9d82f554e2143f3adc5b95a27aec9b3f695e78e8)
This commit is contained in:
1 parent
16ceec5f00
commit
4c1199bc40
1 file changed
+9
-5
@@ -168,7 +168,11 @@ class Report(URLMixin):
|
||||
pool.get('ir.translation'))
|
||||
localcontext['setLang'] = lambda language: translate.set_language(language)
|
||||
|
||||
if not report.report_content:
|
||||
# Convert to str as buffer from DB is not supported by StringIO
|
||||
report_content = str(report.report_content)
|
||||
style_content = str(report.style_content)
|
||||
|
||||
if not report_content:
|
||||
raise Exception('Error', 'Missing report file!')
|
||||
|
||||
fd, path = tempfile.mkstemp(
|
||||
@@ -177,14 +181,14 @@ class Report(URLMixin):
|
||||
outzip = zipfile.ZipFile(path, mode='w')
|
||||
|
||||
content_io = StringIO.StringIO()
|
||||
content_io.write(report.report_content)
|
||||
content_io.write(report_content)
|
||||
content_z = zipfile.ZipFile(content_io, mode='r')
|
||||
|
||||
style_info = None
|
||||
style_xml = None
|
||||
manifest = None
|
||||
for f in content_z.infolist():
|
||||
if f.filename == 'styles.xml' and report.style_content:
|
||||
if f.filename == 'styles.xml' and style_content:
|
||||
style_info = f
|
||||
style_xml = content_z.read(f.filename)
|
||||
continue
|
||||
@@ -193,13 +197,13 @@ class Report(URLMixin):
|
||||
continue
|
||||
outzip.writestr(f, content_z.read(f.filename))
|
||||
|
||||
if report.style_content:
|
||||
if style_content:
|
||||
pictures = []
|
||||
|
||||
#cStringIO difference:
|
||||
#calling StringIO() with a string parameter creates a read-only object
|
||||
new_style_io = StringIO.StringIO()
|
||||
new_style_io.write(report.style_content)
|
||||
new_style_io.write(style_content)
|
||||
new_style_z = zipfile.ZipFile(new_style_io, mode='r')
|
||||
new_style_xml = new_style_z.read('styles.xml')
|
||||
for file in new_style_z.namelist():
|
||||
|
||||
Reference in new issue
Block a user