#798 closed task (fixed)
Specifying username, email, and password on as arguments to "django-admin.py createsuperuser"
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Translations | Version: | 0.91 |
Severity: | trivial | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
We're frequently rebuilding the entire Django database environment, and it's a pain to specify the username, email, and password to the createsuperuser command. This patch enable you to specify these on the command line so the process can be completely automated/ done in a batch script.
Index: django/bin/django-admin.py
===================================================================
--- django/bin/django-admin.py (revision 1235)
+++ django/bin/django-admin.py (working copy)
@@ -81,7 +81,7 @@
translation.activate('en-us')
if action in ('createsuperuser', 'init', 'validate'):
- ACTION_MAPPING[action]()
+ ACTION_MAPPING[action](*args[1:])
elif action == 'inspectdb':
try:
param = args[1]
Index: django/core/management.py
===================================================================
--- django/core/management.py (revision 1235)
+++ django/core/management.py (working copy)
@@ -480,39 +480,43 @@
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
+ sys.stderr.write("Error: That username is invalid\n")
+ username = None
try:
users.get_object(usernameexact=username)
except users.UserDoesNotExist:
break
else:
- sys.stderr.write("Error: That username is already taken.\n")
+ 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")
+ 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")
+ continue
if password.strip() == :
sys.stderr.write("Error: Blank passwords aren't allowed.\n")
+ password = None
continue
break
except KeyboardInterrupt:
@@ -524,7 +528,7 @@
u.is_superuser = True
u.save()
print "User created successfully."
-createsuperuser.args =
+createsuperuser.args = '[optional username, email, password]'
def inspectdb(db_name):
"Generator that introspects the tables in the given database name and returns a Django model, one line at a time."
Attachments (1)
Change History (5)
by , 19 years ago
Attachment: | createsuperuser.patch added |
---|
comment:1 by , 19 years ago
It's a little rusty, but miniflush.py demonstrates a slightly different approach: automate the whole thing so you don't have to even run django-admin multiple times.
comment:2 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 18 years ago
Component: | django-admin.py → Translations |
---|---|
milestone: | → Version 0.92 |
priority: | normal → lowest |
Severity: | normal → trivial |
Summary: | Specifying username, email, and password on as arguments to "django-admin.py createsuperuser" → Specifying username, email, and password on as arguments to "django-admin.py createsuperuser" |
Type: | enhancement → task |
Version: | → 0.91 |
Patch to createsuperuser