You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
etesync-server/django_etebase/admin-cli/management/commands/users-delete.py

31 lines
1.2 KiB

from django.core.management.base import BaseCommand
from myauth.models import User
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument( 'usernames'
, default=False
, type=str
, nargs='*'
, default=[]
, help="Delete ALL users!" )
parser.add_argument( '-a'
, '--all'
, action='store_true'
, default=False
, help="Delete ALL users!" )
def handle(self, *args, **options):
try:
if options["all"]:
for user in User.objects.all():
user.delete()
self.stdout.write(self.style.SUCCESS(f'All users have been deleted.'))
else:
for username in options["usernames"]:
User.objects.get(username=username).delete()
self.stdout.write(self.style.SUCCESS(f'Users have been deleted.'))
except User.DoesNotExist as exception:
self.stdout.write(self.style.ERROR(f'Unable to delete users: ' + str(exception)))