Add Info providers Admin pages
[cascardo/ipsilon.git] / ipsilon / admin / common.py
index 0a46797..2c8ff89 100755 (executable)
@@ -25,28 +25,45 @@ from ipsilon.util.page import admin_protect
 
 class AdminPluginPage(Page):
 
-    def __init__(self, obj, site, baseurl, facility):
-        super(AdminPluginPage, 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.facility = facility
+        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/plugin_config.html',
-                              title='%s plugin' % self._obj.name,
+        return self._template('admin/plugin_config.html', title=self.title,
                               name='admin_%s_%s_form' % (self.facility,
                                                          self._obj.name),
-                              action=self.url,
+                              menu=self.menu, action=self.url, back=self.back,
+                              options_order=self.options_order,
                               options=self.plugin_config)
 
     @admin_protect
@@ -80,27 +97,31 @@ class AdminPluginPage(Page):
                 self._obj.set_config_value(name, value)
                 self.plugin_config[name][2] = value
 
-        return self._template('admin/plugin_config.html',
+        return self._template('admin/plugin_config.html', title=self.title,
                               message=message,
                               message_type=message_type,
-                              title='%s plugin' % self._obj.name,
                               name='admin_%s_%s_form' % (self.facility,
                                                          self._obj.name),
-                              action=self.url,
+                              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 Admin(Page):
 
     def __init__(self, site, mount):
         super(Admin, self).__init__(site)
         self.url = '%s/%s' % (self.basepath, mount)
+        self.menu = []
 
     def root(self, *args, **kwargs):
-        return self._template('admin/index.html', title='Configuration')
+        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]