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):
try:
UserModel = get_user_model()
user = UserModel.objects.get(**{
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
})
user = UserModel.objects.get_by_natural_key(username)
if user.check_password(password):
return user
except UserModel.DoesNotExist:
@ -111,9 +109,7 @@ class RemoteUserBackend(ModelBackend):
user = self.configure_user(user)
else:
try:
user = UserModel.objects.get(**{
getattr(UserModel, 'USERNAME_FIELD', 'username'): username
})
user = UserModel.objects.get_by_natural_key(username)
except UserModel.DoesNotExist:
pass
return user