deleterequesteduseraccounts.py 656 B

123456789101112131415161718192021222324
  1. from __future__ import unicode_literals
  2. from django.contrib.auth import get_user_model
  3. from django.core.management.base import CommandError, BaseCommand
  4. from misago.core.pgutils import chunk_queryset
  5. UserModel = get_user_model()
  6. class Command(BaseCommand):
  7. help = "Deletes accounts of users that have choosen to delete their account."
  8. def handle(self, *args, **options):
  9. deleted = 0
  10. queryset = UserModel.objects.filter(delete_own_account=True)
  11. for user in chunk_queryset(queryset):
  12. user.delete()
  13. deleted += 1
  14. self.stdout.write('{} user accounts have been deleted.'.format(deleted))