VirtualMailManager/Domain.py
changeset 239 184970fd7486
parent 162 0ac9ef587769
child 240 fb6336b25b8f
--- a/VirtualMailManager/Domain.py	Mon Apr 05 10:22:51 2010 +0000
+++ b/VirtualMailManager/Domain.py	Mon Apr 05 11:00:13 2010 +0000
@@ -289,23 +289,25 @@
     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 len(order) == 0:
-        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