diff options
| author | Lucas Perais (lpe) <lpe@odoo.com> | 2019-02-21 13:45:27 +0000 |
|---|---|---|
| committer | Lucas Perais (lpe) <lpe@odoo.com> | 2019-02-22 08:14:10 +0000 |
| commit | 6fc08a88ae5151b3378d01a2d963e0c4d3734a32 (patch) | |
| tree | a59722376546a617b15e5408c809cfa3c720d45b /addons/web_unsplash/models | |
| parent | 27f8bb8913d71850395c15d7958b926020792afb (diff) | |
[FIX] web_unsplash: save image for res_model
Go on the website, create a new product from there
Click on the image to change it, select an unsplash image
Save your product.
Beforer this commit, the image wasn't saved because the qweb field image
did not know what to do with /unsplash/ urls
After this commit, the image is saved on the product (or any object...)
OPW 1936191
closes odoo/odoo#31328
Diffstat (limited to 'addons/web_unsplash/models')
| -rw-r--r-- | addons/web_unsplash/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/web_unsplash/models/ir_qweb.py | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/addons/web_unsplash/models/__init__.py b/addons/web_unsplash/models/__init__.py index 63a963dae32..ffce82298b0 100644 --- a/addons/web_unsplash/models/__init__.py +++ b/addons/web_unsplash/models/__init__.py @@ -3,3 +3,4 @@ from . import res_config_settings from . import res_users +from . import ir_qweb diff --git a/addons/web_unsplash/models/ir_qweb.py b/addons/web_unsplash/models/ir_qweb.py new file mode 100644 index 00000000000..8d581c47299 --- /dev/null +++ b/addons/web_unsplash/models/ir_qweb.py @@ -0,0 +1,26 @@ +from werkzeug import urls + +from odoo import models, api + + +class Image(models.AbstractModel): + _inherit = 'ir.qweb.field.image' + + @api.model + def from_html(self, model, field, element): + url = element.find('img').get('src') + url_object = urls.url_parse(url) + + if url_object.path.startswith('/unsplash/'): + res_id = element.get('data-oe-id') + if res_id: + res_id = int(res_id) + res_model = model._name + attachment = self.env['ir.attachment'].search([ + ('res_model', '=', res_model), + ('res_id', '=', res_id), + ('url', '=', url_object.path), + ], limit=1) + return attachment.datas + + return super(Image, self).from_html(model, field, element) |
