diff --git a/.env.dist b/.env.dist index 4ee5ed69d..bf8f775c3 100644 --- a/.env.dist +++ b/.env.dist @@ -4,9 +4,12 @@ SQL_PASSWORD= SQL_HOST= AML_DEBUG=true DJANGO_SETTINGS_MODULE=aml.development_settings +DJANGO_SUPERUSER_USERNAME=admin # do not use in production! +DJANGO_SUPERUSER_PASSWORD=admin # do not use in production! +DJANGO_SUPERUSER_EMAIL=mail@example.com # do not use in production! AML_LOCATION_PROVIDER=http://ip2country:8854 REACT_APP_API_ROOT=http://localhost:8000 -REACT_APP_EXPERIMENT_SLUG= +REACT_APP_EXPERIMENT_SLUG=gold-msi REACT_APP_AML_HOME=https://www.amsterdammusiclab.nl REACT_APP_LOGO_URL= REACT_APP_HTML_PAGE_TITLE=Amsterdam Music Lab Experiment diff --git a/backend/experiment/management/commands/bootstrap.py b/backend/experiment/management/commands/bootstrap.py new file mode 100644 index 000000000..3e340bd90 --- /dev/null +++ b/backend/experiment/management/commands/bootstrap.py @@ -0,0 +1,26 @@ +from django.core import management +from django.core.management.base import BaseCommand +from django.contrib.auth.models import User + +from experiment.models import Experiment +from section.models import Playlist + +class Command(BaseCommand): + """ Command for creating a superuser and an experiment if they do not yet exist """ + + def handle(self, *args, **options): + if User.objects.count() == 0: + management.call_command('createsuperuser', '--no-input') + logger.info('Created superuser') + if Experiment.objects.count() == 0: + playlist = Playlist.objects.create( + name='Empty Playlist' + ) + experiment = Experiment.objects.create( + name='Goldsmiths Musical Sophistication Index', + rules='GOLD_MSI', + slug='gold-msi', + ) + experiment.playlists.add(playlist) + print('Created default experiment') + diff --git a/backend/manage.py b/backend/manage.py index 2a997e7fc..041efeacc 100755 --- a/backend/manage.py +++ b/backend/manage.py @@ -1,10 +1,8 @@ #!/usr/bin/env python """Django's command-line utility for administrative tasks.""" -import os import sys from os.path import join, dirname from dotenv import load_dotenv -from pathlib import Path def main(): env_path = join(dirname(__file__), '.env') diff --git a/docker-compose.yaml b/docker-compose.yaml index ba7319826..03f2b3ed3 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -42,6 +42,9 @@ services: environment: - AML_DEBUG=${AML_DEBUG} - DJANGO_SETTINGS_MODULE=${DJANGO_SETTINGS_MODULE} + - DJANGO_SUPERUSER_USERNAME=${DJANGO_SUPERUSER_USERNAME} + - DJANGO_SUPERUSER_PASSWORD=${DJANGO_SUPERUSER_PASSWORD} + - DJANGO_SUPERUSER_EMAIL=${DJANGO_SUPERUSER_EMAIL} - AML_LOCATION_PROVIDER=${AML_LOCATION_PROVIDER} - SQL_DATABASE=${SQL_DATABASE} - SQL_USER=${SQL_USER} @@ -49,7 +52,7 @@ services: - SQL_HOST=${SQL_HOST} ports: - 8000:8000 - command: bash -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000" + command: bash -c "python manage.py migrate && python manage.py bootstrap && python manage.py runserver 0.0.0.0:8000" client: build: context: ./frontend