本文整理汇总了Python中users.serializers.UserSerializer类的典型用法代码示例。如果您正苦于以下问题:Python UserSerializer类的具体用法?Python UserSerializer怎么用?Python UserSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: put
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,代码行数:11,代码来源:api.py
示例17: post
def post(self, request):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
new_user = serializer.save()
blog = Blog()
blog.title = request.data.get("blog")
blog.owner = new_user
blog.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:AgDP,项目名称:Django-Wordplease,代码行数:11,代码来源:api.py
示例18: list_matches
def list_matches(self, request):
serialized = UserSerializer(data=request.data)
if serialized.is_valid():
User.objects.create_user(
serialized.init_data['email'],
serialized.init_data['date_of_birth'],
serialized.init_data['password']
)
return Response(serialized.data, status=status.HTTP_201_CREATED)
else:
return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:rgachuhi,项目名称:pendoproject,代码行数:11,代码来源:views.py
示例19: post
def post(self, request):
serializer = UserSerializer(data=request.data) # se inicializa el serializer con los datos que me llegan por http mediante POST
if serializer.is_valid():
new_user = serializer.save() # Guarda el objeto en BB.DD. y me lo devuelve
new_blog = Blog()
new_blog.name = 'El blog de {0} {1}'.format(request.data.get('first_name'), request.data.get('last_name'))
new_blog.author = new_user
new_blog.save()
# serializer almacena los datos en 'serializer.data'
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
# serializer almacena los errores en 'serializer.errors'
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:jalzueta,项目名称:keepCodingMaster-Django,代码行数:13,代码来源:api.py
示例20: create
def create(self, request):
serializer = UserSerializer(data=request.data) #TODOS LOS MÉTODOS REST VIENEN POR EL PARAMETRO 'DATA' DE LA REQUEST
if serializer.is_valid():
new_user = serializer.save()
# TODO - crear el usuario y su blog en una sóla llamada
blog_for_newUser = Blog()
blog_for_newUser.owner = new_user
blog_for_newUser.name = new_user.first_name + ' ' + new_user.last_name + '\'s Personal Blog'
blog_for_newUser.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:dregatos,项目名称:Keepcoding_DjangoModule_WordPlease,代码行数:14,代码来源:api.py
注:本文中的users.serializers.UserSerializer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论