Commit f13f3239 authored by Nicolas Delaby's avatar Nicolas Delaby

When adding image inside ODF archive update also manifest file, otherwise

document is considered broken by recent OOo versions.

addImage accept new argument content_type which must be required.
But backward compatibility is kept so FutureWarning is raised instead
to inform user to update the argument list.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40555 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d286b0d4
...@@ -52,6 +52,7 @@ from OFS.Image import Pdata ...@@ -52,6 +52,7 @@ from OFS.Image import Pdata
from lxml import etree from lxml import etree
from lxml.etree import Element, XMLSyntaxError from lxml.etree import Element, XMLSyntaxError
from copy import deepcopy from copy import deepcopy
from warnings import warn
class CorruptedOOoFile(Exception): pass class CorruptedOOoFile(Exception): pass
...@@ -188,13 +189,18 @@ class OOoBuilder(Implicit): ...@@ -188,13 +189,18 @@ class OOoBuilder(Implicit):
self.replace(MANIFEST_FILENAME, meta_infos) self.replace(MANIFEST_FILENAME, meta_infos)
self._manifest_additions_list = [] self._manifest_additions_list = []
def addImage(self, image, format='png'): def addImage(self, image, format='png', content_type=None):
""" """
Add an image to the current document and return its id Add an image to the current document and return its id
""" """
count = self._image_count count = self._image_count
self._image_count += 1 self._image_count += 1
name = "Pictures/%s.%s" % (count, format) name = "Pictures/%s.%s" % (count, format)
if not content_type:
import mimetypes
warn('content_type argument must be passed explicitely', FutureWarning)
content_type = mimetypes.guess_type(name)[0]
self.addManifest(name, content_type)
self.replace(name, image) self.replace(name, image)
is_legacy = ('oasis.opendocument' not in self.getMimeType()) is_legacy = ('oasis.opendocument' not in self.getMimeType())
return "%s%s" % (is_legacy and '#' or '', name,) return "%s%s" % (is_legacy and '#' or '', name,)
......
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