Django

Code

Changeset 1474

Show
Ignore:
Timestamp:
11/27/05 20:57:38 (4 years ago)
Author:
adrian
Message:

Fixed #798 and #715 -- Added optional arguments to createsuperuser, for each use in shell scripts. Thanks for the patch, bjorn@exoweb.net

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/bin/django-admin.py

    r1185 r1474  
    8181        translation.activate('en-us') 
    8282 
    83     if action in ('createsuperuser', 'init', 'validate'): 
     83    if action == 'createsuperuser': 
     84        try: 
     85            username, email, password = args[1], args[2], args[3] 
     86        except IndexError: 
     87            sys.stderr.write("Error: %r requires arguments of 'username email password' or no argument at all.\n") 
     88            sys.exit(1) 
     89        ACTION_MAPPING[action](username, email, password) 
     90    elif action in ('init', 'validate'): 
    8491        ACTION_MAPPING[action]() 
    8592    elif action == 'inspectdb': 
  • django/trunk/django/core/management.py

    r1434 r1474  
    482482startapp.args = "[appname]" 
    483483 
    484 def createsuperuser(): 
     484def createsuperuser(username=None, email=None, password=None): 
    485485    "Creates a superuser account." 
    486486    from django.core import validators 
     
    489489    try: 
    490490        while 1: 
    491             username = raw_input('Username (only letters, digits and underscores): ') 
     491            if not username: 
     492                username = raw_input('Username (only letters, digits and underscores): ') 
    492493            if not username.isalnum(): 
    493494                sys.stderr.write("Error: That username is invalid.\n") 
    494                 continu
     495                username = Non
    495496            try: 
    496497                users.get_object(username__exact=username) 
     
    499500            else: 
    500501                sys.stderr.write("Error: That username is already taken.\n") 
     502                username = None 
    501503        while 1: 
    502             email = raw_input('E-mail address: ') 
     504            if not email: 
     505                email = raw_input('E-mail address: ') 
    503506            try: 
    504507                validators.isValidEmail(email, None) 
    505508            except validators.ValidationError: 
    506509                sys.stderr.write("Error: That e-mail address is invalid.\n") 
     510                email = None 
    507511            else: 
    508512                break 
    509513        while 1: 
    510             password = getpass.getpass() 
    511             password2 = getpass.getpass('Password (again): ') 
    512             if password != password2: 
    513                 sys.stderr.write("Error: Your passwords didn't match.\n") 
    514                 continue 
     514            if not password: 
     515                password = getpass.getpass() 
     516                password2 = getpass.getpass('Password (again): ') 
     517                if password != password2: 
     518                    sys.stderr.write("Error: Your passwords didn't match.\n") 
     519                    password = None 
     520                    continue 
    515521            if password.strip() == '': 
    516522                sys.stderr.write("Error: Blank passwords aren't allowed.\n") 
     523                password = None 
    517524                continue 
    518525            break 
     
    526533    u.save() 
    527534    print "User created successfully." 
    528 createsuperuser.args = '
     535createsuperuser.args = '[username] [email] [password] (Either all or none)
    529536 
    530537def inspectdb(db_name): 
  • django/trunk/docs/django-admin.txt

    r1107 r1474  
    5555address and password. 
    5656 
     57**New in Django development version:** You can specify 
     58``username email password`` on the command line, for convenient use in shell 
     59scripts. Example:: 
     60 
     61    django-admin.py createsuperuser john john@example.com mypassword 
     62 
    5763init 
    5864----