|
|
|
@ -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'],))) |
|
|
|
|