Fixes references to serializers + isort

This commit is contained in:
Michael 2020-02-29 23:56:21 -06:00
parent 9b78f0e3be
commit 8bc9ba8c8a
21 changed files with 119 additions and 121 deletions

View File

@ -1,7 +1,6 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
from django.views.generic import TemplateView, RedirectView from django.views.generic import RedirectView, TemplateView
from rest_framework_swagger.views import get_swagger_view from rest_framework_swagger.views import get_swagger_view
urlpatterns = [ urlpatterns = [

View File

@ -8,7 +8,9 @@ https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
""" """
import os import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "demo.settings")
application = get_wsgi_application() application = get_wsgi_application()

View File

@ -1,34 +1,36 @@
from dj_rest_auth.serializers import JWTSerializer as DefaultJWTSerializer
from dj_rest_auth.serializers import LoginSerializer as DefaultLoginSerializer
from dj_rest_auth.serializers import \
PasswordChangeSerializer as DefaultPasswordChangeSerializer
from dj_rest_auth.serializers import \
PasswordResetConfirmSerializer as DefaultPasswordResetConfirmSerializer
from dj_rest_auth.serializers import \
PasswordResetSerializer as DefaultPasswordResetSerializer
from dj_rest_auth.serializers import TokenSerializer as DefaultTokenSerializer
from dj_rest_auth.serializers import \
UserDetailsSerializer as DefaultUserDetailsSerializer
from django.conf import settings from django.conf import settings
from dj_rest_auth.serializers import ( from .utils import default_create_token, import_callable
TokenSerializer as DefaultTokenSerializer,
JWTSerializer as DefaultJWTSerializer,
UserDetailsSerializer as DefaultUserDetailsSerializer,
LoginSerializer as DefaultLoginSerializer,
PasswordResetSerializer as DefaultPasswordResetSerializer,
PasswordResetConfirmSerializer as DefaultPasswordResetConfirmSerializer,
PasswordChangeSerializer as DefaultPasswordChangeSerializer)
from .utils import default_create_token
create_token = getattr(settings, 'REST_AUTH_TOKEN_CREATOR', default_create_token) create_token = import_callable(getattr(settings, 'REST_AUTH_TOKEN_CREATOR', default_create_token))
serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {}) serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})
TokenSerializer = serializers.get('TOKEN_SERIALIZER', DefaultTokenSerializer) TokenSerializer = import_callable(serializers.get('TOKEN_SERIALIZER', DefaultTokenSerializer))
JWTSerializer = serializers.get('JWT_SERIALIZER', DefaultJWTSerializer) JWTSerializer = import_callable(serializers.get('JWT_SERIALIZER', DefaultJWTSerializer))
UserDetailsSerializer = serializers.get('USER_DETAILS_SERIALIZER', DefaultUserDetailsSerializer) UserDetailsSerializer = import_callable(serializers.get('USER_DETAILS_SERIALIZER', DefaultUserDetailsSerializer))
LoginSerializer = serializers.get('LOGIN_SERIALIZER', DefaultLoginSerializer) LoginSerializer = import_callable(serializers.get('LOGIN_SERIALIZER', DefaultLoginSerializer))
PasswordResetSerializer = serializers.get( PasswordResetSerializer = import_callable(serializers.get(
'PASSWORD_RESET_SERIALIZER', 'PASSWORD_RESET_SERIALIZER', DefaultPasswordResetSerializer
DefaultPasswordResetSerializer ))
)
PasswordResetConfirmSerializer = serializers.get( PasswordResetConfirmSerializer = serializers.get(
'PASSWORD_RESET_CONFIRM_SERIALIZER', DefaultPasswordResetConfirmSerializer 'PASSWORD_RESET_CONFIRM_SERIALIZER', DefaultPasswordResetConfirmSerializer
) )
PasswordChangeSerializer = serializers.get('PASSWORD_CHANGE_SERIALIZER', DefaultPasswordChangeSerializer) PasswordChangeSerializer = import_callable(serializers.get('PASSWORD_CHANGE_SERIALIZER', DefaultPasswordChangeSerializer))

View File

