Code

Ticket #7259: 1.diff

File 1.diff, 1.3 KB (added by leotr, 6 years ago)
Line 
1Index: django/contrib/admin/views/decorators.py
2===================================================================
3--- django/contrib/admin/views/decorators.py    (revision 7540)
4+++ django/contrib/admin/views/decorators.py    (working copy)
5@@ -84,13 +84,14 @@
6             message = ERROR_MESSAGE
7             if '@' in username:
8                 # Mistakenly entered e-mail address instead of username? Look it up.
9-                users = list(User.objects.filter(email=username))
10-                if len(users) == 1:
11-                    message = _("Your e-mail address is not your username. Try '%s' instead.") % users[0].username
12-                else:
13+                try:
14+                    user = User.objects.get(email=username)
15+                except (User.DoesNotExist, User.MultipleObjectsReturned):
16                     # Either we cannot find the user, or if more than 1
17                     # we cannot guess which user is the correct one.
18                     message = _("Usernames cannot contain the '@' character.")
19+                else:
20+                    message = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
21             return _display_login_form(request, message)
22 
23         # The user data is correct; log in the user in and continue.