django-orchestra/orchestra/apps/accounts/management/commands/createinitialaccount.py

32 lines
1.2 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from optparse import make_option
2014-09-26 15:05:20 +00:00
from django.core.management.base import BaseCommand
2014-05-08 16:59:35 +00:00
from django.db import transaction
from orchestra.apps.accounts.models import Account
class Command(BaseCommand):
def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
self.option_list = BaseCommand.option_list + (
make_option('--noinput', action='store_false', dest='interactive',
default=True),
make_option('--username', action='store', dest='username'),
make_option('--password', action='store', dest='password'),
make_option('--email', action='store', dest='email'),
)
option_list = BaseCommand.option_list
help = 'Used to create an initial account and its user.'
@transaction.atomic
def handle(self, *args, **options):
interactive = options.get('interactive')
if not interactive:
email = options.get('email')
username = options.get('username')
password = options.get('password')
2014-08-29 12:45:27 +00:00
account = Account.objects.create()
2014-09-26 15:05:20 +00:00
account.users.create_superuser(username, email, password, is_main=True)