Ticket #19745: 19745-2.diff

File 19745-2.diff, 3.5 KB (added by claudep, 2 years ago)
  • django/contrib/auth/management/commands/createsuperuser.py

    diff --git a/django/contrib/auth/management/commands/createsuperuser.py b/django/contrib/auth/management/commands/createsuperuser.py
    index 4169da2..b3cd6f9 100644
    a b from django.contrib.auth.management import get_default_username 
    1111from django.core import exceptions
    1212from django.core.management.base import BaseCommand, CommandError
    1313from django.db import DEFAULT_DB_ALIAS
    14 from django.utils.encoding import force_str
     14from django.utils.encoding import force_str, force_text
    1515from django.utils.six.moves import input
    1616from django.utils.text import capfirst
    1717
    class Command(BaseCommand): 
    8080            try:
    8181
    8282                # Get a username
     83                verbose_field_name = force_text(self.username_field.verbose_name)
    8384                while username is None:
    8485                    if not username:
    85                         input_msg = capfirst(self.username_field.verbose_name)
     86                        input_msg = capfirst(verbose_field_name)
    8687                        if default_username:
    8788                            input_msg = "%s (leave blank to use '%s')" % (
    8889                                input_msg, default_username)
    class Command(BaseCommand): 
    102103                        pass
    103104                    else:
    104105                        self.stderr.write("Error: That %s is already taken." %
    105                                 self.username_field.verbose_name)
     106                                verbose_field_name)
    106107                        username = None
    107108
    108109                for field_name in self.UserModel.REQUIRED_FIELDS:
    109110                    field = self.UserModel._meta.get_field(field_name)
    110111                    user_data[field_name] = options.get(field_name)
    111112                    while user_data[field_name] is None:
    112                         raw_value = input(force_str('%s: ' % capfirst(field.verbose_name)))
     113                        raw_value = input(force_str('%s: ' % capfirst(force_text(field.verbose_name))))
    113114                        try:
    114115                            user_data[field_name] = field.clean(raw_value, None)
    115116                        except exceptions.ValidationError as e:
  • django/contrib/auth/tests/basic.py

    diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py
    index 8627329..6e2b06a 100644
    a b def mock_inputs(inputs): 
    2929            def mock_input(prompt):
    3030                # prompt should be encoded in Python 2. This line will raise an
    3131                # Exception if prompt contains unencoded non-ascii on Python 2.
     32                assert str('__proxy__') not in prompt
    3233                prompt = str(prompt)
    3334                if str('leave blank to use') in prompt:
    3435                    return inputs['username']
    class BasicTestCase(TestCase): 
    180181
    181182    @mock_inputs({'password': "nopasswd", 'username': 'foo'})
    182183    def test_createsuperuser_non_ascii_verbose_name(self):
     184        # Aliased so the string doesn't get extracted
     185        from django.utils.translation import ugettext_lazy as ulazy
    183186        username_field = User._meta.get_field('username')
    184187        old_verbose_name = username_field.verbose_name
    185         username_field.verbose_name = 'uživatel'
     188        username_field.verbose_name = ulazy('uživatel')
    186189        new_io = StringIO()
    187190        try:
    188191            call_command("createsuperuser",
Back to Top