VRE Backend API and Scheduler
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

40 lines
1.6 KiB

from django.core.management.base import BaseCommand, CommandError
from django.contrib.auth.models import User
from django.db.utils import IntegrityError
#from polls.models import Question as Poll
class Command(BaseCommand):
help = 'Setting up admin and tusd users for VRE'
def add_arguments(self, parser):
parser.add_argument('username', help='Username')
parser.add_argument('password', help='Password')
parser.add_argument('email', help='Email address')
parser.add_argument('--key', help='Token key')
parser.add_argument('--secret', help='Token secret')
def handle(self, *args, **options):
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']))
if options['key'] is not None and options['secret'] is not None:
user.token.key=options['key']
user.token.secret=options['secret']
user.token.save()
self.stdout.write(self.style.SUCCESS('Successfully created token for user "%s"' % options['username']))
else:
# We do not want an token for the admin
user.token.delete()
except IntegrityError as ex:
if 'unique constraint' in str(ex).lower():
self.stdout.write(self.style.WARNING('User "%s" already exists' % options['username']))
else:
raise CommandError('Could not create user "%s": %s' % (options['username'],ex))