Ticket #798: createsuperuser.patch

File createsuperuser.patch, 3.4 KB (added by bjorn@…, 19 years ago)

Patch to createsuperuser

  • django/bin/django-admin.py

     
    8181        translation.activate('en-us')
    8282
    8383    if action in ('createsuperuser', 'init', 'validate'):
    84         ACTION_MAPPING[action]()
     84        ACTION_MAPPING[action](*args[1:])
    8585    elif action == 'inspectdb':
    8686        try:
    8787            param = args[1]
  • django/core/management.py

     
    480480startapp.help_doc = "Creates a Django app directory structure for the given app name in the current directory."
    481481startapp.args = "[appname]"
    482482
    483 def createsuperuser():
     483def createsuperuser(username=None, email=None, password=None):
    484484    "Creates a superuser account."
    485485    from django.core import validators
    486486    from django.models.auth import users
    487487    import getpass
    488488    try:
    489489        while 1:
    490             username = raw_input('Username (only letters, digits and underscores): ')
     490            if not username: username = raw_input('Username (only letters, digits and underscores): ')
    491491            if not username.isalnum():
    492                 sys.stderr.write("Error: That username is invalid.\n")
    493                 continue
     492                sys.stderr.write("Error: That username is invalid\n")
     493                username = None
    494494            try:
    495495                users.get_object(username__exact=username)
    496496            except users.UserDoesNotExist:
    497497                break
    498498            else:
    499                 sys.stderr.write("Error: That username is already taken.\n")
     499                sys.stderr.write("Error: That username is already taken\n")
     500                username = None
    500501        while 1:
    501             email = raw_input('E-mail address: ')
     502            if not email: email = raw_input('E-mail address: ')
    502503            try:
    503504                validators.isValidEmail(email, None)
    504505            except validators.ValidationError:
    505                 sys.stderr.write("Error: That e-mail address is invalid.\n")
     506                sys.stderr.write("Error: That e-mail address is invalid\n")
     507                email = None
    506508            else:
    507509                break
    508510        while 1:
    509             password = getpass.getpass()
    510             password2 = getpass.getpass('Password (again): ')
    511             if password != password2:
    512                 sys.stderr.write("Error: Your passwords didn't match.\n")
    513                 continue
     511            if not password:
     512                password = getpass.getpass()
     513                password2 = getpass.getpass('Password (again): ')
     514                if password != password2:
     515                    sys.stderr.write("Error: Your passwords didn't match.\n")
     516                    continue
    514517            if password.strip() == '':
    515518                sys.stderr.write("Error: Blank passwords aren't allowed.\n")
     519                password = None
    516520                continue
    517521            break
    518522    except KeyboardInterrupt:
     
    524528    u.is_superuser = True
    525529    u.save()
    526530    print "User created successfully."
    527 createsuperuser.args = ''
     531createsuperuser.args = '[optional username, email, password]'
    528532
    529533def inspectdb(db_name):
    530534    "Generator that introspects the tables in the given database name and returns a Django model, one line at a time."
Back to Top