3 # Copyright (C) 2014 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 from ipsilon.util.data import Store
22 from ipsilon.util.page import Page
23 from ipsilon.util.page import admin_protect
26 class AdminPluginPage(Page):
28 def __init__(self, obj, site, baseurl, facility):
29 super(AdminPluginPage, self).__init__(site)
31 self.url = '%s/%s' % (baseurl, obj.name)
32 self.facility = facility
35 self.plugin_config = obj.get_config_desc()
36 if not self.plugin_config:
37 self.plugin_config = []
39 # Now overlay the actual config
40 for option in self.plugin_config:
41 self.plugin_config[option][2] = obj.get_config_value(option)
44 def GET(self, *args, **kwargs):
45 return self._template('admin/plugin_config.html',
46 title='%s plugin' % self._obj.name,
47 name='admin_%s_%s_form' % (self.facility,
50 options=self.plugin_config)
53 def POST(self, *args, **kwargs):
55 message = "Nothing was modified."
59 for key, value in kwargs.iteritems():
60 if key in self.plugin_config:
61 if value != self.plugin_config[key][2]:
62 cherrypy.log.error("Storing [%s]: %s = %s" %
63 (self._obj.name, key, value))
64 new_values[key] = value
66 if len(new_values) != 0:
67 # First we try to save in the database
70 store.save_plugin_config(self.facility,
71 self._obj.name, new_values)
72 message = "New configuration saved."
73 message_type = "success"
74 except Exception: # pylint: disable=broad-except
75 message = "Failed to save data!"
76 message_type = "error"
78 # And only if it succeeds we change the live object
79 for name, value in new_values.items():
80 self._obj.set_config_value(name, value)
81 self.plugin_config[name][2] = value
83 return self._template('admin/plugin_config.html',
85 message_type=message_type,
86 title='%s plugin' % self._obj.name,
87 name='admin_%s_%s_form' % (self.facility,
90 options=self.plugin_config)
92 def root(self, *args, **kwargs):
93 cherrypy.log.error("method: %s" % cherrypy.request.method)
94 op = getattr(self, cherrypy.request.method, self.GET)
96 return op(*args, **kwargs)
101 def __init__(self, site, mount):
102 super(Admin, self).__init__(site)
103 self.url = '%s/%s' % (self.basepath, mount)
105 def root(self, *args, **kwargs):
106 return self._template('admin/index.html', title='Configuration')