1
0
mirror of https://github.com/etesync/server synced 2024-11-01 05:09:56 +00:00
etesync-server/django_etebase/admin-cli/management/commands/groups-delete.py

28 lines
1.1 KiB
Python
Raw Normal View History

2021-06-02 21:29:18 +00:00
from django.core.management.base import BaseCommand
from django.contrib.auth.models import Group
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument( '-y'
, '--yes'
, action='store_true'
, default=False
, help="Allow deletion of all groups!" )
def handle(self, *args, **options):
if options["yes"] != True:
print('Do you really want to delete all groups? [y/N]: ', end='')
if input() not in ('y', 'Y', 'yes', 'YES', 'Yes'):
self.stdout.write(self.style.SUCCESS(f'No groups have been deleted.'))
exit(0)
try:
for group in Group.objects.all():
group.delete()
self.stdout.write(self.style.SUCCESS(f'All groups have been deleted.'))
exit(0)
except Group.DoesNotExist as exception:
self.stdout.write(self.style.ERROR(f'Unable to delete all groups: ' + str(exception)))
exit(1)