Beispiel #1
0
    def delete(self, obj_id):
        post = PostModel.objects(id=obj_id).first()
        comment_num = int(request.args.get('comment_num'))
        self.check_is_exist(post, comment_num)

        if not len(post.comments):
            return Response('', 204)

        PostModel.objects(comments__match={"comment_num": comment_num}) \
                 .update_one(pull__comments_comment_num=comment_num)

        return '', 200
Beispiel #2
0
    def delete(self, obj_id, comment_num):
        post = PostModel.objects(id=obj_id).first()
        self.check_is_exist(post, comment_num)

        if not len(post.comments):
            return Response('', 204)

        comment = PostModel.objects(comment__match={
            "comment_num": comment_num
        }).first()
        comment.delete()

        return Response('', 200)
Beispiel #3
0
    def post(self, obj_id, comment_num):
        post = PostModel.objects(id=obj_id).first()
        self.check_is_exist(post, comment_num)

        new_comment_num = len(post.comments) + 1

        comment = CommentModel(user=g.user,
                               comment=request.json['comment'],
                               comment_num=new_comment_num)

        post.comments.append(comment)
        post.save()

        return Response('', 201)
Beispiel #4
0
    def get(self):
        all_post = PostModel.objects().all()
        if not all_post:
            return Response('', 204)

        return self.unicode_safe_json_dumps([{
            'obj_id':
            str(post.id),
            'title':
            post.title,
            'author':
            post.author.nickname,
            'content':
            post.content,
            'comments': [{
                "name": data.name,
                "comment": data.comment
            } for data in post.comments],
            'tags':
            post.tags,
            'timestamp':
            str(post.timestamp)
        } for post in all_post], 200)
Beispiel #5
0
    def get(self, obj_id):
        post = PostModel.objects(id=obj_id).first()
        self.check_is_exist(post)

        return self.unicode_safe_json_dumps(
            {
                'obj_id':
                str(post.id),
                'title':
                post.title,
                'author':
                post.author.nickname,
                'content':
                post.content,
                'comments': [{
                    "user": data.user.nickname,
                    "comment": data.comment
                } for data in post.comments],
                'tags':
                post.tags,
                'timestamp':
                str(post.timestamp)
            }, 200)
Beispiel #6
0
    def delete(self, obj_id):
        post = PostModel.objects(id=obj_id).first()
        self.check_is_exist(post)
        post.delete()

        return Response('', 200)