VirtualMailManager/Domain.py
branchv0.6.x
changeset 240 fb6336b25b8f
parent 236 084331dd1e4c
parent 239 184970fd7486
child 242 496099847480
--- a/VirtualMailManager/Domain.py	Sun Apr 04 22:44:58 2010 +0000
+++ b/VirtualMailManager/Domain.py	Mon Apr 05 11:26:54 2010 +0000
@@ -352,25 +352,27 @@
     sql += ' ORDER BY is_primary DESC, domainname'
     dbc = dbh.cursor()
     dbc.execute(sql)
-    doms = dbc.fetchall()
+    result = dbc.fetchall()
     dbc.close()
 
-    domdict = {}
-    order = [dom[0] for dom in doms if dom[2]]
-    if not order:
-        for dom in doms:
-            if dom[0] not in order:
-                order.append(dom[0])
-    for gid, dom, is_primary in doms:
+    gids = [domain[0] for domain in result if domain[2]]
+    domains = {}
+    for gid, domain, is_primary in result:
         if is_primary:
-            domdict[gid] = [dom]
+            if not gid in domains:
+                domains[gid] = [domain]
+            else:
+                domains[gid].insert(0, domain)
         else:
-            try:
-                domdict[gid].append(dom)
-            except KeyError:
-                domdict[gid] = [None, dom]
-    del doms
-    return order, domdict
+            if gid in gids:
+                if gid in domains:
+                    domains[gid].append(domain)
+                else:
+                    domains[gid] = [domain]
+            else:
+                gids.append(gid)
+                domains[gid] = [None, domain]
+    return gids, domains
 
 
 def get_gid(dbh, domainname):