From: Simo Sorce Date: Tue, 14 Oct 2014 15:57:28 +0000 (-0400) Subject: Handle lists type options in plugins configuration X-Git-Tag: v0.3.0~55 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=c6fab2542f52f6cca71c207c1925785971e51295 Handle lists type options in plugins configuration Autodetect and convert config values based on the options definition. If the option is marked as list split a string on setting the configuration or join the list into a string before saving it to the database. Signed-off-by: Simo Sorce --- diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index 48edf0e..9222a35 100755 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -132,8 +132,23 @@ class PluginObject(Log): return '' return opt[0] + def _value_to_list(self, name): + if name not in self._config: + return + value = self._config[name] + if type(value) is list: + return + vlist = [x.strip() for x in value.split(',')] + self._config[name] = vlist + def set_config(self, config): self._config = config + if self._config is None: + return + if self._options: + for name, opt in self._options.iteritems(): + if opt[1] == 'list': + self._value_to_list(name) def get_config_value(self, name): value = None @@ -154,6 +169,9 @@ class PluginObject(Log): if not self._config: self._config = dict() self._config[option] = value + if self._options and option in self._options: + if self._options[option][1] == 'list': + self._value_to_list(option) def get_plugin_config(self, facility): return self._data.load_options(facility, self.name) @@ -165,6 +183,12 @@ class PluginObject(Log): def save_plugin_config(self, facility, config=None): if config is None: config = self._config + config = config.copy() + + for key, value in config.items(): + if type(value) is list: + config[key] = ','.join(value) + self._data.save_options(facility, self.name, config) def get_data(self, idval=None, name=None, value=None): diff --git a/templates/admin/plugin_config.html b/templates/admin/plugin_config.html index 70d56f0..e722aa1 100644 --- a/templates/admin/plugin_config.html +++ b/templates/admin/plugin_config.html @@ -12,7 +12,12 @@ {% for o in options_order %}
- + {% set val = plugin.get_config_value(o) %} + {% if val is string %} + + {% else %} + + {% endif %}
{{ plugin.get_config_desc(o) }} {% endfor %}