2013-06-08 01:47:17 +08:00
|
|
|
import warnings
|
2009-12-22 23:18:51 +08:00
|
|
|
from optparse import make_option
|
2014-02-27 05:48:20 +08:00
|
|
|
|
2014-06-11 00:22:07 +08:00
|
|
|
from django.apps import apps
|
|
|
|
from django.contrib.auth import get_user_model
|
2013-06-08 01:47:17 +08:00
|
|
|
from django.db import DEFAULT_DB_ALIAS
|
2012-06-06 19:53:12 +08:00
|
|
|
from django.core.management import call_command
|
2007-08-16 22:34:01 +08:00
|
|
|
from django.core.management.base import NoArgsCommand
|
2014-02-27 05:48:20 +08:00
|
|
|
from django.utils.deprecation import RemovedInDjango19Warning
|
2014-06-11 00:22:07 +08:00
|
|
|
from django.utils.six.moves import input
|
2007-08-16 14:06:55 +08:00
|
|
|
|
|
|
|
|
2007-08-16 22:34:01 +08:00
|
|
|
class Command(NoArgsCommand):
|
2007-09-10 05:57:59 +08:00
|
|
|
option_list = NoArgsCommand.option_list + (
|
|
|
|
make_option('--noinput', action='store_false', dest='interactive', default=True,
|
|
|
|
help='Tells Django to NOT prompt the user for input of any kind.'),
|
2012-06-05 22:46:15 +08:00
|
|
|
make_option('--no-initial-data', action='store_false', dest='load_initial_data', default=True,
|
|
|
|
help='Tells Django not to load any initial data after database synchronization.'),
|
2009-12-22 23:18:51 +08:00
|
|
|
make_option('--database', action='store', dest='database',
|
|
|
|
default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
|
|
|
|
'Defaults to the "default" database.'),
|
2007-09-10 05:57:59 +08:00
|
|
|
)
|
2013-06-08 01:47:17 +08:00
|
|
|
help = "Deprecated - use 'migrate' instead."
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2007-08-16 22:34:01 +08:00
|
|
|
def handle_noargs(self, **options):
|
2014-02-27 05:48:20 +08:00
|
|
|
warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
|
2013-06-08 01:47:17 +08:00
|
|
|
call_command("migrate", **options)
|
2014-06-11 00:22:07 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
apps.get_model('auth', 'Permission')
|
|
|
|
except LookupError:
|
|
|
|
return
|
|
|
|
|
|
|
|
UserModel = get_user_model()
|
|
|
|
|
|
|
|
if not UserModel._default_manager.exists() and options.get('interactive'):
|
|
|
|
msg = ("\nYou have installed Django's auth system, and "
|
|
|
|
"don't have any superusers defined.\nWould you like to create one "
|
|
|
|
"now? (yes/no): ")
|
|
|
|
confirm = input(msg)
|
|
|
|
while 1:
|
|
|
|
if confirm not in ('yes', 'no'):
|
|
|
|
confirm = input('Please enter either "yes" or "no": ')
|
|
|
|
continue
|
|
|
|
if confirm == 'yes':
|
|
|
|
call_command("createsuperuser", interactive=True, database=options['database'])
|
|
|
|
break
|