diff --git a/src/core/management/commands/create_conference.py b/src/core/management/commands/create_conference.py index 986a0fe5c69e8ac1aebbf82456d697456d921550..e7dccc788fa2fc474d1a34bbbb53724ea23175f8 100644 --- a/src/core/management/commands/create_conference.py +++ b/src/core/management/commands/create_conference.py @@ -3,6 +3,7 @@ from datetime import datetime from zoneinfo import ZoneInfo +from django.contrib.auth.models import Group from django.core.management import call_command from django.core.management.base import BaseCommand, CommandError from django.utils.text import slugify @@ -76,7 +77,7 @@ INTRO_PAGES = { } -def seed_conference(conf: Conference, year: int = 0, force: bool = False): +def seed_conference(conf: Conference, year: int = 0): if Assembly.objects.filter(conference=conf).exists(): raise ValueError('Conference already has assemblies?!') @@ -373,6 +374,7 @@ class Command(BaseCommand): def handle(self, *args, **options): interactive = options.get('interactive', False) + bootstrap = options.get('bootstrap') if not (name := options.get('name')): if not interactive: self.print_help('manage.py', 'create_conference') @@ -396,9 +398,28 @@ class Command(BaseCommand): year = year.year print(f'Creating conference {slug} ({name}) for year {year}') + # check if the conference already exists + if Conference.objects.filter(slug=slug).exists(): + raise CommandError(f'Conference with slug "{slug}" already exists.') + + if bootstrap and Group.objects.exists(): + answer = None + while answer not in ['y', 'n', '']: + answer = input('Groups are already present in the database. Do you still want to bootstrap? (y/[n]) ') + + bootstrap = answer.lower() == 'y' + if bootstrap: + self.stdout.write(self.style.WARNING('Groups will be loaded and may be duplicated!')) + else: + self.stdout.write(self.style.WARNING('Bootstrap will not be applied.')) + # load our bootstrap fixtures - if options.get('bootstrap'): + if bootstrap or (bootstrap is None and not Group.objects.exists()): + self.stdout.write('Loading bootstrap data...') call_command('loaddata', 'bootstrap_auth_groups.json') + self.stdout.write(self.style.SUCCESS('Bootstrap data loaded.')) + elif bootstrap is None and Group.objects.exists(): + self.stdout.write(self.style.SUCCESS('Groups are already present in the database.')) # create the new conference conf = Conference.objects.create(