當前位置: 首頁>>代碼示例>>Python>>正文


Python UserSerializer.is_valid方法代碼示例

本文整理匯總了Python中users.serializers.UserSerializer.is_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python UserSerializer.is_valid方法的具體用法?Python UserSerializer.is_valid怎麽用?Python UserSerializer.is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在users.serializers.UserSerializer的用法示例。


在下文中一共展示了UserSerializer.is_valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def post(self, request):
     serializer = UserSerializer(data=request.data) #en rest framework los datos que se envían están en data, y no en POST
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
開發者ID:Eucrow,項目名稱:kc-front-end-ninja-practica,代碼行數:9,代碼來源:api.py

示例2: put

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def put(self, request, userid):
     user = self.get_user(userid)
     serializer = UserSerializer(user, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(status=status.HTTP_200_OK)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:sarasafavi,項目名稱:usersapi,代碼行數:9,代碼來源:views.py

示例3: put

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
    def put(self, request, format=None):
        my_profile = request.user.get_profile()

        # User should be able to edit first_name, last_name, email here
        # TODO: Make sure this is safe as we are making two calls to serialize the request
        user_serializer = UserSerializer(
            request.user,
            data=request.DATA,
            partial=True
        )

        if not user_serializer.is_valid():
            return errors.New400BadRequest(user_serializer.errors)
        user_serializer.save()

        serializer = ProfileSerializer(
            my_profile,
            data=request.DATA,
            partial=True
        )
        print serializer.errors
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_200_OK)
        return errors.New400BadRequest(serializer.errors)
開發者ID:mlp5ab,項目名稱:DrinkUp,代碼行數:27,代碼來源:views.py

示例4: post

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
    def post(self, request, format=None):
        request_data = request.data
        client_data = request_data["client"]
        try:
            client = Client.objects.get(user__email=client_data["user"]["email"])
            user_serializer = UserSerializer(client.user, data=client_data["user"])
        except Client.DoesNotExist:
            client = None
            user_serializer = UserSerializer(data=client_data["user"])
        # Update information for user.
        if user_serializer.is_valid():
            user_serializer.save()
        else: 
            return Response(user_serializer.errors)
        del client_data["user"]
        client_data["user_id"] = user_serializer.instance.id
        # Update information for client.
        if client:
            serializer = ClientSerializer(client, data=client_data)
        else:
            serializer = ClientSerializer(data=client_data)

        if serializer.is_valid():
            serializer.save()
            # Add this client to the provision table.
            users_db_utils.add_to_client_provision(
                serializer.instance.id)
            return Response(serializer.data,
                status=status.HTTP_201_CREATED)
        return Response(serializer.errors)
開發者ID:lasoren,項目名稱:ice-dam-drone,代碼行數:32,代碼來源:views.py

示例5: post

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def post(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         new_user = serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:a-rodriguez296,項目名稱:Django-Tutorial,代碼行數:9,代碼來源:api.py

示例6: create

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def create(self, req):
     serializer = UserSerializer(data=req.data, context={'request': req})
     if serializer.is_valid():
         new_user = serializer.save()
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:krainet,項目名稱:Wordplease,代碼行數:9,代碼來源:api.py

示例7: create

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def create(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         new_user = serializer.save()
         send_mail(u"Bienvenido!", u"Bienvenido a Frikr!", "[email protected]", [new_user.email], fail_silently=True)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:frisinacho,項目名稱:Frikr,代碼行數:10,代碼來源:api.py

示例8: update

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def update(self, request, pk):
     user = get_object_or_404(User, pk=pk)
     # Paso al serializados que instancia y con que la tiene que actualizar.
     serializer = UserSerializer(instance=user, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:walnow78,項目名稱:wordplese,代碼行數:11,代碼來源:api.py

示例9: update

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def update(self, request, pk):
     user = get_object_or_404(User, pk=pk)
     self.check_object_permissions(request, user) # compruebo si el usuario autenticado puede hacer PUT en este user
     serializer = UserSerializer(instance=user, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:mvelezserrano,項目名稱:wordplease,代碼行數:11,代碼來源:api.py

示例10: update

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def update(self, req, pk):
     user = get_object_or_404(User, pk=pk)
     self.check_object_permissions(req, user)  # permisos a mano
     serializer = UserSerializer(instance=user, data=req.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_404_NOT_FOUND)
開發者ID:krainet,項目名稱:Wordplease,代碼行數:11,代碼來源:api.py

示例11: put

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def put(self, request, pk):
     user = get_object_or_404(User, pk=pk)
     self.check_object_permissions(request, user)
     serializer = UserSerializer(User, request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.data, status=status.HTTP_400_BAD_REQUEST)
開發者ID:a-rodriguez296,項目名稱:Django-Tutorial,代碼行數:11,代碼來源:api.py

示例12: create

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def create(self, request):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         new_user = serializer.save()
         # Devolvemos los datos después de crear el recurso, es como un acuse de recibo.
         # no todas las apis devuelven los datos.
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:mvelezserrano,項目名稱:wordplease,代碼行數:11,代碼來源:api.py

示例13: put

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def put(self, request, pk):
     user = get_object_or_404(User, pk=pk)
     self.check_object_permissions(request, user)  # llama a has_object_permission
     serializer = UserSerializer(user, data=request.data)
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=HTTP_202_ACCEPTED)
     else:
         return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
開發者ID:Eucrow,項目名稱:kc-front-end-ninja-practica,代碼行數:11,代碼來源:api.py

示例14: update

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def update(self, request, pk):
     self.check_permissions(request)
     user = get_object_or_404(User, pk=pk)
     self.check_object_permissions(request, user)
     serializer = UserSerializer(instance=user, data=request.data) #Serializa este usuario con data datos
     if serializer.is_valid():
         serializer.save()
         return Response(serializer.data, status=status.HTTP_200_OK)
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
開發者ID:lbarrous,項目名稱:Frikr,代碼行數:12,代碼來源:api.py

示例15: put

# 需要導入模塊: from users.serializers import UserSerializer [as 別名]
# 或者: from users.serializers.UserSerializer import is_valid [as 別名]
 def put(self, request, pk):
     user = get_object_or_404(User, pk=pk)
     if request.user.is_superuser or request.user.username == user.username:
         serializer = UserSerializer(instance=user, data=request.data)
         if serializer.is_valid():
             serializer.save()
             return Response(serializer.data, status=status.HTTP_200_OK)
         else:
             return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
     else:
         return Response(status=status.HTTP_401_UNAUTHORIZED)
開發者ID:jbiscarri,項目名稱:Wordplease-django,代碼行數:13,代碼來源:api.py


注:本文中的users.serializers.UserSerializer.is_valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。