summaryrefslogtreecommitdiff
path: root/odoo/tools
diff options
context:
space:
mode:
Diffstat (limited to 'odoo/tools')
-rw-r--r--odoo/tools/image.py5
-rw-r--r--odoo/tools/misc.py22
2 files changed, 26 insertions, 1 deletions
diff --git a/odoo/tools/image.py b/odoo/tools/image.py
index bacf6a9c999..0ff50967f0a 100644
--- a/odoo/tools/image.py
+++ b/odoo/tools/image.py
@@ -75,7 +75,7 @@ def image_resize_image(base64_source, size=(1024, 1024), encoding='base64', file
if image.size != size:
image = image_resize_and_sharpen(image, size)
- if image.mode not in ["1", "L", "P", "RGB", "RGBA"]:
+ if image.mode not in ["1", "L", "P", "RGB", "RGBA"] or (filetype == 'JPEG' and image.mode == 'RGBA'):
image = image.convert("RGB")
background_stream = StringIO.StringIO()
@@ -92,6 +92,7 @@ def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2.
:param preserve_aspect_ratio: boolean (default: False)
:param factor: Sharpen factor (default: 2.0)
"""
+ origin_mode = image.mode
if image.mode != 'RGBA':
image = image.convert('RGBA')
image.thumbnail(size, Image.ANTIALIAS)
@@ -102,6 +103,8 @@ def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2.
# create a transparent image for background and paste the image on it
image = Image.new('RGBA', size, (255, 255, 255, 0))
image.paste(resized_image, ((size[0] - resized_image.size[0]) / 2, (size[1] - resized_image.size[1]) / 2))
+ if image.mode != origin_mode:
+ image = image.convert(origin_mode)
return image
def image_save_for_web(image, fp=None, format=None):
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py
index 45ff5e28bbd..448ffdfed43 100644
--- a/odoo/tools/misc.py
+++ b/odoo/tools/misc.py
@@ -374,6 +374,28 @@ try:
except ImportError:
xlwt = None
+try:
+ import xlsxwriter
+
+ # add some sanitizations to respect the excel sheet name restrictions
+ # as the sheet name is often translatable, can not control the input
+ class PatchedXlsxWorkbook(xlsxwriter.Workbook):
+
+ # TODO when xlsxwriter bump to 0.9.8, add worksheet_class=None parameter instead of kw
+ def add_worksheet(self, name=None, **kw):
+ # invalid Excel character: []:*?/\
+ name = re.sub(r'[\[\]:*?/\\]', '', name)
+
+ # maximum size is 31 characters
+ name = name[:31]
+ return super(PatchedXlsxWorkbook, self).add_worksheet(name, **kw)
+
+ xlsxwriter.Workbook = PatchedXlsxWorkbook
+
+except ImportError:
+ xlsxwriter = None
+
+
def to_xml(s):
return s.replace('&','&amp;').replace('<','&lt;').replace('>','&gt;')