Code

Ticket #7249: 1.diff

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