diff options
| author | Sébastien Theys <seb@odoo.com> | 2019-06-04 15:11:08 +0200 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2019-06-04 22:14:13 +0200 |
| commit | 76cf2ae82a45b9ffcf63b524944a42b7f5192b0c (patch) | |
| tree | 89540178c9e62def90377eb50ea8f7e1c089aff6 /addons/web_editor/models | |
| parent | 191c556d6b50b35178ea5bb91fb998bcffb86367 (diff) | |
[IMP] web_editor, *: improve media dialog attachment upload
* = web_unsplash, website
Remove iframe upload and replace it with a proper RPC. The route is now only
accepting one file at a time, which makes it easier to maintain, and allows to
process the first file as soon as it is ready, instead of having to wait on
everything.
Also fix a bug where a document could not be uploaded because it would try to
parse it as an image.
Remove filter after search result from the JS and add the corresponding
conditions in the domain to avoid processing and returning unnecessary records.
If multiple attachments exist with the same URL, now display them all to avoid
confusion.
Compute all the necessary values in the python model instead of in the JS.
Allow SVG in the widget (the server already accepted them before).
Disable multiple image upload when not in multiImages mode.
task-1930726
PR: #31208
Diffstat (limited to 'addons/web_editor/models')
| -rw-r--r-- | addons/web_editor/models/ir_attachment.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/addons/web_editor/models/ir_attachment.py b/addons/web_editor/models/ir_attachment.py index 0c5f0e53de8..83f8766b42e 100644 --- a/addons/web_editor/models/ir_attachment.py +++ b/addons/web_editor/models/ir_attachment.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from werkzeug import url_quote + from odoo import api, models, fields @@ -9,6 +11,7 @@ class IrAttachment(models.Model): _inherit = "ir.attachment" local_url = fields.Char("Attachment URL", compute='_compute_local_url') + image_src = fields.Char(compute='_compute_image_src') @api.one def _compute_local_url(self): @@ -16,3 +19,21 @@ class IrAttachment(models.Model): self.local_url = self.url else: self.local_url = '/web/image/%s?unique=%s' % (self.id, self.checksum) + + @api.multi + @api.depends('mimetype', 'url', 'name') + def _compute_image_src(self): + for attachment in self: + if attachment.mimetype not in ['image/gif', 'image/jpe', 'image/jpeg', 'image/jpg', 'image/gif', 'image/png', 'image/svg+xml']: + attachment.image_src = False + else: + attachment.image_src = attachment.url or '/web/image/%s/%s' % ( + attachment.id, + url_quote(attachment.name or ''), + ) + + @api.multi + def _get_media_info(self): + """Return a dict with the values that we need on the media dialog.""" + self.ensure_one() + return self.read(['id', 'name', 'mimetype', 'checksum', 'url', 'type', 'res_id', 'res_model', 'public', 'access_token', 'image_src'])[0] |