@ -1,8 +1,6 @@
from django.conf import settings from django.conf import settings
from rest_framework.authtoken.models import Token as DefaultTokenModel from rest_framework.authtoken.models import Token as DefaultTokenModel
# Register your models here. # Register your models here.
TokenModel = getattr(settings, 'REST_AUTH_TOKEN_MODEL', DefaultTokenModel) TokenModel = getattr(settings, 'REST_AUTH_TOKEN_MODEL', DefaultTokenModel)

View File

@ -1,14 +1,13 @@
from django.conf import settings from dj_rest_auth.registration.serializers import \
from rest_framework.permissions import AllowAny
from dj_rest_auth.registration.serializers import (
RegisterSerializer as DefaultRegisterSerializer RegisterSerializer as DefaultRegisterSerializer
) from django.conf import settings
from rest_framework.permissions import AllowAny
from ..utils import import_callable
serializers = getattr(settings, 'REST_AUTH_REGISTER_SERIALIZERS', {}) serializers = getattr(settings, 'REST_AUTH_REGISTER_SERIALIZERS', {})
RegisterSerializer = serializers.get('REGISTER_SERIALIZER', DefaultRegisterSerializer) RegisterSerializer = import_callable(serializers.get('REGISTER_SERIALIZER', DefaultRegisterSerializer))
def register_permission_classes(): def register_permission_classes():

View File

@ -1,6 +1,8 @@
from django.contrib.auth import get_user_model
from django.http import HttpRequest from django.http import HttpRequest
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib.auth import get_user_model from requests.exceptions import HTTPError
from rest_framework import serializers
try: try:
from allauth.account import app_settings as allauth_settings from allauth.account import app_settings as allauth_settings
@ -14,8 +16,6 @@ try:
except ImportError: except ImportError:
raise ImportError("allauth needs to be added to INSTALLED_APPS.") raise ImportError("allauth needs to be added to INSTALLED_APPS.")
from rest_framework import serializers
from requests.exceptions import HTTPError
class SocialAccountSerializer(serializers.ModelSerializer): class SocialAccountSerializer(serializers.ModelSerializer):

View File

@ -1,5 +1,5 @@
from django.views.generic import TemplateView
from django.conf.urls import url from django.conf.urls import url
from django.views.generic import TemplateView
from .views import RegisterView, VerifyEmailView from .views import RegisterView, VerifyEmailView

View File

@ -1,34 +1,30 @@
from allauth.account import app_settings as allauth_settings
from allauth.account.adapter import get_adapter
from allauth.account.utils import complete_signup
from allauth.account.views import ConfirmEmailView
from allauth.socialaccount import signals
from allauth.socialaccount.adapter import get_adapter as get_social_adapter
from allauth.socialaccount.models import SocialAccount
from dj_rest_auth.app_settings import (JWTSerializer, TokenSerializer,
create_token)
from dj_rest_auth.models import TokenModel
from dj_rest_auth.registration.serializers import (SocialAccountSerializer,
SocialConnectSerializer,
SocialLoginSerializer,
VerifyEmailSerializer)
from dj_rest_auth.utils import jwt_encode
from dj_rest_auth.views import LoginView
from django.conf import settings from django.conf import settings
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import (AllowAny,
IsAuthenticated)
from rest_framework.generics import CreateAPIView, ListAPIView, GenericAPIView
from rest_framework.exceptions import NotFound
from rest_framework import status from rest_framework import status
from rest_framework.exceptions import NotFound
from rest_framework.generics import CreateAPIView, GenericAPIView, ListAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from allauth.account.adapter import get_adapter
from allauth.account.views import ConfirmEmailView
from allauth.account.utils import complete_signup
from allauth.account import app_settings as allauth_settings
from allauth.socialaccount import signals
from allauth.socialaccount.adapter import get_adapter as get_social_adapter
from allauth.socialaccount.models import SocialAccount
from dj_rest_auth.app_settings import (TokenSerializer,
JWTSerializer,
create_token)
from dj_rest_auth.models import TokenModel
from dj_rest_auth.registration.serializers import (VerifyEmailSerializer,
SocialLoginSerializer,
SocialAccountSerializer,
SocialConnectSerializer)
from dj_rest_auth.utils import jwt_encode
from dj_rest_auth.views import LoginView
from .app_settings import RegisterSerializer, register_permission_classes from .app_settings import RegisterSerializer, register_permission_classes
sensitive_post_parameters_m = method_decorator( sensitive_post_parameters_m = method_decorator(

View File

@ -1,12 +1,11 @@
from django.contrib.auth import get_user_model, authenticate
from django.conf import settings from django.conf import settings
from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm from django.contrib.auth.forms import PasswordResetForm, SetPasswordForm
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
from django.utils.encoding import force_text
from django.utils.http import urlsafe_base64_decode as uid_decoder from django.utils.http import urlsafe_base64_decode as uid_decoder
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text from rest_framework import exceptions, serializers
from rest_framework import serializers, exceptions
from rest_framework.exceptions import ValidationError from rest_framework.exceptions import ValidationError
from .models import TokenModel from .models import TokenModel

View File

@ -1,6 +1,7 @@
from django.conf import settings from django.conf import settings
from django.http import HttpRequest from django.http import HttpRequest
from rest_framework import serializers from rest_framework import serializers
# Import is needed only if we are using social login, in which # Import is needed only if we are using social login, in which
# case the allauth.socialaccount will be declared # case the allauth.socialaccount will be declared
if 'allauth.socialaccount' in settings.INSTALLED_APPS: if 'allauth.socialaccount' in settings.INSTALLED_APPS:

View File

@ -1,11 +1,9 @@
import json import json
from django.conf import settings from django.conf import settings
from django.test.client import Client, MULTIPART_CONTENT from django.test.client import MULTIPART_CONTENT, Client
from django.utils.encoding import force_text from django.utils.encoding import force_text
from rest_framework import permissions, status
from rest_framework import status
from rest_framework import permissions
try: try:
from django.urls import reverse from django.urls import reverse

View File

@ -1,6 +1,6 @@
import logging
import os import os
import sys import sys
import logging
PROJECT_ROOT = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0]) PROJECT_ROOT = os.path.abspath(os.path.split(os.path.split(__file__)[0])[0])

