Skip to content
Snippets Groups Projects
Commit c1b1ba69 authored by Christophe Matthieu's avatar Christophe Matthieu
Browse files

[IMP] website: image controller can use xmlid

parent dd4a7213
No related branches found
No related tags found
No related merge requests found
......@@ -403,9 +403,11 @@ class Website(openerp.addons.web.controllers.main.Home):
@http.route([
'/website/image',
'/website/image/<xmlid>',
'/website/image/<xmlid>/<field>',
'/website/image/<model>/<id>/<field>'
], auth="public", website=True)
def website_image(self, model, id, field, max_width=None, max_height=None):
def website_image(self, model=None, id=None, field=None, xmlid=None, max_width=None, max_height=None):
""" Fetches the requested field and ensures it does not go above
(max_width, max_height), resizing it if necessary.
......@@ -419,7 +421,21 @@ class Website(openerp.addons.web.controllers.main.Home):
The requested field is assumed to be base64-encoded image data in
all cases.
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])
except:
raise werkzeug.exceptions.NotFound()
if model == 'ir.attachment':
field = "datas"
if not model or not id or not field:
raise werkzeug.exceptions.NotFound()
response = werkzeug.wrappers.Response()
return request.registry['website']._image(
request.cr, request.uid, model, id, field, response, max_width, max_height)
......
......@@ -92,12 +92,13 @@
<!-- Pre loaded images -->
<record model="ir.attachment">
<!-- base64-encoded on ir.attachment, to allow to load image with the xmlid -->
<record id="website.business_conference" model="ir.attachment">
<field name="name">business_conference</field>
<field name="datas_fname">business_conference.jpg</field>
<field name="res_model">ir.ui.view</field>
<field name="type">url</field>
<field name="url">/website/static/src/img/library/business_conference.jpg</field>
<field name="type">binary</field>
<field name="datas" type="base64" file="website/static/src/img/library/business_conference.jpg"/>
</record>
<record model="ir.attachment">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment