Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#798 closed task (fixed)

Specifying username, email, and password on as arguments to "django-admin.py createsuperuser"

Reported by: bjorn@… 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)

createsuperuser.patch (3.4 KB ) - added by bjorn@… 19 years ago.
Patch to createsuperuser

Download all attachments as: .zip

Change History (5)

by bjorn@…, 19 years ago

Attachment: createsuperuser.patch added

Patch to createsuperuser

comment:1 by garthk, 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 Adrian Holovaty, 19 years ago

Resolution: fixed
Status: newclosed

(In [1474]) Fixed #798 and #715 -- Added optional arguments to createsuperuser, for each use in shell scripts. Thanks for the patch, bjorn@…

comment:3 by anonymous, 18 years ago

Component: django-admin.pyTranslations
milestone: Version 0.92
priority: normallowest
Severity: normaltrivial
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: enhancementtask
Version: 0.91

comment:4 by Adrian Holovaty, 18 years ago

milestone: Version 0.92

Milestone Version 0.92 deleted

Note: See TracTickets for help on using tickets.
Back to Top