Improve users-delete interface

pull/99/head
Martin Michalec 3 years ago
parent 211fb12d43
commit 8803d749db

@ -4,22 +4,27 @@ from myauth.models import User
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument( '-y'
, '--yes'
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="Allow deletion of all users!" )
, help="Delete ALL users!" )
def handle(self, *args, **options):
if options["yes"] != True:
print('Do you really want to delete all users? [y/N]: ', end='')
if input()[0] not in ('y', 'Y', 'yes', 'YES', 'Yes'):
self.stdout.write(self.style.SUCCESS(f'No users have been deleted.'))
exit(0)
try:
for user in User.objects.all():
user.delete()
self.stdout.write(self.style.SUCCESS(f'All users have been deleted.'))
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 all users: ' + str(exception)))
self.stdout.write(self.style.ERROR(f'Unable to delete users: ' + str(exception)))

Loading…
Cancel
Save