Merge pull request #129 from ron8mcr/master

raise_exception=True for views
This commit is contained in:
mariodev 2015-11-23 20:55:08 +01:00
commit 52283aed70

View File

@ -44,15 +44,9 @@ class LoginView(GenericAPIView):
self.response_serializer(self.token).data, status=status.HTTP_200_OK
)
def get_error_response(self):
return Response(
self.serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
def post(self, request, *args, **kwargs):
self.serializer = self.get_serializer(data=self.request.data)
if not self.serializer.is_valid():
return self.get_error_response()
self.serializer.is_valid(raise_exception=True)
self.login()
return self.get_response()
@ -112,10 +106,8 @@ class PasswordResetView(GenericAPIView):
def post(self, request, *args, **kwargs):
# Create a serializer with request.data
serializer = self.get_serializer(data=request.data)
serializer.is_valid(raise_exception=True)
if not serializer.is_valid():
return Response(serializer.errors,
status=status.HTTP_400_BAD_REQUEST)
serializer.save()
# Return the success message with OK HTTP status
return Response(
@ -139,10 +131,7 @@ class PasswordResetConfirmView(GenericAPIView):
def post(self, request):
serializer = self.get_serializer(data=request.data)
if not serializer.is_valid():
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response({"success": "Password has been reset with the new password."})
@ -161,9 +150,6 @@ class PasswordChangeView(GenericAPIView):
def post(self, request):
serializer = self.get_serializer(data=request.data)
if not serializer.is_valid():
return Response(
serializer.errors, status=status.HTTP_400_BAD_REQUEST
)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response({"success": "New password has been saved."})