Revision 3c41f3ef snf-astakos-app/astakos/im/migrations/0016_auth_providers_and_projects.py

b/snf-astakos-app/astakos/im/migrations/0016_auth_providers_and_projects.py
45 45
                            'ASTAKOS_MIGRATION_0045_DELETE_DUPLICATE_USER_IDS',
46 46
                            [])
47 47
        for pk in to_remove:
48
            orm.AstakosUser.objects.filter(pk=int(pk)).delete()
48
            try:
49
                u = orm.AstakosUser.objects.get(pk=int(pk))
50
                print "Removing user: %s (%d)" % (u.email, u.pk)
51
            except Exception:
52
                msg = "You requested user with id %s to be removed but such user doesn't exist in database" % str(pk)
53
                raise Exception(msg)
54

  
55
            if orm.AstakosUser.objects.filter(email__iexact=u.email).count() == 1:
56
                msg = ("You requested user with duplicate email %s and id (%d) to"
57
                " be removed, but it seems that only one user exists with this"
58
                " email in the database.") % (u.email , pk)
59
                raise Exception(msg)
60
            else:
61
                orm.AstakosUser.objects.filter(pk=int(pk)).delete()
49 62

  
50 63
        for u in orm.AstakosUser.objects.all():
51 64
            if orm.AstakosUser.objects.filter(email__iexact=u.email).count() > 1:
......
54 67
                print "Duplicate email found in database"
55 68
                for e in existing:
56 69
                    print "%d: %s (is_active: %s)" % (e.pk, e.email, e.is_active)
57
                keep = input("Select which user id you want to be preserved in the database: ")
70
                keep = input("Select which user id you want to BE PRESERVED in the database: ")
58 71
                if keep:
59 72
                    for e in existing.exclude(pk=int(keep)):
60 73
                        e.delete()

Also available in: Unified diff