Skip to content
Snippets Groups Projects
Commit 7deceae1 authored by Andrea Ulliana's avatar Andrea Ulliana Committed by qsm-odoo
Browse files

[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: default avatarqsm-odoo <qsm@odoo.com>
parent 15bae292
Branches
Tags
No related merge requests found
Showing
with 42 additions and 38 deletions
from odoo import models
class ThemeBootswatch(models.AbstractModel):
_inherit = 'theme.utils'
......
from odoo import models
class ThemeDefault(models.AbstractModel):
_inherit = 'theme.utils'
......
......@@ -369,10 +369,6 @@ class Website(Home):
@http.route(['/website/make_scss_custo'], type='json', auth='user', website=True)
def make_scss_custo(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
......@@ -382,24 +378,11 @@ class Website(Home):
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.
"""
AssetsUtils = request.env['web_editor.assets']
custom_url = AssetsUtils.make_custom_asset_file_url(url, 'web.assets_common')
updatedFileContent = AssetsUtils.get_asset_content(custom_url) or AssetsUtils.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
AssetsUtils.save_asset(url, 'web.assets_common', updatedFileContent, 'scss')
Returns:
boolean
"""
request.env['web_editor.assets'].make_scss_customization(url, values)
return True
@http.route(['/website/multi_render'], type='json', auth="public", website=True)
......
# -*- 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
......
......@@ -25,9 +25,9 @@ $body-color: palette-color('text') !default;
//
// Font, line-height, and color for body text, headings, and more.
$font-family-sans-serif: nth($o-theme-fonts, $o-theme-font-number) !default;
$font-family-sans-serif: $o-theme-font !default;
$headings-font-family: nth($o-theme-fonts, $o-theme-headings-font-number) !default;
$headings-font-family: $o-theme-headings-font !default;
$headings-color: palette-color('h1') !default;
// Jumbotron
......
$o-theme-font-number: 2;
$o-theme-font-number: 3;
$o-theme-font-number: 4;
$o-theme-font-number: 5;
$o-theme-font-number: 6;
$o-theme-buttons-font-number: 2;
$o-theme-buttons-font-number: 3;
$o-theme-buttons-font-number: 4;
$o-theme-buttons-font-number: 5;
$o-theme-buttons-font-number: 6;
$o-theme-navbar-font-number: 2;
$o-theme-navbar-font-number: 3;
$o-theme-navbar-font-number: 4;
$o-theme-navbar-font-number: 5;
$o-theme-navbar-font-number: 6;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment