summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2014-10-14 11:57:28 -0400
committerPatrick Uiterwijk <puiterwijk@redhat.com>2014-10-24 18:02:20 +0200
commitc6fab2542f52f6cca71c207c1925785971e51295 (patch)
tree83c4bb441c7eb62c41b8b58c738e070bde674045
parentcecf9f6c60a048f4f7c947a969f1610695d1d3be (diff)
downloadipsilon-c6fab2542f52f6cca71c207c1925785971e51295.tar.gz
ipsilon-c6fab2542f52f6cca71c207c1925785971e51295.tar.xz
ipsilon-c6fab2542f52f6cca71c207c1925785971e51295.zip
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 <simo@redhat.com>
-rwxr-xr-xipsilon/util/plugin.py24
-rw-r--r--templates/admin/plugin_config.html7
2 files changed, 30 insertions, 1 deletions
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 %}
<div class="form-group">
<label for="{{ o }}">{{ o }}:</label>
- <input type="text" class="form-control" name="{{ o }}" value="{{ plugin.get_config_value(o) }}">
+ {% set val = plugin.get_config_value(o) %}
+ {% if val is string %}
+ <input type="text" class="form-control" name="{{ o }}" value="{{ val }}">
+ {% else %}
+ <input type="text" class="form-control" name="{{ o }}" value="{{ val|join(', ') }}">
+ {% endif %}
</div>
<span class="help-block">{{ plugin.get_config_desc(o) }}</span>
{% endfor %}