diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 6891d767842..4fc90e4a8bc 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -16,6 +16,7 @@ from PIL import Image import openerp from openerp.addons.web import http from openerp.http import request, STATIC_CACHE +from openerp.tools import image_save_for_web logger = logging.getLogger(__name__) @@ -314,7 +315,7 @@ class Website(openerp.addons.web.controllers.main.Home): return True @http.route('/website/attach', type='http', auth='user', methods=['POST'], website=True) - def attach(self, func, upload=None, url=None): + def attach(self, func, upload=None, url=None, disable_optimization=None): Attachments = request.registry['ir.attachment'] website_url = message = None @@ -337,6 +338,9 @@ class Website(openerp.addons.web.controllers.main.Home): u"Image size excessive, uploaded images must be smaller " u"than 42 million pixel") + if not disable_optimization and image.format in ('PNG', 'JPEG'): + image_data = image_save_for_web(image) + attachment_id = Attachments.create(request.cr, request.uid, { 'name': upload.filename, 'datas': image_data.encode('base64'), diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index ab6abed522b..50c939a0803 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1387,6 +1387,10 @@ 'click button.filepicker': function () { this.$('input[type=file]').click(); }, + 'click .js_disable_optimization': function () { + this.$('input[name="disable_optimization"]').val('1'); + this.$('button.filepicker').click(); + }, 'change input[type=file]': 'file_selection', 'submit form': 'form_submit', 'change input.url': "change_input", diff --git a/addons/website/static/src/xml/website.editor.xml b/addons/website/static/src/xml/website.editor.xml index 24d54ec017e..13b80b1e706 100644 --- a/addons/website/static/src/xml/website.editor.xml +++ b/addons/website/static/src/xml/website.editor.xml @@ -204,7 +204,17 @@
- + +
+ + + +