Commit 9134e865 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Fixed some issues related to conversion handling of presentations to images...

Fixed some issues related to conversion handling of presentations to images with resizing. (untested) Use of UnrestrictedMethod for HTML conversion.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@18513 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b54008f0
......@@ -175,7 +175,9 @@ class ConversionCacheMixin:
if mime is not None:
self._cached_mime[tformat] = mime
if data is not None:
self._cached_data[tformat] = data
self._cached_data[tformat] = aq_base(data) # Use of aq_base
# is useful to remove the wrapper from a temp object
# which may have been used to generate data
self.updateConversion(**format)
self._p_changed = 1
......
......@@ -42,6 +42,8 @@ from DocumentTemplate.DT_Util import html_quote
from Products.CMFCore.utils import _setCacheHeaders
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5.Document.File import File
from Products.ERP5.Document.Document import ConversionError
from OFS.Image import Image as OFSImage
from OFS.Image import getImageInfo
from OFS.content_types import guess_content_type
......@@ -379,13 +381,12 @@ class Image(File, OFSImage):
else:
from popen2 import popen2
if resolution is None:
imgout, imgin = popen2('convert -quality %s -geometry %sx%s -%s %s-'
% (quality, width, height, frame, format))
cmd = 'convert -quality %s -geometry %sx%s -%s %s-' % (
quality, width, height, frame, format)
else:
# LOG('Resolution',0,str(resolution))
cmd = 'convert -density %sx%s -quality %s -geometry %sx%s -%s %s-' % (
resolution, resolution, quality, width, height, frame, format)
imgout, imgin = popen2(cmd)
imgout, imgin = popen2(cmd)
def writeData(stream, data):
if isinstance(data, str):
......@@ -401,6 +402,8 @@ class Image(File, OFSImage):
imgin.close()
newimg.write(imgout.read())
imgout.close()
if not newimg.tell():
raise ConversionError('Image conversion failed (empty file).')
newimg.seek(0)
return newimg
......
......@@ -37,6 +37,7 @@ from OFS.Image import Pdata
from Products.CMFCore.utils import getToolByName, _setCacheHeaders
from Products.ERP5Type import Permissions, PropertySheet, Constraint, Interface
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5.Document.File import File
from Products.ERP5.Document.Document import ConversionCacheMixin
from Products.ERP5.Document.Document import ConversionError
......@@ -310,7 +311,7 @@ class OOoDocument(File, ConversionCacheMixin):
z.close()
return 'text/plain', s
server_proxy = self._mkProxy()
generate_result = server_proxy.run_generate(self.getId(),
enc(_unpackData(self.getBaseData())),
None,
......@@ -321,7 +322,7 @@ class OOoDocument(File, ConversionCacheMixin):
# This is for backward compatibility with older oood version returning
# only response_dict
response_dict = generate_result
# XXX: handle possible OOOd server failure
return response_dict['mime'], Pdata(dec(response_dict['data']))
......@@ -401,7 +402,7 @@ class OOoDocument(File, ConversionCacheMixin):
portal_type='Image',
temp_object=1)
temp_image._setData(data)
mime, data = temp_image.convert(format, display=display)
mime, data = temp_image.convert(original_format, display=display)
self.setConversion(data, mime, format=format, display=display)
if display is None or original_format not in STANDARD_IMAGE_FORMAT_LIST:
return self.getConversion(format=format)
......@@ -426,7 +427,7 @@ class OOoDocument(File, ConversionCacheMixin):
"""
if zip_file is None:
format_list = [x for x in self.getTargetFormatList()
if x.startswith('html')]
if x.startswith('html') or x.endswith('html')]
format = format_list[0]
mime, data = self._convert(format)
archive_file = cStringIO.StringIO()
......@@ -437,13 +438,16 @@ class OOoDocument(File, ConversionCacheMixin):
must_close = 0
for f in zip_file.infolist():
file_name = f.filename
if not file_name.endswith('html'):
if not file_name.endswith('html'): # XXX - we must add here more values in order to
# support multi-page HTML conversions
# such as for presentations.
document = self.get(file_name, None)
if document is not None:
self.manage_delObjects([file_name])
self.portal_contributions.newContent(id=file_name, container=self,
file_name=file_name,
data=zip_file.read(file_name))
newContent = UnrestrictedMethod(self.portal_contributions.newContent)
newContent(id=file_name, container=self,
file_name=file_name,
data=zip_file.read(file_name))
if must_close:
zip_file.close()
archive_file.close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment