From 269e2ca36f9d69591052175d91bad53150d32eb7 Mon Sep 17 00:00:00 2001 From: Nicolas Bessi Date: Tue, 9 Sep 2014 14:56:04 +0200 Subject: [PATCH] Refactor in order to support dotted parameters --- server_environment/serv_config.py | 18 ++++++++---------- server_environment/system_info.py | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/server_environment/serv_config.py b/server_environment/serv_config.py index 472b4db07..0fd903897 100644 --- a/server_environment/serv_config.py +++ b/server_environment/serv_config.py @@ -133,15 +133,16 @@ class ServerConfiguration(models.TransientModel): def _add_columns(self): """Add columns to model dynamically""" cols = chain( - self._get_base_cols(), - self._get_env_cols(), - self._get_system_cols() + self._get_base_cols().items(), + self._get_env_cols().items(), + self._get_system_cols().items() ) - for col in cols: - print col + for col, value in cols: + col_name = col.replace('.', '_') setattr(ServerConfiguration, - col, + col_name, fields.Char(string=col, readonly=True)) + self._conf_defaults[col_name] = value def _get_base_cols(self): """ Compute base fields""" @@ -152,7 +153,6 @@ class ServerConfiguration(models.TransientModel): # fld.name = key # fld.model_name = self._model res[key] = item - self._conf_defaults[key] = item return res def _get_env_cols(self, sections=None): @@ -163,7 +163,6 @@ class ServerConfiguration(models.TransientModel): for col, item in serv_config.items(section): key = self._format_key(section, col) res[key] = item - self._conf_defaults[key] = item return res def _get_system_cols(self): @@ -172,7 +171,6 @@ class ServerConfiguration(models.TransientModel): for col, item in get_server_environment(): key = self._format_key('system', col) res[key] = item - self._conf_defaults[key] = item return res def _group(self, items): @@ -180,7 +178,7 @@ class ServerConfiguration(models.TransientModel): names = [] for key in sorted(items): - names.append(key) + names.append(key.replace('.', '_')) return ('' + ''.join(['' % _escape(name) for name in names]) + diff --git a/server_environment/system_info.py b/server_environment/system_info.py index bd0f5fea8..fd590eafc 100644 --- a/server_environment/system_info.py +++ b/server_environment/system_info.py @@ -53,7 +53,7 @@ def get_server_environment(): lsbinfo = 'not lsb compliant' return ( ('platform', platform.platform()), - ('os name', os.name), + ('os.name', os.name), ('lsb_release', lsbinfo), ('release', platform.release()), ('version', platform.version()),