Django

Code

Ticket #798 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

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

Reported by: bjorn@exoweb.net Assigned to: adrian
Milestone: Component: Translations
Version: 0.91 Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

createsuperuser.patch (3.4 kB) - added by bjorn@exoweb.net on 11/14/05 21:53:59.
Patch to createsuperuser

Change History

11/14/05 21:53:59 changed by bjorn@exoweb.net

  • attachment createsuperuser.patch added.

Patch to createsuperuser

11/15/05 04:52:11 changed by garthk

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.

11/27/05 20:57:39 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

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

07/03/06 02:11:38 changed by anonymous

  • severity changed from normal to trivial.
  • component changed from django-admin.py to Translations.
  • summary changed from Specifying username, email, and password on as arguments to "django-admin.py createsuperuser" to Specifying username, email, and password on as arguments to "django-admin.py createsuperuser".
  • priority changed from normal to lowest.
  • version set to 0.91.
  • milestone set to Version 0.92.
  • type changed from enhancement to task.

10/24/06 15:17:23 changed by adrian

  • milestone deleted.

Milestone Version 0.92 deleted


Add/Change #798 (Specifying username, email, and password on as arguments to "django-admin.py createsuperuser")




Change Properties
Action