merged changes from default(184970fd7486) v0.6.x
authorPascal Volk <neverseen@users.sourceforge.net>
Mon, 05 Apr 2010 11:26:54 +0000
branchv0.6.x
changeset 240 fb6336b25b8f
parent 237 09b7e3fe29b3 (current diff)
parent 239 184970fd7486 (diff)
child 241 2493453f2c10
merged changes from default(184970fd7486)
VirtualMailManager/Domain.py
VirtualMailManager/Handler.py
--- 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):