Change the admin plugin to not overwrite the plugin default options,
and only use the sanctioned pluginObject interfaces to read/write
config values.
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
class AdminPluginPage(AdminPage):
class AdminPluginPage(AdminPage):
- def __init__(self, obj, site, parent):
+ def __init__(self, po, site, parent):
super(AdminPluginPage, self).__init__(site, form=True)
super(AdminPluginPage, self).__init__(site, form=True)
- self._obj = obj
- self.title = '%s plugin' % obj.name
- self.url = '%s/%s' % (parent.url, obj.name)
+ self._po = po
+ self.title = '%s plugin' % po.name
+ self.url = '%s/%s' % (parent.url, po.name)
self.facility = parent.facility
self.menu = [parent]
self.back = parent.url
# Get the defaults
self.facility = parent.facility
self.menu = [parent]
self.back = parent.url
# Get the defaults
- self.plugin_config = obj.get_config_desc()
- if not self.plugin_config:
- self.plugin_config = dict()
-
- # Now overlay the actual config
- for option in self.plugin_config:
- self.plugin_config[option][2] = obj.get_config_value(option)
+ options = po.get_config_desc()
+ if options is None:
+ options = dict()
- if hasattr(obj, 'conf_opt_order'):
- self.options_order = obj.conf_opt_order
+ if hasattr(po, 'conf_opt_order'):
+ self.options_order = po.conf_opt_order
# append any undefined options
add = []
# append any undefined options
add = []
- for k in self.plugin_config.keys():
+ for k in options.keys():
if k not in self.options_order:
add.append(k)
if len(add):
if k not in self.options_order:
add.append(k)
if len(add):
def GET(self, *args, **kwargs):
return self._template('admin/plugin_config.html', title=self.title,
name='admin_%s_%s_form' % (self.facility,
def GET(self, *args, **kwargs):
return self._template('admin/plugin_config.html', title=self.title,
name='admin_%s_%s_form' % (self.facility,
menu=self.menu, action=self.url, back=self.back,
options_order=self.options_order,
menu=self.menu, action=self.url, back=self.back,
options_order=self.options_order,
- options=self.plugin_config)
@admin_protect
def POST(self, *args, **kwargs):
@admin_protect
def POST(self, *args, **kwargs):
message_type = "info"
new_values = dict()
message_type = "info"
new_values = dict()
+ # Get the defaults
+ options = self._po.get_config_desc()
+ if options is None:
+ options = dict()
+
for key, value in kwargs.iteritems():
for key, value in kwargs.iteritems():
- if key in self.plugin_config:
- if value != self.plugin_config[key][2]:
+ if key in options:
+ if value != self._po.get_config_value(key):
cherrypy.log.error("Storing [%s]: %s = %s" %
cherrypy.log.error("Storing [%s]: %s = %s" %
- (self._obj.name, key, value))
+ (self._po.name, key, value))
new_values[key] = value
if len(new_values) != 0:
# First we try to save in the database
try:
new_values[key] = value
if len(new_values) != 0:
# First we try to save in the database
try:
- self._obj.save_plugin_config(self.facility, new_values)
+ self._po.save_plugin_config(self.facility, new_values)
message = "New configuration saved."
message_type = "success"
except Exception: # pylint: disable=broad-except
message = "New configuration saved."
message_type = "success"
except Exception: # pylint: disable=broad-except
message_type = "error"
# And only if it succeeds we change the live object
message_type = "error"
# And only if it succeeds we change the live object
- for name, value in new_values.items():
- self._obj.set_config_value(name, value)
- self.plugin_config[name][2] = value
+ self._po.refresh_plugin_config(self.facility)
return self._template('admin/plugin_config.html', title=self.title,
message=message,
message_type=message_type,
name='admin_%s_%s_form' % (self.facility,
return self._template('admin/plugin_config.html', title=self.title,
message=message,
message_type=message_type,
name='admin_%s_%s_form' % (self.facility,
menu=self.menu, action=self.url,
menu=self.menu, action=self.url,
- options=self.plugin_config)
self._options = None
self._data = AdminStore()
self._options = None
self._data = AdminStore()
- def get_config_desc(self):
+ def get_config_desc(self, name=None):
""" The configuration description is a dictionary that provides
A description of the supported configuration options, as well
as the default configuration option values.
""" The configuration description is a dictionary that provides
A description of the supported configuration options, as well
as the default configuration option values.
- option type
- default value
"""
- option type
- default value
"""
+ if name is None:
+ return self._options
+
+ opt = self._options.get(name, None)
+ if opt is None:
+ return ''
+ return opt[0]
def set_config(self, config):
self._config = config
def set_config(self, config):
self._config = config
def get_plugin_config(self, facility):
return self._data.load_options(facility, self.name)
def get_plugin_config(self, facility):
return self._data.load_options(facility, self.name)
+ def refresh_plugin_config(self, facility):
+ config = self.get_plugin_config(facility)
+ self.set_config(config)
+
def save_plugin_config(self, facility, config=None):
if config is None:
config = self._config
def save_plugin_config(self, facility, config=None):
if config is None:
config = self._config
{% for o in options_order %}
<div class="form-group">
<label for="{{ o }}">{{ o }}:</label>
{% for o in options_order %}
<div class="form-group">
<label for="{{ o }}">{{ o }}:</label>
- <input type="text" class="form-control" name="{{ o }}" value="{{ options[o][2] }}">
+ <input type="text" class="form-control" name="{{ o }}" value="{{ plugin.get_config_value(o) }}">
- <span class="help-block">{{ options[o][0] }}</span>
+ <span class="help-block">{{ plugin.get_config_desc(o) }}</span>
{% endfor %}
<button id="submit" class="btn btn-primary" name="submit" type="submit" value="Submit">
{% endfor %}
<button id="submit" class="btn btn-primary" name="submit" type="submit" value="Submit">