From 2b5942c4acbe0aa2210b4e4a787235f678570280 Mon Sep 17 00:00:00 2001 From: Mateusz Sikora Date: Wed, 8 Oct 2014 13:19:34 +0200 Subject: [PATCH] custom serializers settings --- rest_auth/app_settings.py | 41 +++++++++++++++++++++++++++++++++++++++ rest_auth/views.py | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 rest_auth/app_settings.py diff --git a/rest_auth/app_settings.py b/rest_auth/app_settings.py new file mode 100644 index 0000000..dda56e0 --- /dev/null +++ b/rest_auth/app_settings.py @@ -0,0 +1,41 @@ +from django.conf import settings + +from rest_auth.serializers import ( + TokenSerializer as DefaultTokenSerializer, + UserDetailsSerializer as DefaultUserDetailsSerializer, + LoginSerializer as DefaultLoginSerializer, + PasswordResetSerializer as DefaultPasswordResetSerializer, + PasswordResetConfirmSerializer as DefaultPasswordResetConfirmSerializer, + PasswordChangeSerializer as DefaultPasswordChangeSerializer) +from allauth.utils import import_callable + + +serializers = getattr(settings, 'REST_AUTH_SERIALIZERS', {}) + +TokenSerializer = import_callable( + serializers.get('TOKEN_SERIALIZER', DefaultTokenSerializer)) + +UserDetailsSerializer = import_callable( + serializers.get('USER_DETAILS_SERIALIZER', DefaultUserDetailsSerializer) +) + +LoginSerializer = import_callable( + serializers.get('LOGIN_SERIALIZER', DefaultLoginSerializer) +) + +PasswordResetSerializer = import_callable( + serializers.get('PASSWORD_RESET_SERIALIZER', + DefaultPasswordResetSerializer) +) + +PasswordResetConfirmSerializer = import_callable( + serializers.get('PASSWORD_RESET_CONFIRM_SERIALIZER', + DefaultPasswordResetConfirmSerializer) +) + +PasswordChangeSerializer = import_callable( + serializers.get('PASSWORD_RESET_SERIALIZER', + DefaultPasswordChangeSerializer) +) + + diff --git a/rest_auth/views.py b/rest_auth/views.py index e814773..c9f2214 100644 --- a/rest_auth/views.py +++ b/rest_auth/views.py @@ -11,7 +11,7 @@ from rest_framework.authentication import SessionAuthentication, \ from rest_framework.authtoken.models import Token from rest_framework.generics import RetrieveUpdateAPIView -from rest_auth.serializers import (TokenSerializer, UserDetailsSerializer, +from app_settings import (TokenSerializer, UserDetailsSerializer, LoginSerializer, PasswordResetSerializer, PasswordResetConfirmSerializer, PasswordChangeSerializer)