mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixes #17327 -- Add --database option to createsuperuser and change password management commands
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17665 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import getpass
|
||||
from optparse import make_option
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from django.contrib.auth.models import User
|
||||
import getpass
|
||||
from django.db import DEFAULT_DB_ALIAS
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--database', action='store', dest='database',
|
||||
default=DEFAULT_DB_ALIAS, help='Nominates a database to query for the user. '
|
||||
'Defaults to the "default" database.'),
|
||||
)
|
||||
help = "Change a user's password for django.contrib.auth."
|
||||
|
||||
requires_model_validation = False
|
||||
@@ -23,11 +32,11 @@ class Command(BaseCommand):
|
||||
username = getpass.getuser()
|
||||
|
||||
try:
|
||||
u = User.objects.get(username=username)
|
||||
u = User.objects.using(options.get('database')).get(username=username)
|
||||
except User.DoesNotExist:
|
||||
raise CommandError("user '%s' does not exist" % username)
|
||||
|
||||
print "Changing password for user '%s'" % u.username
|
||||
self.stdout.write("Changing password for user '%s'\n" % u.username)
|
||||
|
||||
MAX_TRIES = 3
|
||||
count = 0
|
||||
@@ -36,7 +45,7 @@ class Command(BaseCommand):
|
||||
p1 = self._get_pass()
|
||||
p2 = self._get_pass("Password (again): ")
|
||||
if p1 != p2:
|
||||
print "Passwords do not match. Please try again."
|
||||
self.stdout.write("Passwords do not match. Please try again.\n")
|
||||
count = count + 1
|
||||
|
||||
if count == MAX_TRIES:
|
||||
|
||||
Reference in New Issue
Block a user