Skip to content

Commit

Permalink
Removes six
Browse files Browse the repository at this point in the history
  • Loading branch information
iMerica committed Mar 1, 2020
1 parent 3402d1f commit a87a458
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 53 deletions.
1 change: 0 additions & 1 deletion demo/requirements.pip
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ django>=1.9.0
dj-rest-auth==0.9.5
djangorestframework>=3.7.0
django-allauth>=0.24.1
six==1.9.0
django-rest-swagger==2.0.7
37 changes: 10 additions & 27 deletions dj_rest_auth/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,27 @@
PasswordResetSerializer as DefaultPasswordResetSerializer,
PasswordResetConfirmSerializer as DefaultPasswordResetConfirmSerializer,
PasswordChangeSerializer as DefaultPasswordChangeSerializer)
from .utils import import_callable, default_create_token
from .utils import default_create_token

create_token = import_callable(
getattr(settings, 'REST_AUTH_TOKEN_CREATOR', default_create_token))
create_token = getattr(settings, 'REST_AUTH_TOKEN_CREATOR', default_create_token)

serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})

TokenSerializer = import_callable(
serializers.get('TOKEN_SERIALIZER', DefaultTokenSerializer))
TokenSerializer = serializers.get('TOKEN_SERIALIZER', DefaultTokenSerializer)

JWTSerializer = import_callable(
serializers.get('JWT_SERIALIZER', DefaultJWTSerializer))
JWTSerializer = serializers.get('JWT_SERIALIZER', DefaultJWTSerializer)

UserDetailsSerializer = import_callable(
serializers.get('USER_DETAILS_SERIALIZER', DefaultUserDetailsSerializer)
)
UserDetailsSerializer = serializers.get('USER_DETAILS_SERIALIZER', DefaultUserDetailsSerializer)

LoginSerializer = import_callable(
serializers.get('LOGIN_SERIALIZER', DefaultLoginSerializer)
)
LoginSerializer = serializers.get('LOGIN_SERIALIZER', DefaultLoginSerializer)

PasswordResetSerializer = import_callable(
serializers.get(
PasswordResetSerializer = serializers.get(
'PASSWORD_RESET_SERIALIZER',
DefaultPasswordResetSerializer
)
)

PasswordResetConfirmSerializer = import_callable(
serializers.get(
'PASSWORD_RESET_CONFIRM_SERIALIZER',
DefaultPasswordResetConfirmSerializer
)
PasswordResetConfirmSerializer = serializers.get(
'PASSWORD_RESET_CONFIRM_SERIALIZER', DefaultPasswordResetConfirmSerializer
)

PasswordChangeSerializer = import_callable(
serializers.get(
'PASSWORD_CHANGE_SERIALIZER',
DefaultPasswordChangeSerializer
)
)
PasswordChangeSerializer = serializers.get('PASSWORD_CHANGE_SERIALIZER', DefaultPasswordChangeSerializer)
4 changes: 1 addition & 3 deletions dj_rest_auth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from rest_framework.authtoken.models import Token as DefaultTokenModel

from .utils import import_callable

# Register your models here.

TokenModel = import_callable(
getattr(settings, 'REST_AUTH_TOKEN_MODEL', DefaultTokenModel))
TokenModel = getattr(settings, 'REST_AUTH_TOKEN_MODEL', DefaultTokenModel)
9 changes: 4 additions & 5 deletions dj_rest_auth/registration/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

from rest_framework.permissions import AllowAny
from rest_auth.registration.serializers import (
RegisterSerializer as DefaultRegisterSerializer)
from ..utils import import_callable
RegisterSerializer as DefaultRegisterSerializer
)


serializers = getattr(settings, 'REST_AUTH_REGISTER_SERIALIZERS', {})

RegisterSerializer = import_callable(
serializers.get('REGISTER_SERIALIZER', DefaultRegisterSerializer))
RegisterSerializer = serializers.get('REGISTER_SERIALIZER', DefaultRegisterSerializer)


def register_permission_classes():
permission_classes = [AllowAny, ]
for klass in getattr(settings, 'REST_AUTH_REGISTER_PERMISSION_CLASSES', tuple()):
permission_classes.append(import_callable(klass))
permission_classes.append(klass)
return tuple(permission_classes)
5 changes: 1 addition & 4 deletions dj_rest_auth/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from rest_framework.exceptions import ValidationError

from .models import TokenModel
from .utils import import_callable

# Get the UserModel
UserModel = get_user_model()
Expand Down Expand Up @@ -146,9 +145,7 @@ def get_user(self, obj):
JWTSerializer. Defining it here to avoid circular imports
"""
rest_auth_serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {})
JWTUserDetailsSerializer = import_callable(
rest_auth_serializers.get('USER_DETAILS_SERIALIZER', UserDetailsSerializer)
)
JWTUserDetailsSerializer = rest_auth_serializers.get('USER_DETAILS_SERIALIZER', UserDetailsSerializer)

This comment has been minimized.

Copy link
@nndnha

nndnha Mar 18, 2020

With a custom USER_DETAILS_SERIALIZER class this change will break the login request with TypeError: 'str' object is not callable error, because JWTUserDetailsSerializer isn't a class but string.

user_data = JWTUserDetailsSerializer(obj['user'], context=self.context).data
return user_data

Expand Down
12 changes: 0 additions & 12 deletions dj_rest_auth/utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
from six import string_types
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, string_types)
package, attr = path_or_callable.rsplit('.', 1)
return getattr(import_module(package), attr)


def default_create_token(token_model, user, serializer):
token, _ = token_model.objects.get_or_create(user=user)
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
install_requires=[
'Django>=1.8.0',
'djangorestframework>=3.1.3',
'six>=1.9.0',
],
extras_require={
'with_social': ['django-allauth>=0.25.0'],
Expand Down

0 comments on commit a87a458

Please sign in to comment.