[IMP] website: website/image controller now handles url type attachments
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user