changeset 5938:f4e0854b1604

SystemAdmin user browser: show disabled user accounts at the botton of the list
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 25 Jan 2013 16:34:37 +0100
parents 9a9af7912a44
children 24054d620fc1
files MoinMoin/userform/admin.py
diffstat 1 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/userform/admin.py	Fri Jan 25 15:13:20 2013 +0100
+++ b/MoinMoin/userform/admin.py	Fri Jan 25 16:34:37 2013 +0100
@@ -31,10 +31,28 @@
         Column('action', label=_('Action')),
     ]
 
-    # Iterate over users
+    class UserAccount(object):
+        # namedtuple is >= 2.6 :-(
+        def __init__(self, **kw):
+            for k, v in kw.items():
+                setattr(self, k, v)
+        def __repr__(self):
+            return "<UserAccount %r>" % self.__dict__
+
+    accounts = []
     for uid in user.getUserList(request):
-        account = user.User(request, uid)
+        # be careful and just create a list of what we really need,
+        # not sure if we can keep lots of User objects instantiated
+        # in parallel (open files? too big?)
+        u = user.User(request, uid)
+        accounts.append(UserAccount(name=u.name, email=u.email, jid=u.jid, disabled=u.disabled))
 
+    def sortkey(account):
+        # enabled accounts at top, sorted by name
+        return (account.disabled, account.name)
+
+    # Iterate over user accounts
+    for account in sorted(accounts, key=sortkey):
         account_groups = set(groups.groups_with_member(account.name))
         wiki_groups = set([group for group in account_groups if isinstance(groups[group], WikiGroup)])
         other_groups = list(account_groups - wiki_groups)
@@ -105,7 +123,7 @@
         from MoinMoin.widget.browser import DataBrowserWidget
 
         browser = DataBrowserWidget(request)
-        browser.setData(data, sort_columns=[0])
+        browser.setData(data)
         return browser.render()
 
     # No data