Exemplo n.º 1
0
 def post(self, request, pk, format=None):
     user = get_object(self, pk)
     serializer = UserSerializer(user, 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)
Exemplo n.º 2
0
class MessageSerializer(serializers.ModelSerializer):
    class Meta:
        model = Message
        fields = ('id', 'text', 'issue', 'space', 'author', 'mention',
                  'created_at', 'updated_at')

    author = UserSerializer()
Exemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     serializer = self.get_serializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     user = serializer.validated_data
     return Response({
         "user":
         UserSerializer(user, context=self.get_serializer_context()).data,
         "token":
         AuthToken.objects.create(user)[1],
     })
Exemplo n.º 4
0
def jwt_response_payload_handler(token, user=None, request=None):
    """
    自定义jwt认证成功返回数据
    """
    # print('timeArray', user.last_login.now())
    # t = int(time.mktime(user.last_login.now().timetuple()))
    # print('timeArray', datetime.datetime.fromtimestamp(t))
    last_login = user.last_login
    if last_login: last_login = int(time.mktime(user.last_login.now().timetuple()))

    return {
        'user': UserSerializer(user).data,
        'token': token,
    }
Exemplo n.º 5
0
 def get(self, request, pk, format=None):
     user = get_object(self, pk)
     serializer = UserSerializer(user)
     return Response(serializer.data)
Exemplo n.º 6
0
 def post(self, request, format=None):
     serializer = UserSerializer(data=request.data)
     if serializer.is_valid():
         serializer.save(created)
         return Response(serializer.data, status=status.HTTP_201_CREATED)
     return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 7
0
 def get(self, request, format=None):
     users = get_all_objects(self)
     serializer = UserSerializer(users, many=True)
     return Response(serializer.data)
Exemplo n.º 8
0
class CommentSerializer(serializers.ModelSerializer):
    author_detail = UserSerializer(source='author', read_only=True)

    class Meta:
        model = Comment
        fields = '__all__'
Exemplo n.º 9
0
 def post(self, request, *args, **kwargs):
     serializer = UserSerializer(data=request.data)
     serializer.is_valid(raise_exception=True)
     return Response(serializer.validated_data)