Browse Source

No not import fixtures data when there is already data in database

master
Joshua Rubingh 7 months ago
parent
commit
0934b27488
  1. 23
      VRE/apps/api/management/commands/dockersetup.py
  2. 7
      docker/entrypoint.api.sh

23
VRE/apps/api/management/commands/dockersetup.py

@ -1,9 +1,13 @@ @@ -1,9 +1,13 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand, CommandError, no_translations
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
from django.core.management import call_command
from django.db.utils import IntegrityError
from apps.university.models import University
from apps.virtual_machine.models import VirtualMachineProfile
class Command(BaseCommand):
help = 'Setting up admin and tusd users for VRE'
@ -13,12 +17,29 @@ class Command(BaseCommand): @@ -13,12 +17,29 @@ class Command(BaseCommand):
parser.add_argument('password', help='Password')
parser.add_argument('email', help='Email address')
parser.add_argument('--loaddata', help='Load initial data')
parser.add_argument('--nokey', help='Skip token key')
parser.add_argument('--key', help='Token key')
parser.add_argument('--secret', help='Token secret')
parser.add_argument('--group', help='Groupname to add the user to')
@no_translations
def handle(self, *args, **options):
if options.get('loaddata'):
university = University.objects.first()
if university is None:
# Load university data
call_command('loaddata', 'university_initial_data')
self.stdout.write(self.style.SUCCESS('Successfully loaded the initial university data'))
virtual_machine_profile = VirtualMachineProfile.objects.first()
if virtual_machine_profile is None:
# Load university data
call_command('loaddata', 'virtual_machine_initial_data')
self.stdout.write(self.style.SUCCESS('Successfully loaded the initial virtual machine data'))
return
try:
user = User.objects.create_superuser(username=options['username'], password=options['password'], email=options['email'])
self.stdout.write(self.style.SUCCESS('Successfully created user "%s"' % (options['username'],)))

7
docker/entrypoint.api.sh

@ -16,13 +16,10 @@ echo "Migrating the database. " @@ -16,13 +16,10 @@ echo "Migrating the database. "
# python manage.py makemigrations --noinput
python manage.py migrate --noinput
# This initial data should only run once..... not sure what happens if run multiple times
python manage.py loaddata virtual_machine_initial_data
python manage.py loaddata university_initial_data
# This is not needed for the API?? Needs to figure this out..
python manage.py collectstatic --noinput
# This initial data. Will check if there is existing data, then no data is imported
python manage.py dockersetup --loaddata 1 NA NA NA
# Create a super user
python manage.py dockersetup --nokey 1 ${DJANGO_ADMIN_NAME} ${DJANGO_ADMIN_PASSWORD} ${DJANGO_ADMIN_EMAIL}
# Create the HAWK REST user

Loading…
Cancel
Save