Index: acct_mgr/admin.py
===================================================================
--- acct_mgr/admin.py	(revision 2186)
+++ acct_mgr/admin.py	(working copy)
@@ -28,6 +28,77 @@
     return [(name, value) for name, value in inspect.getmembers(cls)
             if isinstance(value, Option)]
 
+def _setorder(req, stores):
+    """Pull the password store ordering out of the req object"""
+    for store in stores.get_all_stores():
+        stores[store] = int(req.args.get(store.__class__.__name__, 0))
+        continue
+
+
+class StoreOrder(dict):
+    """Keeps the order of the Password Stores"""
+
+    instance = 0
+
+    def __init__(self, d={}, stores=[], list=[]):
+        self.instance += 1
+        self.d = {}
+        self.sxref = {}
+        for store in stores:
+            self.d[store] = 0
+            self[0] = store
+            self.sxref[store.__class__.__name__] = store
+            continue
+        for i, s in enumerate(list):
+            self.d[s] = i + 1
+            self[i + 1] = s
+
+    def __getitem__(self, key):
+        """Lookup a store in the list"""
+        return self.d[key]
+
+    def __setitem__(self, key, value):
+        if isinstance(key, Component):
+            order = self.d[key]
+            self.d[key] = value
+            self.d[order].remove(key)
+            self[value] = key
+        elif isinstance(key, basestring):
+            self.d[self.sxref[key]] = value
+        elif isinstance(key, int):
+            self.d.setdefault(key, [])
+            self.d[key].append(value)
+        else:
+            raise KeyError('Invalid key type (%s) for StoreOrder' 
+                           % str(type(key)))
+        pass
+
+    def get_enabled_stores(self):
+        """Return an ordered list of password stores
+        
+        All stores that are order 0 are dropped from the list.
+        """
+        keys = [k for k in self.d.keys() if isinstance(k, int)]
+        keys.sort()
+        storelist = []
+        for k in keys[1:]:
+            storelist.extend(self.d[k])
+            continue
+        return storelist
+
+    def get_enabled_store_names(self):
+        """Returns the class names of the enabled password stores"""
+        stores = self.get_enabled_stores()
+        return [s.__class__.__name__ for s in stores]
+    
+    def get_all_stores(self):
+        return [k for k in self.d.keys() if isinstance(k, Component)]
+
+    def numstores(self):
+        return len(self.get_all_stores())
+        
+    
+
 class AccountManagerAdminPage(Component):
 
     implements(IAdminPageProvider)
@@ -46,35 +117,45 @@
             return self._do_config(req)
         elif page == 'users': 
             return self._do_users(req) 
-            
+        
     def _do_config(self, req):
+        stores = StoreOrder(stores=self.account_manager.stores, 
+                            list=self.account_manager.password_store)
+
         if req.method == 'POST':
-            selected_class = req.args.get('selected')
-            self.config.set('account-manager', 'password_store', selected_class)
-            selected = self.account_manager.password_store
-            for attr, option in _getoptions(selected):
-                newvalue = req.args.get('%s.%s' % (selected_class, attr))
-                if newvalue is not None:
-                    self.config.set(option.section, option.name, newvalue)
-                    self.config.save()
-        try:
-            selected = self.account_manager.password_store
-        except AttributeError:
-            selected = None
-        sections = [
-            {'name': store.__class__.__name__,
-             'classname': store.__class__.__name__,
-             'selected': store is selected,
-             'options': [
-                {'label': attr,
-                 'name': '%s.%s' % (store.__class__.__name__, attr),
-                 'value': option.__get__(store, store),
-                }
-                for attr, option in _getoptions(store)
-             ],
-            } for store in self.account_manager.stores
-        ]
+            _setorder(req, stores)
+            self.config.set('account-manager', 'password_store', 
+                            ','.join(stores.get_enabled_store_names()))
+            for store in stores.get_all_stores():
+                for attr, option in _getoptions(store):
+                    newvalue = req.args.get('%s.%s' % (store.__class__.__name__, attr))
+                    self.log.debug("%s.%s: %s" % (store.__class__.__name__, attr, newvalue))
+                    if newvalue is not None:
+                        self.config.set(option.section, option.name, newvalue)
+                        self.config.save()
+        
+        sections = []
+        for store in self.account_manager.stores:
+            options = []
+            for attr, option in _getoptions(store):
+                opt_val = option.__get__(store, store)
+                opt_val = isinstance(opt_val, Component) and \
+                          opt_val.__class__.__name__ or opt_val
+                options.append(
+                            {'label': attr,
+                            'name': '%s.%s' % (store.__class__.__name__, attr),
+                            'value': opt_val,
+                            })
+                continue
+            sections.append(
+                        {'name': store.__class__.__name__,
+                        'classname': store.__class__.__name__,
+                        'order': stores[store],
+                        'options' : options,
+                        })
+            continue
         sections = sorted(sections, key=lambda i: i['name'])
+        req.hdf['numstores'] = range(0, stores.numstores() + 1)
         req.hdf['sections'] = sections
         return 'admin_accountsconfig.cs', None
             
