some pep cleaning

This commit is contained in:
Philippe Luickx 2015-04-12 20:20:01 +03:00
parent f9f9d5605f
commit 8e9ddd9849

View File

@ -9,9 +9,14 @@ from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from rest_framework.generics import RetrieveUpdateAPIView from rest_framework.generics import RetrieveUpdateAPIView
from .app_settings import (TokenSerializer, UserDetailsSerializer, from .app_settings import (
LoginSerializer, PasswordResetSerializer, PasswordResetConfirmSerializer, TokenSerializer,
PasswordChangeSerializer) UserDetailsSerializer,
LoginSerializer,
PasswordResetSerializer,
PasswordResetConfirmSerializer,
PasswordChangeSerializer,
)
class Login(GenericAPIView): class Login(GenericAPIView):
@ -38,12 +43,16 @@ class Login(GenericAPIView):
login(self.request, self.user) login(self.request, self.user)
def get_response(self): def get_response(self):
return Response(self.response_serializer(self.token).data, return Response(
status=status.HTTP_200_OK) self.response_serializer(self.token).data,
status=status.HTTP_200_OK
)
def get_error_response(self): def get_error_response(self):
return Response(self.serializer.errors, return Response(
status=status.HTTP_400_BAD_REQUEST) self.serializer.errors,
status=status.HTTP_400_BAD_REQUEST
)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
self.serializer = self.get_serializer(data=self.request.DATA) self.serializer = self.get_serializer(data=self.request.DATA)
@ -71,8 +80,10 @@ class Logout(APIView):
logout(request) logout(request)
return Response({"success": "Successfully logged out."}, return Response(
status=status.HTTP_200_OK) {"success": "Successfully logged out."},
status=status.HTTP_200_OK
)
class UserDetails(RetrieveUpdateAPIView): class UserDetails(RetrieveUpdateAPIView):
@ -114,14 +125,17 @@ class PasswordReset(GenericAPIView):
status=status.HTTP_400_BAD_REQUEST) status=status.HTTP_400_BAD_REQUEST)
serializer.save() serializer.save()
# Return the success message with OK HTTP status # Return the success message with OK HTTP status
return Response({"success": "Password reset e-mail has been sent."}, return Response(
status=status.HTTP_200_OK) {"success": "Password reset e-mail has been sent."},
status=status.HTTP_200_OK
)
class PasswordResetConfirm(GenericAPIView): class PasswordResetConfirm(GenericAPIView):
""" """
Password reset e-mail link is confirmed, therefore this resets the user's password. Password reset e-mail link is confirmed,
therefore this resets the user's password.
Accepts the following POST parameters: new_password1, new_password2 Accepts the following POST parameters: new_password1, new_password2
Accepts the following Django URL arguments: token, uid Accepts the following Django URL arguments: token, uid
@ -134,10 +148,14 @@ class PasswordResetConfirm(GenericAPIView):
def post(self, request): def post(self, request):
serializer = self.get_serializer(data=request.DATA) serializer = self.get_serializer(data=request.DATA)
if not serializer.is_valid(): if not serializer.is_valid():
return Response(serializer.errors, return Response(
status=status.HTTP_400_BAD_REQUEST) serializer.errors,
status=status.HTTP_400_BAD_REQUEST
)
serializer.save() serializer.save()
return Response({"success": "Password has been reset with the new password."}) return Response(
{"success": "Password has been reset with the new password."}
)
class PasswordChange(GenericAPIView): class PasswordChange(GenericAPIView):
@ -155,7 +173,11 @@ class PasswordChange(GenericAPIView):
def post(self, request): def post(self, request):
serializer = self.get_serializer(data=request.DATA) serializer = self.get_serializer(data=request.DATA)
if not serializer.is_valid(): if not serializer.is_valid():
return Response(serializer.errors, return Response(
status=status.HTTP_400_BAD_REQUEST) serializer.errors,
status=status.HTTP_400_BAD_REQUEST
)
serializer.save() serializer.save()
return Response({"success": "New password has been saved."}) return Response(
{"success": "New password has been saved."}
)