diff options
| author | Christophe Simonis <chs@odoo.com> | 2014-10-01 19:18:14 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2014-10-01 19:18:14 +0200 |
| commit | 709c9868de7c4ac4985ed4e0055ae3e3e49742ad (patch) | |
| tree | e90227a947bddf47b3043fcbe8b99529a22aa7dd /addons/website/controllers/main.py | |
| parent | 85f26244a71a0b9a7faa283d6d24fdde6bae899a (diff) | |
| parent | e8831932464814ed5f9e3a0af33f98891a466417 (diff) | |
[MERGE] forward port of branch 8.0 up to e883193
Diffstat (limited to 'addons/website/controllers/main.py')
| -rw-r--r-- | addons/website/controllers/main.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 5e3cc68a53b..db6b405d9fb 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -8,8 +8,6 @@ import xml.etree.ElementTree as ET import logging import re -from sys import maxint - import werkzeug.utils import urllib2 import werkzeug.wrappers @@ -17,7 +15,8 @@ from PIL import Image import openerp from openerp.addons.web import http -from openerp.http import request, Response +from openerp.http import request, STATIC_CACHE +from openerp.tools import image_save_for_web logger = logging.getLogger(__name__) @@ -293,7 +292,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): # the upload argument doesn't allow us to access the files if more than # one file is uploaded, as upload references the first file # therefore we have to recover the files from the request object @@ -321,6 +320,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': c_file.filename, 'datas': image_data.encode('base64'), @@ -466,9 +468,12 @@ class Website(openerp.addons.web.controllers.main.Home): raise werkzeug.exceptions.NotFound() try: + idsha = id.split('_') + id = idsha[0] response = werkzeug.wrappers.Response() return request.registry['website']._image( - request.cr, request.uid, model, id, field, response, max_width, max_height) + request.cr, request.uid, model, id, field, response, max_width, max_height, + cache=STATIC_CACHE if len(idsha) > 1 else None) except Exception: logger.exception("Cannot render image field %r of record %s[%s] at size(%s,%s)", field, model, id, max_width, max_height) |
