summaryrefslogtreecommitdiff
path: root/addons/website/models
diff options
context:
space:
mode:
authorAndrea Ulliana <aul@odoo.com>2019-06-26 12:28:13 +0000
committerqsm-odoo <qsm@odoo.com>2019-07-30 09:59:28 +0000
commit7deceae18c209c67f6cfbbe3f7704798bb02a42e (patch)
tree625139a2d2a20e9cf4ee0768c92dc172bbde892b /addons/website/models
parent15bae2920cf6cf9e8f399ecc0374da04654ef66f (diff)
[IMP] website, *: use "auto" widget for font customization
* theme_bootswatch, theme_default, website_theme_install This commit makes use of the new 'auto' widget for font selection: instead of enabling a template which will enable a scss file which sets a font variable to a specific value... we directly allow to do a scss custo which sets that value. The code in charge of resetting font customizations on theme switching is also moved and refactored here in website (instead of being specific to each theme). Part of https://github.com/odoo/odoo/pull/33442 task-1974659 Co-authored-by: qsm-odoo <qsm@odoo.com>
Diffstat (limited to 'addons/website/models')
-rw-r--r--addons/website/models/assets.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/website/models/assets.py b/addons/website/models/assets.py
index c2a52588eaa..1bbd653bd47 100644
--- a/addons/website/models/assets.py
+++ b/addons/website/models/assets.py
@@ -1,12 +1,46 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+import re
+
from odoo import models
class Assets(models.AbstractModel):
_inherit = 'web_editor.assets'
+ def make_scss_customization(self, url, values):
+ """
+ Makes a scss customization of the given file. That file must
+ contain a scss map including a line comment containing the word 'hook',
+ to indicate the location where to write the new key,value pairs.
+
+ Params:
+ url (str):
+ the URL of the scss file to customize (supposed to be a variable
+ file which will appear in the assets_common bundle)
+
+ values (dict):
+ key,value mapping to integrate in the file's map (containing the
+ word hook). If a key is already in the file's map, its value is
+ overridden.
+ """
+ custom_url = self.make_custom_asset_file_url(url, 'web.assets_common')
+ updatedFileContent = self.get_asset_content(custom_url) or self.get_asset_content(url)
+ updatedFileContent = updatedFileContent.decode('utf-8')
+ for name, value in values.items():
+ pattern = "'%s': %%s,\n" % name
+ regex = re.compile(pattern % ".+")
+ replacement = pattern % value
+ if regex.search(updatedFileContent):
+ updatedFileContent = re.sub(regex, replacement, updatedFileContent)
+ else:
+ updatedFileContent = re.sub(r'( *)(.*hook.*)', r'\1%s\1\2' % replacement, updatedFileContent)
+
+ # Bundle is 'assets_common' as this route is only meant to update
+ # variables scss files
+ self.save_asset(url, 'web.assets_common', updatedFileContent, 'scss')
+
def _get_custom_attachment(self, custom_url, op='='):
"""
See web_editor.Assets._get_custom_attachment