class InvitationSerializer(serializers.ModelSerializer):
    sender = UserSerializer()
    receiver = UserSerializer()

    class Meta:
        model = Invitation
        fields = '__all__'
class TransferSerializer(serializers.ModelSerializer):
    sender = UserSerializer()
    receiver = UserSerializer()

    class Meta:
        model = Transfer
        fields = '__all__'
class PrivateMessageSerializer(serializers.ModelSerializer):
    sender = UserSerializer()
    receiver = UserSerializer()

    class Meta:
        model = PrivateMessage
        fields = '__all__'
class ModeratorSerializer(serializers.ModelSerializer):
    sponsor = UserSerializer()
    user = UserSerializer()

    class Meta:
        model = Moderator
        fields = '__all__'
Exemple #5
0
    def get(request):
        """
        List users
        """

        users = User.objects.all()
        return Response(UserSerializer(users, many=True).data)
Exemple #6
0
class PostSerializer(serializers.ModelSerializer):
    post_replies = PostReplySerializer(many=True, read_only=True)
    user = UserSerializer()

    class Meta:
        model = Post
        fields = '__all__'
Exemple #7
0
    def get(request, user_id):
        """
        View individual user
        """

        user = get_object_or_404(User, pk=user_id)
        return Response(UserSerializer(user).data)
Exemple #8
0
    def post(request):
        """
        Create user
        """

        serializer = UserSerializerCreate(data=request.data, context={'request': request})
        if serializer.is_valid():
            serializer.save()
            return Response(UserSerializer(serializer.instance).data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #9
0
    def post(request, user_id):
        """
        Follow a user
        """

        current_user = request.user
        to_follow = get_object_or_404(User, pk=user_id)

        current_user.following.add(to_follow)

        return Response(UserSerializer(to_follow).data,
                        status=status.HTTP_201_CREATED)
Exemple #10
0
class PostSerializer(serializers.ModelSerializer):
    post_reply_count = serializers.SerializerMethodField()
    post_votes = PostVoteSerializer(many=True, read_only=True)
    user = UserSerializer()

    class Meta:
        model = Post
        fields = '__all__'

    @staticmethod
    def get_post_reply_count(post):
        return PostReply.objects.filter(post=post).count()
class PostSerializer(serializers.ModelSerializer):
    post_reply_count = serializers.SerializerMethodField()
    post_votes = PostVoteSerializer(many=True, read_only=True)
    post_upper_votes_count = serializers.SerializerMethodField()
    post_down_votes_count = serializers.SerializerMethodField()
    user_page_view_count = serializers.SerializerMethodField()
    login_user_page_view_count = serializers.SerializerMethodField()
    go_to_link = serializers.SerializerMethodField()
    login_user_go_to_link = serializers.SerializerMethodField()
    user = UserSerializer()
    category = PostCategorySerializer(many=True)
    created_time_timestamp = serializers.SerializerMethodField()

    class Meta:
        model = Post
        fields = '__all__'
        ordering = ['-post_total_view', '-post_votes', '-created_time']

    @staticmethod
    def get_created_time_timestamp(post):
        return datetime.timestamp(post.created_time)

    @staticmethod
    def get_post_reply_count(post):
        return PostReply.objects.filter(post=post).count()

    @staticmethod
    def get_user_page_view_count(post):
        return UserPageView.objects.filter(post=post).count()

    @staticmethod
    def get_login_user_page_view_count(post):
        return UserPageView.objects.filter(post=post,
                                           user__isnull=False).count()

    @staticmethod
    def get_go_to_link(post):
        return UserPageView.objects.filter(post=post, click_link=True).count()

    @staticmethod
    def get_login_user_go_to_link(post):
        return UserPageView.objects.filter(post=post,
                                           click_link=True,
                                           user__isnull=False).count()

    @staticmethod
    def get_post_down_votes_count(post):
        return PostVote.objects.filter(post=post, value=-1).count()

    @staticmethod
    def get_post_upper_votes_count(post):
        return PostVote.objects.filter(post=post, value=1).count()
Exemple #12
0
    def post(request):
        """
        Create user
        """

        serializer = UserSerializerCreate(data=request.data,
                                          context={'request': request})
        if serializer.is_valid():
            user = serializer.save()
            user.set_password(serializer.validated_data['password'])
            user.save()
            Profile(user=user).save()
            return Response(UserSerializer(user).data,
                            status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Exemple #13
0
class PostReplySerializer(serializers.ModelSerializer):
    user = UserSerializer()
    post_reply_upper_votes_count = serializers.SerializerMethodField()
    post_reply_down_votes_count = serializers.SerializerMethodField()

    class Meta:
        model = PostReply
        fields = '__all__'

    @staticmethod
    def get_post_reply_down_votes_count(post_reply):
        return PostReplyVote.objects.filter(post_reply=post_reply,
                                            value=-1).count()

    @staticmethod
    def get_post_reply_upper_votes_count(post_reply):
        return PostReplyVote.objects.filter(post_reply=post_reply,
                                            value=1).count()
Exemple #14
0
class PostImageSerializer(serializers.ModelSerializer):
    user = UserSerializer()
    post = PostSimpleSerializer()
    image = Base64ImageField(required=False)
    post_id = serializers.SerializerMethodField()

    class Meta:
        model = PostImage
        fields = '__all__'
        ordering = ['-created_time']
        read_only_fields = ['id', 'user', 'created_time', 'last_modified']

    @staticmethod
    def get_post_id(post_image):
        return Post.objects.filter(post_image=post_image)

    def validate_user(self, user):
        """
        Validate authenticated user
        """
        if user != self.context['request'].user or user != self.post.user:
            raise serializers.ValidationError('You can not modify post image for other users')
        return user
Exemple #15
0
class PostReplySerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = PostReply
        fields = '__all__'
Exemple #16
0
class AdministratorSerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = Administrator
        fields = '__all__'
class WalletSerializer(serializers.ModelSerializer):
    user = UserSerializer()

    class Meta:
        model = Wallet
        fields = '__all__'