Allow plugins to determine config options order
authorSimo Sorce <simo@redhat.com>
Fri, 29 Aug 2014 21:50:45 +0000 (17:50 -0400)
committerPatrick Uiterwijk <puiterwijk@redhat.com>
Wed, 24 Sep 2014 18:29:35 +0000 (20:29 +0200)
Ordering may also be partial, for any option not specified they will be
appended in lexycographic order.

Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
ipsilon/admin/common.py
templates/admin/plugin_config.html

index 424103e..d2ef3cf 100755 (executable)
@@ -36,18 +36,33 @@ class AdminPluginPage(Page):
         # 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,
+                              options_order=self.options_order,
                               options=self.plugin_config)
 
     @admin_protect
index 7c143af..1f75182 100644 (file)
@@ -9,7 +9,7 @@
     <div id="options">
         <form role="form" id="{{ name }}" action="{{ action }}" method="post" enctype="application/x-www-form-urlencoded">
 
-        {% for o in options %}
+        {% 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] }}">