@@ -0,0 +1,1070 @@
+from django.core.management.base import BaseCommand%0Afrom mygpo.api.models import Device%0Afrom registration.models import RegistrationProfile%0A%0Aclass Command(BaseCommand):%0A%0A    def handle(self, *args, **options):%0A%0A        for profile in RegistrationProfile.objects.all():%0A%0A            if not profile.activation_key_expired():%0A                continue%0A%0A            user = profile.user%0A            try:%0A                user_profile = user.get_profile()%0A                deleted = user_profile.deleted%0A            except:%0A                deleted = False%0A%0A            if not user.is_active:%0A                if deleted:%0A                    continue%0A%0A                devices = Device.objects.filter(user=user).count()%0A                print '%25s (%25s)' %25 (user, devices)%0A%0A                if devices %3E 0:%0A                    user.is_active = True%0A                    profile.activation_key = RegistrationProfile.ACTIVATED%0A                    user.save()%0A                    profile.save()%0A%0A                else:%0A                    profile.delete()%0A                    user.delete()%0A%0A

add management command cleanup-unused-users