[IMP] web_editor: improve image optimization workflow in media dialog
Previously, when selecting an image, the user could optimize their images by clicking a little cog icon in the media dialog. They would also be prompted to optimize their images when uploading them. In most cases, it makes a lot more sense to always save the original in the database, and optimize the original whenever it's dropped in the page automatically. A second problem is that when using the optimization feature, optimized images would be displayed along the originals by default, resulting in a lot of duplicates while browsing the media dialog. This commit changes both of these things: - By default, when uploading an image, the original uploaded image is used. The user can still optimize their image manually through the media-dialog by using the cog icon. When choosing an image in the media-dialog, if it's not already an optimized image, an optimized copy is automatically created and used instead. - Optimized images are now hidden by default, in the media dialog, and can be shown by clicking a checkbox at the top of the modal when in debug mode task-2091417 closes odoo/odoo#45174
This commit is contained in:
@@ -173,7 +173,16 @@ class Web_Editor(http.Controller):
|
||||
if attachment.type == 'url':
|
||||
raise UserError(_("You cannot change the quality, the width or the name of an URL attachment."))
|
||||
if copy:
|
||||
original = attachment
|
||||
attachment = attachment.copy()
|
||||
attachment.original_id = original
|
||||
# Uniquify url by adding a path segment with the id before the name
|
||||
if attachment.url:
|
||||
url_fragments = attachment.url.split('/')
|
||||
url_fragments.insert(-1, str(attachment.id))
|
||||
attachment.url = '/'.join(url_fragments)
|
||||
elif attachment.original_id:
|
||||
attachment.datas = attachment.original_id.datas
|
||||
data = {}
|
||||
if name:
|
||||
data['name'] = name
|
||||
|
||||
Reference in New Issue
Block a user