Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #19745 -- Forced resolution of verbose names in createsupersuser

Thanks Baptiste Mispelon for the report and Preston Holmes for the review.
  • Loading branch information...
commit 2390fe3f4f8f52e24157d79b0c60247207c9716f 1 parent ea425eb
Claude Paroz claudep authored
9 django/contrib/auth/management/commands/createsuperuser.py
View
@@ -11,7 +11,7 @@
from django.core import exceptions
from django.core.management.base import BaseCommand, CommandError
from django.db import DEFAULT_DB_ALIAS
-from django.utils.encoding import force_str
+from django.utils.encoding import force_str, force_text
from django.utils.six.moves import input
from django.utils.text import capfirst
@@ -80,9 +80,10 @@ def handle(self, *args, **options):
try:
# Get a username
+ verbose_field_name = force_text(self.username_field.verbose_name)
while username is None:
if not username:
- input_msg = capfirst(self.username_field.verbose_name)
+ input_msg = capfirst(verbose_field_name)
if default_username:
input_msg = "%s (leave blank to use '%s')" % (
input_msg, default_username)
@@ -102,14 +103,14 @@ def handle(self, *args, **options):
pass
else:
self.stderr.write("Error: That %s is already taken." %
- self.username_field.verbose_name)
+ verbose_field_name)
username = None
for field_name in self.UserModel.REQUIRED_FIELDS:
field = self.UserModel._meta.get_field(field_name)
user_data[field_name] = options.get(field_name)
while user_data[field_name] is None:
- raw_value = input(force_str('%s: ' % capfirst(field.verbose_name)))
+ raw_value = input(force_str('%s: ' % capfirst(force_text(field.verbose_name))))
try:
user_data[field_name] = field.clean(raw_value, None)
except exceptions.ValidationError as e:
20 django/contrib/auth/tests/basic.py
View
@@ -12,6 +12,7 @@
from django.core.management import call_command
from django.test import TestCase
from django.test.utils import override_settings
+from django.utils.encoding import force_str
from django.utils.six import StringIO
@@ -30,8 +31,13 @@ def mock_input(prompt):
# prompt should be encoded in Python 2. This line will raise an
# Exception if prompt contains unencoded non-ascii on Python 2.
prompt = str(prompt)
- if str('leave blank to use') in prompt:
- return inputs['username']
+ assert str('__proxy__') not in prompt
+ response = ''
+ for key, val in inputs.items():
+ if force_str(key) in prompt.lower():
+ response = val
+ break
+ return response
old_getpass = createsuperuser.getpass
old_input = createsuperuser.input
@@ -178,16 +184,20 @@ def test_createsuperuser_nolocale(self):
u = User.objects.get(username="nolocale@somewhere.org")
self.assertEqual(u.email, 'nolocale@somewhere.org')
- @mock_inputs({'password': "nopasswd", 'username': 'foo'})
+ @mock_inputs({
+ 'password': "nopasswd",
+ 'uživatel': 'foo', # username (cz)
+ 'email': 'nolocale@somewhere.org'})
def test_createsuperuser_non_ascii_verbose_name(self):
+ # Aliased so the string doesn't get extracted
+ from django.utils.translation import ugettext_lazy as ulazy
username_field = User._meta.get_field('username')
old_verbose_name = username_field.verbose_name
- username_field.verbose_name = 'uživatel'
+ username_field.verbose_name = ulazy('uživatel')
new_io = StringIO()
try:
call_command("createsuperuser",
interactive=True,
- email="nolocale@somewhere.org",
stdout=new_io
)
finally:
Please sign in to comment.
Something went wrong with that request. Please try again.