Don't _require_ rest_framework_simplejwt

Rather than importing it at the top level (which breaks dj-rest-auth
entirely if you aren't using JWTs and don't have the library installed),
only do the import if the user has the relevant setting enabled.
This commit is contained in:
Rami Chowdhury 2020-04-14 13:26:52 -04:00
parent 40125b15c4
commit 40208ea0b6

View File

@ -11,8 +11,20 @@ from rest_framework.generics import GenericAPIView, RetrieveUpdateAPIView
from rest_framework.permissions import AllowAny, IsAuthenticated from rest_framework.permissions import AllowAny, IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
if getattr(settings, 'REST_USE_JWT'):
from rest_framework_simplejwt.exceptions import TokenError from rest_framework_simplejwt.exceptions import TokenError
from rest_framework_simplejwt.tokens import RefreshToken from rest_framework_simplejwt.tokens import RefreshToken
else:
# NOTE: these are not actually used except if `REST_USE_JWT` is True, but
# ensuring they're defined anyway in case
class TokenError(Exception):
pass
class RefreshToken:
pass
from .app_settings import (JWTSerializer, LoginSerializer, from .app_settings import (JWTSerializer, LoginSerializer,
PasswordChangeSerializer, PasswordChangeSerializer,