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