From 4daac5d60ef888bb81b13cef73cf40a03d69d979 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Thu, 20 Dec 2018 01:13:53 +0000 Subject: [PATCH] publish muk_utils - 12.0 --- muk_utils/__manifest__.py | 2 +- muk_utils/models/scss_editor.py | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 2041041..e0321a5 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.1.9', + "version": '12.0.1.1.10', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_utils/models/scss_editor.py b/muk_utils/models/scss_editor.py index ecc2b3f..39e438d 100644 --- a/muk_utils/models/scss_editor.py +++ b/muk_utils/models/scss_editor.py @@ -52,23 +52,35 @@ class ScssEditor(models.AbstractModel): def _get_variables(self, content, variables): return {var: self._get_variable(content, var) for var in variables} + def _replace_variables(self, content, variables): + for variable in variables: + variable_content = '{0}: {1};'.format( + variable['name'], + variable['value'] + ) + regex = r'{0}\:?\s(.*?);'.format(variable['name']) + content = re.sub(regex, variable_content, content) + return content + #---------------------------------------------------------- # Read #---------------------------------------------------------- - def get_value(self, url, xmlid, variables): + def get_content(self, url, xmlid): custom_url = self._get_custom_url(url, xmlid) custom_attachment = self._get_custom_attachment(custom_url) if custom_attachment.exists(): - content = str(base64.b64decode(custom_attachment.datas)) - return self._get_variables(content, variables) + return base64.b64decode(custom_attachment.datas).decode('utf-8') else: match = re.compile("^/(\w+)/(.+?)(\.custom\.(.+))?\.(\w+)$").match(url) module_path = module.get_module_path(match.group(1)) resource_path = "%s.%s" % (match.group(2), match.group(5)) module_resource_path = module.get_resource_path(module_path, resource_path) with open(module_resource_path, "rb") as file: - return self._get_variables(str(file.read()), variables) + return file.read().decode('utf-8') + + def get_values(self, url, xmlid, variables): + return self._get_variables(self.get_content(url, xmlid), variables) #---------------------------------------------------------- # Write @@ -110,4 +122,10 @@ class ScssEditor(models.AbstractModel): 'new_url': custom_url, } }) - self.env["ir.qweb"].clear_caches() \ No newline at end of file + self.env["ir.qweb"].clear_caches() + + def replace_values(self, url, xmlid, variables): + content = self._replace_variables( + self.get_content(url, xmlid), variables + ) + self.replace_content(url, xmlid, content) \ No newline at end of file