From 6051a5ae3a4250327b03ebc22cf562118b3fb218 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 31 May 2020 16:06:59 +0300 Subject: [PATCH] Signup: use the recommended drf style for validation. --- django_etesync/views.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/django_etesync/views.py b/django_etesync/views.py index 7864c6a..52d3531 100644 --- a/django_etesync/views.py +++ b/django_etesync/views.py @@ -573,13 +573,11 @@ class AuthenticationViewSet(viewsets.ViewSet): @action_decorator(detail=False, methods=['POST']) def signup(self, request): serializer = AuthenticationSignupSerializer(data=request.data) - if serializer.is_valid(): - user = serializer.save() - - data = self.login_response_data(user) - return Response(data, status=status.HTTP_201_CREATED) + serializer.is_valid(raise_exception=True) + user = serializer.save() - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + data = self.login_response_data(user) + return Response(data, status=status.HTTP_201_CREATED) def get_login_user(self, serializer): username = serializer.validated_data.get('username')