server-environment: Run pre-commit
This commit is contained in:
parent
e9d8dccc2d
commit
65ba74b1e9
|
|
@ -181,13 +181,18 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
# _server_env_has_key_defined so we are sure that the value is
|
||||
# either in the global or the record config
|
||||
getter = getattr(serv_config, config_getter)
|
||||
if section_name in serv_config and field_name in serv_config[section_name]:
|
||||
if (
|
||||
section_name in serv_config
|
||||
and field_name in serv_config[section_name]
|
||||
):
|
||||
value = getter(section_name, field_name)
|
||||
else:
|
||||
value = getter(global_section_name, field_name)
|
||||
except Exception:
|
||||
_logger.exception(
|
||||
"error trying to read field %s in section %s", field_name, section_name
|
||||
"error trying to read field %s in section %s",
|
||||
field_name,
|
||||
section_name,
|
||||
)
|
||||
return False
|
||||
return value
|
||||
|
|
@ -201,7 +206,8 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
and field_name in serv_config[global_section_name]
|
||||
)
|
||||
has_config = (
|
||||
section_name in serv_config and field_name in serv_config[section_name]
|
||||
section_name in serv_config
|
||||
and field_name in serv_config[section_name]
|
||||
)
|
||||
return has_global_config or has_config
|
||||
|
||||
|
|
@ -243,7 +249,9 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
record._compute_server_env_from_config(field_name, options)
|
||||
|
||||
else:
|
||||
record._compute_server_env_from_default(field_name, options)
|
||||
record._compute_server_env_from_default(
|
||||
field_name, options
|
||||
)
|
||||
|
||||
def _inverse_server_env(self, field_name):
|
||||
options = self._server_env_fields[field_name]
|
||||
|
|
@ -271,8 +279,12 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
# in ``_inverse_server_env`` it would reset the value of the field
|
||||
for record in self:
|
||||
for field_name in self._server_env_fields:
|
||||
is_editable_field = self._server_env_is_editable_fieldname(field_name)
|
||||
is_editable = not record._server_env_has_key_defined(field_name)
|
||||
is_editable_field = self._server_env_is_editable_fieldname(
|
||||
field_name
|
||||
)
|
||||
is_editable = not record._server_env_has_key_defined(
|
||||
field_name
|
||||
)
|
||||
record[is_editable_field] = is_editable
|
||||
|
||||
def _server_env_view_set_readonly(self, view_arch):
|
||||
|
|
@ -282,12 +294,17 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
for elem in view_arch.findall(field_xpath % field):
|
||||
# set env-computed fields to readonly if the configuration
|
||||
# files have a key set for this field
|
||||
elem.set("attrs", str({"readonly": [(is_editable_field, "=", False)]}))
|
||||
elem.set(
|
||||
"attrs",
|
||||
str({"readonly": [(is_editable_field, "=", False)]}),
|
||||
)
|
||||
if not view_arch.findall(field_xpath % is_editable_field):
|
||||
# add the _is_editable fields in the view for the 'attrs'
|
||||
# domain
|
||||
view_arch.append(
|
||||
etree.Element("field", name=is_editable_field, invisible="1")
|
||||
etree.Element(
|
||||
"field", name=is_editable_field, invisible="1"
|
||||
)
|
||||
)
|
||||
return view_arch
|
||||
|
||||
|
|
@ -295,7 +312,10 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
self, view_id=None, view_type="form", toolbar=False, submenu=False
|
||||
):
|
||||
view_data = super()._fields_view_get(
|
||||
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
|
||||
view_id=view_id,
|
||||
view_type=view_type,
|
||||
toolbar=toolbar,
|
||||
submenu=submenu,
|
||||
)
|
||||
view_arch = etree.fromstring(view_data["arch"].encode("utf-8"))
|
||||
view_arch = self._server_env_view_set_readonly(view_arch)
|
||||
|
|
@ -322,7 +342,9 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
field.compute = "_compute_server_env"
|
||||
|
||||
inverse_method_name = "_inverse_server_env_%s" % field.name
|
||||
inverse_method = partialmethod(type(self)._inverse_server_env, field.name)
|
||||
inverse_method = partialmethod(
|
||||
type(self)._inverse_server_env, field.name
|
||||
)
|
||||
setattr(type(self), inverse_method_name, inverse_method)
|
||||
field.inverse = inverse_method_name
|
||||
field.store = False
|
||||
|
|
@ -368,7 +390,9 @@ class ServerEnvMixin(models.AbstractModel):
|
|||
base_field_cls = base_field.__class__
|
||||
field_args = base_field.args.copy()
|
||||
field_args.pop("_sequence", None)
|
||||
field_args.update({"sparse": "server_env_defaults", "automatic": True})
|
||||
field_args.update(
|
||||
{"sparse": "server_env_defaults", "automatic": True}
|
||||
)
|
||||
|
||||
if hasattr(base_field, "selection"):
|
||||
field_args["selection"] = base_field.selection
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ try:
|
|||
_dir = os.path.dirname(server_environment_files.__file__)
|
||||
except ImportError:
|
||||
_logger.info(
|
||||
"not using server_environment_files for configuration," " no directory found"
|
||||
"not using server_environment_files for configuration,"
|
||||
" no directory found"
|
||||
)
|
||||
_dir = None
|
||||
|
||||
|
|
@ -119,7 +120,9 @@ def _load_config_from_server_env_files(config_p):
|
|||
try:
|
||||
config_p.read(conf_files)
|
||||
except Exception as e:
|
||||
raise Exception('Cannot read config files "{}": {}'.format(conf_files, e))
|
||||
raise Exception(
|
||||
'Cannot read config files "{}": {}'.format(conf_files, e)
|
||||
)
|
||||
|
||||
|
||||
def _load_config_from_rcfile(config_p):
|
||||
|
|
@ -209,7 +212,8 @@ class ServerConfiguration(models.TransientModel):
|
|||
ServerConfiguration,
|
||||
col_name,
|
||||
fields.Char(
|
||||
string=cls._format_key_display_name(col_name), readonly=True
|
||||
string=cls._format_key_display_name(col_name),
|
||||
readonly=True,
|
||||
),
|
||||
)
|
||||
cls._conf_defaults[col_name] = value
|
||||
|
|
@ -253,7 +257,10 @@ class ServerConfiguration(models.TransientModel):
|
|||
return (
|
||||
'<group col="2" colspan="4">'
|
||||
+ "".join(
|
||||
['<field name="%s" readonly="1"/>' % _escape(name) for name in names]
|
||||
[
|
||||
'<field name="%s" readonly="1"/>' % _escape(name)
|
||||
for name in names
|
||||
]
|
||||
)
|
||||
+ "</group>"
|
||||
)
|
||||
|
|
@ -292,13 +299,13 @@ class ServerConfiguration(models.TransientModel):
|
|||
self, view_id=None, view_type="form", toolbar=False, submenu=False
|
||||
):
|
||||
"""Overwrite the default method to render the custom view."""
|
||||
res = super().fields_view_get(
|
||||
view_id, view_type, toolbar
|
||||
)
|
||||
res = super().fields_view_get(view_id, view_type, toolbar)
|
||||
View = self.env["ir.ui.view"]
|
||||
if view_type == "form":
|
||||
arch_node = self._arch
|
||||
xarch, xfields = View.postprocess_and_fields(self._name, arch_node, view_id)
|
||||
xarch, xfields = View.postprocess_and_fields(
|
||||
self._name, arch_node, view_id
|
||||
)
|
||||
res["arch"] = xarch
|
||||
res["fields"] = xfields
|
||||
return res
|
||||
|
|
|
|||
|
|
@ -30,7 +30,11 @@ from odoo.tools.config import config
|
|||
def _get_output(cmd):
|
||||
bindir = config["root_path"]
|
||||
p = subprocess.Popen(
|
||||
cmd, shell=True, cwd=bindir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
|
||||
cmd,
|
||||
shell=True,
|
||||
cwd=bindir,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT,
|
||||
)
|
||||
return p.communicate()[0].rstrip()
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ class ServerEnvironmentCase(common.SavepointCase):
|
|||
def load_config(self, public=None, secret=None):
|
||||
original_serv_config = server_env_mixin.serv_config
|
||||
try:
|
||||
with self.set_config_dir(None), self.set_env_variables(public, secret):
|
||||
with self.set_config_dir(None), self.set_env_variables(
|
||||
public, secret
|
||||
):
|
||||
parser = server_env._load_config()
|
||||
server_env_mixin.serv_config = parser
|
||||
yield
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
# Copyright 2018 Camptocamp (https://www.camptocamp.com).
|
||||
# License GPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from .. import server_env
|
||||
|
||||
from . import common
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue