Code

Ticket #19745: 19745-2.diff

File 19745-2.diff, 3.5 KB (added by claudep, 14 months ago)
Line 
1diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
2index 4169da2..b3cd6f9 100644
3--- a/django/contrib/auth/management/commands/createsuperuser.py
4+++ b/django/contrib/auth/management/commands/createsuperuser.py
5@@ -11,7 +11,7 @@ from django.contrib.auth.management import get_default_username
6 from django.core import exceptions
7 from django.core.management.base import BaseCommand, CommandError
8 from django.db import DEFAULT_DB_ALIAS
9-from django.utils.encoding import force_str
10+from django.utils.encoding import force_str, force_text
11 from django.utils.six.moves import input
12 from django.utils.text import capfirst
13 
14@@ -80,9 +80,10 @@ class Command(BaseCommand):
15             try:
16 
17                 # Get a username
18+                verbose_field_name = force_text(self.username_field.verbose_name)
19                 while username is None:
20                     if not username:
21-                        input_msg = capfirst(self.username_field.verbose_name)
22+                        input_msg = capfirst(verbose_field_name)
23                         if default_username:
24                             input_msg = "%s (leave blank to use '%s')" % (
25                                 input_msg, default_username)
26@@ -102,14 +103,14 @@ class Command(BaseCommand):
27                         pass
28                     else:
29                         self.stderr.write("Error: That %s is already taken." %
30-                                self.username_field.verbose_name)
31+                                verbose_field_name)
32                         username = None
33 
34                 for field_name in self.UserModel.REQUIRED_FIELDS:
35                     field = self.UserModel._meta.get_field(field_name)
36                     user_data[field_name] = options.get(field_name)
37                     while user_data[field_name] is None:
38-                        raw_value = input(force_str('%s: ' % capfirst(field.verbose_name)))
39+                        raw_value = input(force_str('%s: ' % capfirst(force_text(field.verbose_name))))
40                         try:
41                             user_data[field_name] = field.clean(raw_value, None)
42                         except exceptions.ValidationError as e:
43diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py
44index 8627329..6e2b06a 100644
45--- a/django/contrib/auth/tests/basic.py
46+++ b/django/contrib/auth/tests/basic.py
47@@ -29,6 +29,7 @@ def mock_inputs(inputs):
48             def mock_input(prompt):
49                 # prompt should be encoded in Python 2. This line will raise an
50                 # Exception if prompt contains unencoded non-ascii on Python 2.
51+                assert str('__proxy__') not in prompt
52                 prompt = str(prompt)
53                 if str('leave blank to use') in prompt:
54                     return inputs['username']
55@@ -180,9 +181,11 @@ class BasicTestCase(TestCase):
56 
57     @mock_inputs({'password': "nopasswd", 'username': 'foo'})
58     def test_createsuperuser_non_ascii_verbose_name(self):
59+        # Aliased so the string doesn't get extracted
60+        from django.utils.translation import ugettext_lazy as ulazy
61         username_field = User._meta.get_field('username')
62         old_verbose_name = username_field.verbose_name
63-        username_field.verbose_name = 'uživatel'
64+        username_field.verbose_name = ulazy('uživatel')
65         new_io = StringIO()
66         try:
67             call_command("createsuperuser",