2015-05-01 18:05:34 +00:00
|
|
|
import sys
|
|
|
|
import textwrap
|
|
|
|
|
|
|
|
from django.contrib.auth import get_user_model
|
2015-05-04 14:19:58 +00:00
|
|
|
from django.core.exceptions import FieldError
|
2015-05-01 18:05:34 +00:00
|
|
|
from django.core.management import execute_from_command_line
|
2015-05-04 14:19:58 +00:00
|
|
|
from django.db import models
|
2015-05-01 18:05:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_initial_superuser(**kwargs):
|
|
|
|
if '--noinput' not in sys.argv and '--fake' not in sys.argv and '--fake-initial' not in sys.argv and 'accounts' in sys.argv:
|
|
|
|
model = get_user_model()
|
|
|
|
if not model.objects.filter(is_superuser=True).exists():
|
|
|
|
sys.stdout.write(textwrap.dedent("""
|
|
|
|
It appears that you just installed Accounts application.
|
|
|
|
You can now create a superuser:
|
|
|
|
|
|
|
|
""")
|
|
|
|
)
|
2015-05-04 14:19:58 +00:00
|
|
|
from ..models import Account
|
|
|
|
try:
|
|
|
|
Account.systemusers.related.model.objects.filter(account_id=1).exists()
|
|
|
|
except FieldError:
|
|
|
|
# avoid creating a systemuser when systemuser table is not ready
|
|
|
|
Account.save = models.Model.save
|
2015-05-01 18:05:34 +00:00
|
|
|
manager = sys.argv[0]
|
|
|
|
execute_from_command_line(argv=[manager, 'createsuperuser'])
|