magic-removal: Changed django.core.management to remove legacy 'dbcheck' cruft and add a nicety in createsuperuser that uses the local OS user's username by default
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2407 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b00a599720
commit
e6962ff1a5
|
@ -661,13 +661,32 @@ def createsuperuser(username=None, email=None, password=None):
|
||||||
"Creates a superuser account."
|
"Creates a superuser account."
|
||||||
from django.core import validators
|
from django.core import validators
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
import getpass
|
import getpass, pwd
|
||||||
|
|
||||||
|
# Determine the current system user's username, to use as a default.
|
||||||
|
default_username = pwd.getpwuid(os.getuid())[0].replace(' ', '').lower()
|
||||||
|
|
||||||
|
# Determine whether the default username is taken, so we don't display
|
||||||
|
# it as an option.
|
||||||
|
if default_username:
|
||||||
|
try:
|
||||||
|
User.objects.get(username=default_username)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
default_username = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while 1:
|
while 1:
|
||||||
if not username:
|
if not username:
|
||||||
username = raw_input('Username (only letters, digits and underscores): ')
|
input_msg = 'Username'
|
||||||
|
if default_username:
|
||||||
|
input_msg += ' (Leave blank to use %r)' % default_username
|
||||||
|
username = raw_input(input_msg + ': ')
|
||||||
|
if default_username and username == '':
|
||||||
|
username = default_username
|
||||||
if not username.isalnum():
|
if not username.isalnum():
|
||||||
sys.stderr.write("Error: That username is invalid.\n")
|
sys.stderr.write("Error: That username is invalid. Use only letters, digits and underscores.\n")
|
||||||
username = None
|
username = None
|
||||||
try:
|
try:
|
||||||
User.objects.get(username=username)
|
User.objects.get(username=username)
|
||||||
|
@ -1088,7 +1107,6 @@ DEFAULT_ACTION_MAPPING = {
|
||||||
NO_SQL_TRANSACTION = (
|
NO_SQL_TRANSACTION = (
|
||||||
'adminindex',
|
'adminindex',
|
||||||
'createcachetable',
|
'createcachetable',
|
||||||
'dbcheck',
|
|
||||||
'install',
|
'install',
|
||||||
'installperms',
|
'installperms',
|
||||||
'reset',
|
'reset',
|
||||||
|
@ -1201,16 +1219,13 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
|
||||||
action_mapping[action](addr, port)
|
action_mapping[action](addr, port)
|
||||||
else:
|
else:
|
||||||
from django.db import models
|
from django.db import models
|
||||||
if action == 'dbcheck':
|
try:
|
||||||
mod_list = models.get_all_installed_modules()
|
mod_list = [models.get_app(app_label) for app_label in args[1:]]
|
||||||
else:
|
except ImportError, e:
|
||||||
try:
|
sys.stderr.write("Error: %s. Are you sure your INSTALLED_APPS setting is correct?\n" % e)
|
||||||
mod_list = [models.get_app(app_label) for app_label in args[1:]]
|
sys.exit(1)
|
||||||
except ImportError, e:
|
if not mod_list:
|
||||||
sys.stderr.write("Error: %s. Are you sure your INSTALLED_APPS setting is correct?\n" % e)
|
parser.print_usage_and_exit()
|
||||||
sys.exit(1)
|
|
||||||
if not mod_list:
|
|
||||||
parser.print_usage_and_exit()
|
|
||||||
if action not in NO_SQL_TRANSACTION:
|
if action not in NO_SQL_TRANSACTION:
|
||||||
print "BEGIN;"
|
print "BEGIN;"
|
||||||
for mod in mod_list:
|
for mod in mod_list:
|
||||||
|
|
Loading…
Reference in New Issue