From: Steven Cummings Date: Sun, 24 Jun 2012 18:17:36 +0000 (-0500) Subject: Move get_user method to specific models backends X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=95f21db0b8e7baaa92cb321b557a10ba5a36533f;p=django-social-auth.git Move get_user method to specific models backends --- diff --git a/social_auth/backends/__init__.py b/social_auth/backends/__init__.py index 59c4751..bb6b3e6 100644 --- a/social_auth/backends/__init__.py +++ b/social_auth/backends/__init__.py @@ -19,13 +19,13 @@ from openid.extensions import sreg, ax from oauth2 import Consumer as OAuthConsumer, Token, Request as OAuthRequest -from django.db import models from django.contrib.auth import authenticate from django.contrib.auth.backends import ModelBackend from django.utils import simplejson from django.utils.importlib import import_module from social_auth.models import get_social_auth_for_user +from social_auth.models import get_user from social_auth.utils import setting, log, model_to_ctype, ctype_to_model, \ clean_partial_pipeline from social_auth.store import DjangoOpenIDStore @@ -36,11 +36,6 @@ from social_auth.backends.exceptions import StopPipeline, AuthException, \ from social_auth.backends.utils import build_consumer_oauth_request -def get_user_model(): - from social_auth.models import User - return User - - # OpenID configuration OLD_AX_ATTRS = [ ('http://schema.openid.net/contact/email', 'old_email'), @@ -195,11 +190,7 @@ class SocialAuthBackend(ModelBackend): """ Return user with given ID from the User model used by this backend """ - user_cls = get_user_model() - try: - return user_cls.objects.get(id=user_id) - except user_cls.DoesNotExist: - return None + return get_user(user_id) class OAuthBackend(SocialAuthBackend): diff --git a/social_auth/django_models.py b/social_auth/django_models.py index 1fce960..34f04f9 100644 --- a/social_auth/django_models.py +++ b/social_auth/django_models.py @@ -45,6 +45,13 @@ def create_user(*args, **kwargs): return User.objects.create_user(*args, **kwargs) +def get_user(user_id): + try: + return User.objects.get(id=user_id) + except User.DoesNotExist: + return None + + def get_social_auth_for_user(user): return user.social_auth.all() diff --git a/social_auth/mongoengine_models.py b/social_auth/mongoengine_models.py index d6b746d..1f12b86 100644 --- a/social_auth/mongoengine_models.py +++ b/social_auth/mongoengine_models.py @@ -53,6 +53,13 @@ def create_user(*args, **kwargs): return User.objects.create(*args, **kwargs) +def get_user(user_id): + try: + return User.objects.get(id=user_id) + except User.DoesNotExist: + return None + + def get_social_auth_for_user(user): return UserSocialAuth.objects(user=user)