diff options
| author | qsm-odoo <qsm@odoo.com> | 2020-08-13 15:35:40 +0000 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2020-08-13 15:44:48 +0000 |
| commit | c5fee9d009329691db58a16c1f90eac734749f4d (patch) | |
| tree | 35217344dca023e8156a172a7b81561a557106bc /addons/web_editor/models/ir_ui_view.py | |
| parent | 4afdebbb7e919878966a3b894ce99e913cf046e4 (diff) | |
[FIX] web_editor, *: restore custom snippets thumbnails
*: website
Since [1], the thumbnails of the saved snippets were not right anymore,
all fallbacking to the default image. This is because snippets thumbs
now use svg files instead of png and the snippet saving feature did not
allow it. This commit fixes that and makes the feature more robust.
- Allow to use any original thumbnail, and not only for website app.
- Remove useless defaut image, a fallback for when the feature is broken
is useless.
- Identify snippets by key instead of by main class (possible since
the new `data-snippet` attribute on snippets).
[1]: https://github.com/odoo/odoo/commit/b7fe2bdae2f45372c0d538767a226a413b806f3f
closes odoo/odoo#55896
Signed-off-by: Quentin Smetz (qsm) <qsm@odoo.com>
Diffstat (limited to 'addons/web_editor/models/ir_ui_view.py')
| -rw-r--r-- | addons/web_editor/models/ir_ui_view.py | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/addons/web_editor/models/ir_ui_view.py b/addons/web_editor/models/ir_ui_view.py index 0897662f2af..a33d29ac756 100644 --- a/addons/web_editor/models/ir_ui_view.py +++ b/addons/web_editor/models/ir_ui_view.py @@ -290,10 +290,6 @@ class IrUiView(models.Model): # -------------------------------------------------------------------------- @api.model - def _get_default_snippet_thumbnail(self, snippet_class=None): - return '/web_editor/static/src/img/snippets_thumbs/s_custom_snippet.png' - - @api.model def _get_snippet_addition_view_key(self, template_key, key): return '%s.%s' % (template_key, key) @@ -302,7 +298,7 @@ class IrUiView(models.Model): return {} @api.model - def save_snippet(self, name, arch, template_key, snippet_class=None, thumbnail_url=None): + def save_snippet(self, name, arch, template_key, snippet_key, thumbnail_url): """ Saves a new snippet arch so that it appears with the given name when using the given snippets template. @@ -311,24 +307,20 @@ class IrUiView(models.Model): :param arch: the html structure of the snippet to save :param template_key: the key of the view regrouping all snippets in which the snippet to save is meant to appear - :param snippet_class: a className which is supposed to uniquely-identify + :param snippet_key: the key (without module part) to identify the snippet from which the snippet to save originates :param thumbnail_url: the url of the thumbnail to use when displaying - the snippet to save (default: see '_get_default_snippet_thumbnail') + the snippet to save """ - if not thumbnail_url: - thumbnail_url = self._get_default_snippet_thumbnail(snippet_class) - app_name = template_key.split('.')[0] - snippet_class = snippet_class or 's_custom_snippet' - key = '%s_%s' % (snippet_class, uuid.uuid4().hex) - snippet_key = '%s.%s' % (app_name, key) + snippet_key = '%s_%s' % (snippet_key, uuid.uuid4().hex) + full_snippet_key = '%s.%s' % (app_name, snippet_key) # html to xml to add '/' at the end of self closing tags like br, ... xml_arch = etree.tostring(html.fromstring(arch)) new_snippet_view_values = { 'name': name, - 'key': snippet_key, + 'key': full_snippet_key, 'type': 'qweb', 'arch': xml_arch, } @@ -338,7 +330,7 @@ class IrUiView(models.Model): custom_section = self.search([('key', '=', template_key)]) snippet_addition_view_values = { 'name': name + ' Block', - 'key': self._get_snippet_addition_view_key(template_key, key), + 'key': self._get_snippet_addition_view_key(template_key, snippet_key), 'inherit_id': custom_section.id, 'type': 'qweb', 'arch': """ @@ -350,7 +342,7 @@ class IrUiView(models.Model): <t t-snippet="%s" t-thumbnail="%s"/> </xpath> </data> - """ % (template_key, snippet_key, thumbnail_url), + """ % (template_key, full_snippet_key, thumbnail_url), } snippet_addition_view_values.update(self._snippet_save_view_values_hook()) self.create(snippet_addition_view_values) |