View File

@ -1,17 +1,15 @@
from django.test import TestCase, override_settings from allauth.account import app_settings as account_app_settings
from dj_rest_auth.registration.app_settings import register_permission_classes
from dj_rest_auth.registration.views import RegisterView
from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core import mail from django.core import mail
from django.conf import settings from django.test import TestCase, override_settings
from django.utils.encoding import force_text from django.utils.encoding import force_text
from allauth.account import app_settings as account_app_settings
from rest_framework import status from rest_framework import status
from rest_framework.test import APIRequestFactory from rest_framework.test import APIRequestFactory
from dj_rest_auth.registration.views import RegisterView from .mixins import CustomPermissionClass, TestsMixin
from dj_rest_auth.registration.app_settings import register_permission_classes
from .mixins import TestsMixin, CustomPermissionClass
try: try:
from django.urls import reverse from django.urls import reverse

View File

@ -1,22 +1,23 @@
import json import json
from django.test import TestCase import responses
from allauth.socialaccount.models import SocialApp
from allauth.socialaccount.providers.facebook.provider import GRAPH_API_URL
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.test.utils import override_settings
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.test import TestCase
from django.test.utils import override_settings
from rest_framework import status
from .mixins import TestsMixin
try: try:
from django.urls import reverse from django.urls import reverse
except ImportError: except ImportError:
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from allauth.socialaccount.models import SocialApp
from allauth.socialaccount.providers.facebook.provider import GRAPH_API_URL
import responses
from rest_framework import status
from .mixins import TestsMixin
@override_settings(ROOT_URLCONF="tests.urls") @override_settings(ROOT_URLCONF="tests.urls")

View File

@ -1,20 +1,18 @@
from django.conf.urls import url, include from allauth.socialaccount.providers.facebook.views import \
from django.views.generic import TemplateView FacebookOAuth2Adapter
from . import django_urls
from allauth.socialaccount.providers.facebook.views import FacebookOAuth2Adapter
from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter from allauth.socialaccount.providers.twitter.views import TwitterOAuthAdapter
from dj_rest_auth.registration.views import (SocialAccountDisconnectView,
SocialAccountListView,
SocialConnectView,
SocialLoginView)
from dj_rest_auth.social_serializers import (TwitterConnectSerializer,
TwitterLoginSerializer)
from dj_rest_auth.urls import urlpatterns
from django.conf.urls import include, url
from django.views.generic import TemplateView
from rest_framework.decorators import api_view from rest_framework.decorators import api_view
from dj_rest_auth.urls import urlpatterns from . import django_urls
from dj_rest_auth.registration.views import (
SocialLoginView, SocialConnectView, SocialAccountListView,
SocialAccountDisconnectView
)
from dj_rest_auth.social_serializers import (
TwitterLoginSerializer, TwitterConnectSerializer
)
class FacebookLogin(SocialLoginView): class FacebookLogin(SocialLoginView):

