diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index bd9e2df6bf7..691824799c3 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -464,13 +464,16 @@ class Website(openerp.addons.web.controllers.main.Home): xmlid can be used to load the image. But the field image must by base64-encoded """ if xmlid and "." in xmlid: - xmlid = xmlid.split(".", 1) try: - model, id = request.registry['ir.model.data'].get_object_reference(request.cr, request.uid, xmlid[0], xmlid[1]) + record = request.env.ref(xmlid) + model, id = record._name, record.id except: raise werkzeug.exceptions.NotFound() - if model == 'ir.attachment': - field = "datas" + if model == 'ir.attachment' and not field: + if record.sudo().type == "url": + field = "url" + else: + field = "datas" if not model or not id or not field: raise werkzeug.exceptions.NotFound() diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 1feb04b2f86..06befda9ebd 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -600,7 +600,22 @@ class website(osv.osv): if response.status_code == 304: return response - data = record[field].decode('base64') + if model == 'ir.attachment' and field == 'url' and field in record: + path = record[field].strip('/') + + # Check that we serve a file from within the module + if os.path.normpath(path).startswith('..'): + return self._image_placeholder(response) + + # Check that the file actually exists + path = path.split('/') + resource = openerp.modules.get_module_resource(*path) + if not resource: + return self._image_placeholder(response) + + data = open(resource, 'rb').read() + else: + data = record[field].decode('base64') image = Image.open(cStringIO.StringIO(data)) response.mimetype = Image.MIME[image.format]