comment.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:MonkeyEye-Server 作者: SYSUMonkeyEye 项目源码 文件源码
def post(self):
        """????(???)"""
        form = request.form
        mid = form.get('movieId', '')
        movie = Movie.query.get(mid)
        if movie is None:
            return {'message': '?????'}, 233

        try:
            rating = int(form.get('rating', ''))
            if rating < 0 or rating > 5:
                return {'message': '????'}, 233
        except ValueError:
            return {'message': '????'}, 233

        content = form.get('content', '').strip()
        if len(content) == 0:
            return {'message': '????????'}, 233

        comment = Comment()
        comment.id = UUID()
        comment.rating = rating
        comment.content = content
        comment.movieId = mid
        comment.username = current_user.id
        db.session.add(comment)

        total = movie.ratingNum * movie.rating
        movie.ratingNum += 1
        movie.rating = (total + rating) / movie.ratingNum
        db.session.commit()

        return {'message': '????', 'id': comment.id}, 200
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号