X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Fadmin%2Fcommon.py;h=2c8ff89a7fdb5a00ecaf5b5666fb4fa1e194bdca;hp=7620d3f1ed3c268c80aa670d0693c91b8f3834b8;hb=14e8ecd7cf8ea8d342eac5c4c66b764b3a8e2dbb;hpb=cd30057eec4c772171c5558d9fac2c1f73bc12dd diff --git a/ipsilon/admin/common.py b/ipsilon/admin/common.py index 7620d3f..2c8ff89 100755 --- a/ipsilon/admin/common.py +++ b/ipsilon/admin/common.py @@ -17,52 +17,60 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import cherrypy from ipsilon.util.data import Store from ipsilon.util.page import Page -from ipsilon.util.user import UserSession -import cherrypy -from ipsilon.login.common import FACILITY as LOGIN_FACILITY - - -def admin_protect(fn): +from ipsilon.util.page import admin_protect - def check(*args, **kwargs): - if UserSession().get_user().is_admin: - return fn(*args, **kwargs) - raise cherrypy.HTTPError(403) +class AdminPluginPage(Page): - return check - - -class LoginPluginPage(Page): - - def __init__(self, obj, site, baseurl): - super(LoginPluginPage, self).__init__(site) + def __init__(self, obj, site, parent): + super(AdminPluginPage, self).__init__(site, form=True) self._obj = obj - self.url = '%s/%s' % (baseurl, obj.name) + self.title = '%s plugin' % obj.name + self.url = '%s/%s' % (parent.url, obj.name) + 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 = [] + 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) + self.options_order = [] + if hasattr(obj, 'conf_opt_order'): + self.options_order = obj.conf_opt_order + + # append any undefined options + add = [] + for k in self.plugin_config.keys(): + if k not in self.options_order: + add.append(k) + if len(add): + add.sort() + for k in add: + self.options_order.append(k) + @admin_protect def GET(self, *args, **kwargs): - return self._template('admin/login_plugin.html', - title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, - action=self.url, + return self._template('admin/plugin_config.html', title=self.title, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), + 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): message = "Nothing was modified." + message_type = "info" new_values = dict() for key, value in kwargs.iteritems(): @@ -76,51 +84,44 @@ class LoginPluginPage(Page): # First we try to save in the database try: store = Store() - store.save_plugin_config(LOGIN_FACILITY, + store.save_plugin_config(self.facility, self._obj.name, new_values) message = "New configuration saved." + message_type = "success" except Exception: # pylint: disable=broad-except message = "Failed to save data!" + 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 - return self._template('admin/login_plugin.html', + return self._template('admin/plugin_config.html', title=self.title, message=message, - title='%s plugin' % self._obj.name, - name='admin_login_%s_form' % self._obj.name, - action=self.url, + message_type=message_type, + name='admin_%s_%s_form' % (self.facility, + self._obj.name), + menu=self.menu, action=self.url, options=self.plugin_config) - def root(self, *args, **kwargs): - cherrypy.log.error("method: %s" % cherrypy.request.method) - op = getattr(self, cherrypy.request.method, self.GET) - if callable(op): - return op(*args, **kwargs) - - -class LoginPlugins(Page): - def __init__(self, site, baseurl): - super(LoginPlugins, self).__init__(site) - self.url = '%s/login' % baseurl - - for plugin in self._site[LOGIN_FACILITY]['available']: - cherrypy.log.error('Admin login plugin: %s' % plugin) - obj = self._site[LOGIN_FACILITY]['available'][plugin] - self.__dict__[plugin] = LoginPluginPage(obj, self._site, self.url) - class Admin(Page): - def __init__(self, *args, **kwargs): - super(Admin, self).__init__(*args, **kwargs) - self.url = '%s/admin' % self.basepath - self.login = LoginPlugins(self._site, self.url) + def __init__(self, site, mount): + super(Admin, self).__init__(site) + self.url = '%s/%s' % (self.basepath, mount) + self.menu = [] def root(self, *args, **kwargs): - login_plugins = self._site[LOGIN_FACILITY] - return self._template('admin/index.html', title='Administration', - available=login_plugins['available'], - enabled=login_plugins['enabled']) + return self._template('admin/index.html', + title='Configuration', + menu=self.menu) + + def add_subtree(self, name, page): + self.__dict__[name] = page + self.menu.append(page) + + def del_subtree(self, name): + self.menu.remove(self.__dict__[name]) + del self.__dict__[name]