View File

@ -1,10 +1,8 @@
from dj_rest_auth.views import (LoginView, LogoutView, PasswordChangeView,
PasswordResetConfirmView, PasswordResetView,
UserDetailsView)
from django.conf.urls import url from django.conf.urls import url
from dj_rest_auth.views import (
LoginView, LogoutView, UserDetailsView, PasswordChangeView,
PasswordResetView, PasswordResetConfirmView
)
urlpatterns = [ urlpatterns = [
# URLs that do not require a session or valid token # URLs that do not require a session or valid token
url(r'^password/reset/$', PasswordResetView.as_view(), url(r'^password/reset/$', PasswordResetView.as_view(),

View File

@ -1,3 +1,14 @@
from importlib import import_module
def import_callable(path_or_callable):
if hasattr(path_or_callable, '__call__'):
return path_or_callable
else:
assert isinstance(path_or_callable, str)
package, attr = path_or_callable.rsplit('.', 1)
return getattr(import_module(package), attr)
def default_create_token(token_model, user, serializer): def default_create_token(token_model, user, serializer):
token, _ = token_model.objects.get_or_create(user=user) token, _ = token_model.objects.get_or_create(user=user)

View File

@ -1,25 +1,22 @@
from django.contrib.auth import (
login as django_login,
logout as django_logout
)
from django.conf import settings from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth import login as django_login
from django.contrib.auth import logout as django_logout
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.decorators.debug import sensitive_post_parameters from django.views.decorators.debug import sensitive_post_parameters
from rest_framework import status from rest_framework import status
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
from rest_framework.permissions import IsAuthenticated, AllowAny from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response
from rest_framework.views import APIView
from .app_settings import ( from .app_settings import (JWTSerializer, LoginSerializer,
TokenSerializer, UserDetailsSerializer, LoginSerializer, PasswordChangeSerializer,
PasswordResetSerializer, PasswordResetConfirmSerializer, PasswordResetConfirmSerializer,
PasswordChangeSerializer, JWTSerializer, create_token PasswordResetSerializer, TokenSerializer,
) UserDetailsSerializer, create_token)
from .models import TokenModel from .models import TokenModel
from .utils import jwt_encode from .utils import jwt_encode

View File

@ -12,8 +12,8 @@
# All configuration values have a default; values that are commented out # All configuration values have a default; values that are commented out
# serve to show the default. # serve to show the default.
import sys
import os import os
import sys
# If extensions (or modules to document with autodoc) are in another directory, # If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the # add these directories to sys.path here. If the directory is relative to the

View File

@ -3,13 +3,14 @@
import os import os
import sys import sys
import django
from django.conf import settings
from django.test.utils import get_runner
os.environ['DJANGO_SETTINGS_MODULE'] = 'dj_rest_auth.tests.settings' os.environ['DJANGO_SETTINGS_MODULE'] = 'dj_rest_auth.tests.settings'
test_dir = os.path.join(os.path.dirname(__file__), 'dj_rest_auth') test_dir = os.path.join(os.path.dirname(__file__), 'dj_rest_auth')
sys.path.insert(0, test_dir) sys.path.insert(0, test_dir)
import django
from django.test.utils import get_runner
from django.conf import settings
def runtests(): def runtests():

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python #!/usr/bin/env python
import os import os
from setuptools import setup, find_packages
from setuptools import find_packages, setup
here = os.path.dirname(os.path.abspath(__file__)) here = os.path.dirname(os.path.abspath(__file__))
f = open(os.path.join(here, 'README.md')) f = open(os.path.join(here, 'README.md'))
@ -12,7 +12,7 @@ f.close()
setup( setup(
name='dj-rest-auth', name='dj-rest-auth',
version='0.1.2', version='0.1.3',
author='iMerica', author='iMerica',
author_email='imichael@pm.me', author_email='imichael@pm.me',
url='http://github.com/iMerica/dj-rest-auth', url='http://github.com/iMerica/dj-rest-auth',