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


Python serializers.UserSerializer類代碼示例

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


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

示例1: post

 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,代碼行數:7,代碼來源:api.py

示例2: post

    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,代碼行數:30,代碼來源:views.py

示例3: put

    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,代碼行數:25,代碼來源:views.py

示例4: create

 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,代碼行數:7,代碼來源:api.py

示例5: post

 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,代碼行數:7,代碼來源:api.py

示例6: put

 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,代碼行數:7,代碼來源:views.py

示例7: create

 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,代碼行數:8,代碼來源:api.py

示例8: UpdateUserTest

class UpdateUserTest(APITestCase):
    def setUp(self):
        self.user = User.objects.create(username="jake", first_name="Jake")
        self.data = UserSerializer(self.user).data
        self.data.update({'first_name': 'Changed'})

    def test_can_update_user(self):
        response = self.client.put(reverse('user-detail', args=[self.user.id]), self.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
開發者ID:dustinfarris,項目名稱:django-ember-authentication,代碼行數:9,代碼來源:tests.py

示例9: create

 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,代碼行數:9,代碼來源:api.py

示例10: update

 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,代碼行數:9,代碼來源:api.py

示例11: put

 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,代碼行數:9,代碼來源:api.py

示例12: update

 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,代碼行數:9,代碼來源:api.py

示例13: put

 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,代碼行數:9,代碼來源:api.py

示例14: update

 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,代碼行數:9,代碼來源:api.py

示例15: update

 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,代碼行數:10,代碼來源:api.py


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