Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
4daac5d60e
  1. 2
      muk_utils/__manifest__.py
  2. 26
      muk_utils/models/scss_editor.py

2
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Utils", "name": "MuK Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": '12.0.1.1.9',
"version": '12.0.1.1.10',
"category": 'Extra Tools', "category": 'Extra Tools',
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",

26
muk_utils/models/scss_editor.py

@ -52,23 +52,35 @@ class ScssEditor(models.AbstractModel):
def _get_variables(self, content, variables): def _get_variables(self, content, variables):
return {var: self._get_variable(content, var) for var in 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 # Read
#---------------------------------------------------------- #----------------------------------------------------------
def get_value(self, url, xmlid, variables):
def get_content(self, url, xmlid):
custom_url = self._get_custom_url(url, xmlid) custom_url = self._get_custom_url(url, xmlid)
custom_attachment = self._get_custom_attachment(custom_url) custom_attachment = self._get_custom_attachment(custom_url)
if custom_attachment.exists(): 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: else:
match = re.compile("^/(\w+)/(.+?)(\.custom\.(.+))?\.(\w+)$").match(url) match = re.compile("^/(\w+)/(.+?)(\.custom\.(.+))?\.(\w+)$").match(url)
module_path = module.get_module_path(match.group(1)) module_path = module.get_module_path(match.group(1))
resource_path = "%s.%s" % (match.group(2), match.group(5)) resource_path = "%s.%s" % (match.group(2), match.group(5))
module_resource_path = module.get_resource_path(module_path, resource_path) module_resource_path = module.get_resource_path(module_path, resource_path)
with open(module_resource_path, "rb") as file: 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 # Write
@ -111,3 +123,9 @@ class ScssEditor(models.AbstractModel):
} }
}) })
self.env["ir.qweb"].clear_caches() 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)
Loading…
Cancel
Save