diff -r 09b7e3fe29b3 -r fb6336b25b8f VirtualMailManager/Domain.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):