make IS_TEST not required, enhancement in Login view

This commit is contained in:
Mateusz Sikora 2014-05-30 11:17:25 +02:00
parent 7825890462
commit 44e0f33b25
2 changed files with 5 additions and 10 deletions

View File

@ -27,13 +27,6 @@ urlpatterns = patterns('rest_auth.views',
name='rest_password_change'),
)
if settings.DEBUG and not settings.IS_TEST:
urlpatterns += patterns('',
# Swagger Docs
url(r'^docs/',
include('rest_framework_swagger.urls')),
)
if settings.IS_TEST:
if getattr(settings, 'IS_TEST', False):
from django.contrib.auth.tests import urls
urlpatterns += patterns('', url(r'^test-admin/', include(urls)))

View File

@ -68,6 +68,8 @@ class Login(LoggedOutRESTAPIView, GenericAPIView):
"""
serializer_class = LoginSerializer
token_model = Token
token_serializer = TokenSerializer
def post(self, request):
# Create a serializer with request.DATA
@ -86,8 +88,8 @@ class Login(LoggedOutRESTAPIView, GenericAPIView):
login(request, user)
# Return REST Token object with OK HTTP status
token, created = Token.objects.get_or_create(user=user)
return Response(TokenSerializer(token).data,
token, created = self.token_model.objects.get_or_create(user=user)
return Response(self.token_serializer(token).data,
status=status.HTTP_200_OK)
else:
return Response({'error': 'This account is disabled.'},