Refactored common 'get' pattern into manager method.

This commit is contained in:
Russell Keith-Magee 2012-09-16 13:46:10 +08:00
parent b441a6bbc7
commit 52a02f1110
1 changed files with 2 additions and 6 deletions

View File

@ -13,9 +13,7 @@ class ModelBackend(object):
def authenticate(self, username=None, password=None): def authenticate(self, username=None, password=None):
try: try:
UserModel = get_user_model() UserModel = get_user_model()
user = UserModel.objects.get(**{ user = UserModel.objects.get_by_natural_key(username)
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
})
if user.check_password(password): if user.check_password(password):
return user return user
except UserModel.DoesNotExist: except UserModel.DoesNotExist:
@ -111,9 +109,7 @@ class RemoteUserBackend(ModelBackend):
user = self.configure_user(user) user = self.configure_user(user)
else: else:
try: try:
user = UserModel.objects.get(**{ user = UserModel.objects.get_by_natural_key(username)
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
})
except UserModel.DoesNotExist: except UserModel.DoesNotExist:
pass pass
return user return user