本文整理汇总了Python中serializers.UserSerializer类的典型用法代码示例。如果您正苦于以下问题:Python UserSerializer类的具体用法?Python UserSerializer怎么用?Python UserSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserSerializer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: put
def put(self, request, pk, format=None):
user = self.get_object(pk)
serializer = UserSerializer(user, data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:erigones,项目名称:api_openvpn,代码行数:7,代码来源:views.py
示例2: post
def post(self, request, format=None):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
#serializer.data
message = "from User2"
return Response({"message": message, "data": serializer.data})
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:eduStack,项目名称:edx_siteapi,代码行数:7,代码来源:views.py
示例3: post
def post(self, request):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid(): # los serializer funcionan como los djangoforms, así que hay que validarlo
serializer.save() # guardamos en la base de datos el nuevo usuario
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:enrimr,项目名称:django_frikr_example,代码行数:7,代码来源:api.py
示例4: post
def post(self,request, format=None):
data = request.DATA
graph = facebook.GraphAPI(data['token'])
profile = graph.get_object("me")
picture = graph.get_connections("me", "picture")
objUser = {}
objUser['first_name'] = profile['first_name']
objUser['last_name'] = profile['last_name']
objUser['email'] = profile['email']
objUser['username'] = profile['id']
objUser['is_active'] = True
objProfile = {}
objProfile['access_token'] = data['token']
objProfile['profile_picture'] = picture['url']
objProfile['gender'] = profile['gender']
objUser['user_profile'] = objProfile
user = UserSerializer()
serializer = UserSerializer(data=objUser)
try:
userobj = User.objects.get(username=objUser['username'])
return Response(objUser, status=status.HTTP_200_OK)
except User.DoesNotExist:
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:eSketchers,项目名称:socialquote,代码行数:26,代码来源:views.py
示例5: post
def post(self, request):
serializer = UserSerializer(data=request.DATA) # en lugar request.POST
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:juandetoro,项目名称:Frikr,代码行数:7,代码来源:api.py
示例6: create_user
def create_user(request):
data = request.data
serializer = UserSerializer(data=data)
if serializer.is_valid():
serializer.save()
return Response({'message': 'Created'})
return Response(serializer.errors)
开发者ID:ZandekA,项目名称:buddhasoft_task,代码行数:7,代码来源:views.py
示例7: createUser
def createUser(self, request):
data = JSONParser.parse(request)
serializer = UserSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JSONResponse(serializer.data, status=201)
return JSONResponse(serializer.errors, status=400)
开发者ID:SCuvanov,项目名称:Babybook_API,代码行数:7,代码来源:Views.py
示例8: put
def put(self, request, id, format=None):
snippet = self.get_object(id=id)
serializer = UserSerializer(snippet, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:kazixma,项目名称:djangorestframeworktutorial,代码行数:7,代码来源:views.py
示例9: get
def get(self, request, *args, **kwargs):
if request.user.is_authenticated():
user_data = UserSerializer(request.user).data
user_data.update(token=Token.objects.get_or_create(user=request.user)[0].key)
return self.get_response(True, data=user_data)
else:
return self.get_response(False)
开发者ID:Mehaor,项目名称:lentach_games,代码行数:7,代码来源:views.py
示例10: post
def post(self, request, format=None):
#Si existe el usuario dar mensaje de error de que ya existe.
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:rbenvos,项目名称:shop_list,代码行数:7,代码来源:api.py
示例11: post
def post(self, request, format=None):
queryset = Logistics_user.objects.all()
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:Rahulkr204,项目名称:SEN-project,代码行数:7,代码来源:views.py
示例12: put
def put(self, request, pk, format=None):
user = Logistics_user.objects.get(pk=pk)
serializer = UserSerializer(user, data=request.data)#, many=True, context={'request': request})
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:Rahulkr204,项目名称:SEN-project,代码行数:7,代码来源:views.py
示例13: patch
def patch(self, request):
serialized = UserSerializer(data=request.DATA)
if serialized.is_valid():
serialized.save()
return Response(status=status.HTTP_205_RESET_CONTENT)
else:
return Response(serialized.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:sirius9,项目名称:restauth_login_test,代码行数:7,代码来源:views.py
示例14: post
def post(self, request):
serializer = UserSerializer(data=request.DATA)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=201)
else:
return Response(serializer.errors, status=400)
开发者ID:nabilmania,项目名称:frikr,代码行数:7,代码来源:api.py
示例15: post
def post(self, request):
serialized = UserSerializer(data=request.data)
if serialized.is_valid():
serialized.save()
Player.objects.create(user_id=serialized.data['id'])
return Response(serialized.data, status=status.HTTP_201_CREATED)
else:
return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:blstream,项目名称:ut-arena,代码行数:8,代码来源:views.py
示例16: create
def create(self, request):
serializer = UserSerializer(data=request.DATA) # en lugar request.POST
if serializer.is_valid():
new_user = serializer.save()
self.send_welcome_email(new_user)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:CarlosLannister,项目名称:frikr_talentum,代码行数:8,代码来源:api.py
示例17: _test_google_auth
def _test_google_auth(self):
auth_token = confidential.google_auth_token
client = APIClient()
request = client.post('user/google_auth/',data={'auth_token':auth_token})
self.assertEqual(request.status_cod, status.HTTP_200_OK)
serializer = UserSerializer(data=request.data)
self.assertTrue(serializer.is_valid(raise_exception=False))
开发者ID:ThomasKomarnicki,项目名称:GeoServer,代码行数:9,代码来源:tests.py
示例18: register
def register(request):
serialized = UserSerializer(data=request.POST)
if serialized.is_valid():
user_data = utils.get_user_data(request.POST)
utils.create_inactive_user(**user_data)
return Response(utils.USER_CREATED_RESPONSE_DATA,
status=status.HTTP_201_CREATED)
else:
return Response(serialized._errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:Bazzinga,项目名称:django-registration-rest-framework,代码行数:9,代码来源:views.py
示例19: authenticate_ldap
def authenticate_ldap(username, password, token):
connection = ldap.initialize("ldap://ldap.iitb.ac.in")
search_result = connection.search_s('dc=iitb,dc=ac,dc=in', ldap.SCOPE_SUBTREE, 'uid=%s' % username,
['uid', 'cn', 'givenName', 'sn', 'mail', 'employeeNumber'])
response_data = {
'error': False,
'error_message': "",
'first_name': "",
'last_name': "",
'email': "",
'employeeNumber': "",
'ldap': "",
'name': "",
'token': "",
}
if len(search_result) < 1 or search_result[0][1]['uid'][0] != username:
response_data['error'] = True
response_data['error_message'] = "Invalid Username/Password"
else:
try:
bind_ds = search_result[0][0]
connection.bind_s(bind_ds, password)
response_data['error'] = False
result_dict = search_result[0][1]
response_data['first_name'] = result_dict['givenName'][0]
response_data['last_name'] = result_dict['sn'][0]
response_data['name'] = result_dict['cn'][0]
response_data['email'] = result_dict['mail'][0]
response_data['ldap'] = result_dict['uid'][0]
response_data['employeeNumber'] = result_dict['employeeNumber'][0]
user_serialized = UserSerializer(data=response_data)
if user_serialized.is_valid():
user = user_serialized.save()
user.backend = "django.contrib.auth.backends.ModelBackend"
response_data['id'] = user.id
if token:
user_token = UserToken(user=user)
user_token.save()
response_data['token'] = user_token.token.hex
return response_data, user
else:
response_data['error'] = True
response_data['error_message'] = 'Unable to login. Please contact admin'
except ldap.INVALID_CREDENTIALS:
response_data['error'] = True
response_data['error_message'] = "Invalid Credentials"
except:
response_data['error'] = True
response_data['error_message'] = 'Unable to authenticate'
return response_data, None
开发者ID:the-coders-hub,项目名称:IITBApp-Server,代码行数:56,代码来源:views.py
示例20: register
def register(request):
serialized = UserSerializer(data=request.DATA)
if serialized.is_valid():
get_user_model().objects.create_user(
serialized.init_data['email'],
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:bbenko,项目名称:TopToDo,代码行数:10,代码来源:views.py
注:本文中的serializers.UserSerializer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论