diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-11-28 02:57:38 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-11-28 02:57:38 +0000 |
| commit | e85b071e47a8b25d47d7dfbb3b006030a1d09d87 (patch) | |
| tree | 8cc51dd6c16ed835b44643f0ce0035d5e90a466b | |
| parent | 5de6fe1b2d5afb0a210f3aa52fd21ad3e4f8a8f8 (diff) | |
Fixed #798 and #715 -- Added optional arguments to createsuperuser, for each use in shell scripts. Thanks for the patch, bjorn@exoweb.net
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1474 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rwxr-xr-x | django/bin/django-admin.py | 9 | ||||
| -rw-r--r-- | django/core/management.py | 27 | ||||
| -rw-r--r-- | docs/django-admin.txt | 6 |
3 files changed, 31 insertions, 11 deletions
diff --git a/django/bin/django-admin.py b/django/bin/django-admin.py index e08eeccb70..38c3fe2c83 100755 --- a/django/bin/django-admin.py +++ b/django/bin/django-admin.py @@ -80,7 +80,14 @@ def main(): from django.utils import translation translation.activate('en-us') - if action in ('createsuperuser', 'init', 'validate'): + if action == 'createsuperuser': + try: + username, email, password = args[1], args[2], args[3] + except IndexError: + sys.stderr.write("Error: %r requires arguments of 'username email password' or no argument at all.\n") + sys.exit(1) + ACTION_MAPPING[action](username, email, password) + elif action in ('init', 'validate'): ACTION_MAPPING[action]() elif action == 'inspectdb': try: diff --git a/django/core/management.py b/django/core/management.py index d34ee6fc4d..1062ebecb5 100644 --- a/django/core/management.py +++ b/django/core/management.py @@ -481,39 +481,46 @@ def startapp(app_name, directory): startapp.help_doc = "Creates a Django app directory structure for the given app name in the current directory." startapp.args = "[appname]" -def createsuperuser(): +def createsuperuser(username=None, email=None, password=None): "Creates a superuser account." from django.core import validators from django.models.auth import users import getpass try: while 1: - username = raw_input('Username (only letters, digits and underscores): ') + if not username: + username = raw_input('Username (only letters, digits and underscores): ') if not username.isalnum(): sys.stderr.write("Error: That username is invalid.\n") - continue + username = None try: users.get_object(username__exact=username) except users.UserDoesNotExist: break else: sys.stderr.write("Error: That username is already taken.\n") + username = None while 1: - email = raw_input('E-mail address: ') + if not email: + email = raw_input('E-mail address: ') try: validators.isValidEmail(email, None) except validators.ValidationError: sys.stderr.write("Error: That e-mail address is invalid.\n") + email = None else: break while 1: - password = getpass.getpass() - password2 = getpass.getpass('Password (again): ') - if password != password2: - sys.stderr.write("Error: Your passwords didn't match.\n") - continue + if not password: + password = getpass.getpass() + password2 = getpass.getpass('Password (again): ') + if password != password2: + sys.stderr.write("Error: Your passwords didn't match.\n") + password = None + continue if password.strip() == '': sys.stderr.write("Error: Blank passwords aren't allowed.\n") + password = None continue break except KeyboardInterrupt: @@ -525,7 +532,7 @@ def createsuperuser(): u.is_superuser = True u.save() print "User created successfully." -createsuperuser.args = '' +createsuperuser.args = '[username] [email] [password] (Either all or none)' def inspectdb(db_name): "Generator that introspects the tables in the given database name and returns a Django model, one line at a time." diff --git a/docs/django-admin.txt b/docs/django-admin.txt index a7a15f2a2e..a8dff6defa 100644 --- a/docs/django-admin.txt +++ b/docs/django-admin.txt @@ -54,6 +54,12 @@ createsuperuser Creates a superuser account interactively. It asks you for a username, e-mail address and password. +**New in Django development version:** You can specify +``username email password`` on the command line, for convenient use in shell +scripts. Example:: + + django-admin.py createsuperuser john john@example.com mypassword + init ---- |
