Ticket #7259: 1.diff

File 1.diff, 1.3 KB (added by leotr, 16 years ago)
  • django/contrib/admin/views/decorators.py

     
    8484            message = ERROR_MESSAGE
    8585            if '@' in username:
    8686                # Mistakenly entered e-mail address instead of username? Look it up.
    87                 users = list(User.objects.filter(email=username))
    88                 if len(users) == 1:
    89                     message = _("Your e-mail address is not your username. Try '%s' instead.") % users[0].username
    90                 else:
     87                try:
     88                    user = User.objects.get(email=username)
     89                except (User.DoesNotExist, User.MultipleObjectsReturned):
    9190                    # Either we cannot find the user, or if more than 1
    9291                    # we cannot guess which user is the correct one.
    9392                    message = _("Usernames cannot contain the '@' character.")
     93                else:
     94                    message = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
    9495            return _display_login_form(request, message)
    9596
    9697        # The user data is correct; log in the user in and continue.
Back to Top