Refactor the data store a bit
[cascardo/ipsilon.git] / ipsilon / admin / common.py
index 424103e..85bd5fd 100755 (executable)
@@ -18,7 +18,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import cherrypy
-from ipsilon.util.data import Store
 from ipsilon.util.page import Page
 from ipsilon.util.page import admin_protect
 
@@ -32,22 +31,38 @@ class AdminPluginPage(Page):
         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=self.title,
                               name='admin_%s_%s_form' % (self.facility,
                                                          self._obj.name),
-                              menu=self.menu, action=self.url,
+                              menu=self.menu, action=self.url, back=self.back,
+                              options_order=self.options_order,
                               options=self.plugin_config)
 
     @admin_protect
@@ -67,9 +82,7 @@ class AdminPluginPage(Page):
         if len(new_values) != 0:
             # First we try to save in the database
             try:
-                store = Store()
-                store.save_plugin_config(self.facility,
-                                         self._obj.name, new_values)
+                self._obj.save_plugin_config(self.facility, new_values)
                 message = "New configuration saved."
                 message_type = "success"
             except Exception:  # pylint: disable=broad-except